Skip to content

Instantly share code, notes, and snippets.

@Nishisonic
Last active March 26, 2023 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nishisonic/d1224e9ecd64b38fa32823a36411480a to your computer and use it in GitHub Desktop.
Save Nishisonic/d1224e9ecd64b38fa32823a36411480a to your computer and use it in GitHub Desktop.
【拡張版script】轟沈セーフティサポート
DataType = Java.type("logbook.data.DataType");
GlobalContext = Java.type("logbook.data.context.GlobalContext");
ApplicationMain = Java.type("logbook.gui.ApplicationMain");
/**
* @param {logbook.data.DataType} type
* @param {logbook.data.Data} data
*/
function update(type, data) {
var json = data.jsonObject.api_data;
switch (type) {
case DataType.START:
case DataType.NEXT:
if (shouldDisposeState() && shouldDisposeCell(json) && !needsContinue(json)) {
// アプリを落とす
ApplicationMain.main.shell.dispose();
}
break;
default:
break;
}
}
/**
* アプリを落とすべき状態か
* @return {boolean}
*/
function shouldDisposeState() {
var isSorties = Java.from(GlobalContext.getIsSortie());
return isSorties.some(function (isSortie, i) {
if (isSortie) {
var dock = GlobalContext.getDock(String(i + 1));
return Java.from(dock.ships)
.filter(function (_, j) {
// 旗艦または退避している艦は除外
return j > 0 && (!dock.escaped || !dock.escaped[j]);
})
.some(function (ship) {
var items = Java.from(ship.item2.toArray());
items.push(ship.slotExItem);
if (
// 以下のうち何れかに当てはまる艦に限定する
// ・30Lv以上
// ・まるゆ
// ・海防艦
// ・ロック済み艦娘
// ・ロック済み装備を所持
(
ship.lv >= 30 ||
ship.name.indexOf("まるゆ") >= 0 ||
ship.stype === 1 ||
ship.locked ||
items.some(function (item) {
return item && item.isLocked();
})
) &&
// 大破している艦
ship.isBadlyDamage()
) {
// ダメコン所持判定
return !items.some(function (item) {
// 42:応急修理要員, 43:応急修理女神
return item && [42, 43].indexOf(item.slotitemId) >= 0;
});
}
return false;
});
}
return false;
});
}
/**
* アプリを落とすべきセルか
* @param {javax.json.JsonObject} json JSON
* @return {boolean}
*/
function shouldDisposeCell(json) {
return !(
// 次のマスでのルート分岐の本数(0:行き止まり)
json.api_next.intValue() === 0 &&
(
// イベント種別(0:非戦闘セル)
json.api_event_kind.intValue() === 0 ||
// イベント(1:イベントなし, 6:気のせいだった)
[1, 6].indexOf(json.api_event_id.intValue()) >= 0
)
);
}
/**
* アプリを続行した(落とさない)方が良いか
* @param {javax.json.JsonObject} json JSON
* @return {boolean}
*/
function needsContinue(json) {
// 潜水艦隊かつ7-4かつ(KマスまたはMマス)の場合はアプリを続行させる
return isSubmarineFleet() &&
json.api_maparea_id.intValue() === 7 &&
json.api_mapinfo_no.intValue() === 4 &&
// [11, 19]:Kマス, 13:Mマス
[11, 19, 13].indexOf(json.api_no.intValue()) >= 0;
}
/**
* 潜水艦隊か
* @return {boolean}
*/
function isSubmarineFleet() {
var isSorties = Java.from(GlobalContext.getIsSortie());
return isSorties.every(function (isSortie, i) {
if (isSortie) {
var dock = GlobalContext.getDock(String(i + 1));
return Java.from(dock.ships)
.every(function (ship) {
// 13:潜水艦, 14:潜水空母
return ship.stype === 13 || ship.stype === 14;
});
}
return true;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment