Skip to content

Instantly share code, notes, and snippets.

@Nishisonic
Last active March 2, 2020 16:50
Show Gist options
  • Save Nishisonic/4ba70841ec5cd408c94b856fbeaf18c5 to your computer and use it in GitHub Desktop.
Save Nishisonic/4ba70841ec5cd408c94b856fbeaf18c5 to your computer and use it in GitHub Desktop.
【拡張版script】PoiDB Client
load("script/ScriptData.js");
data_prefix = "PoiDB";
BufferedReader = Java.type("java.io.BufferedReader");
InputStreamReader = Java.type("java.io.InputStreamReader");
OutputStreamWriter = Java.type("java.io.OutputStreamWriter");
URL = Java.type("java.net.URL");
Collectors = Java.type("java.util.stream.Collectors");
GlobalContext = Java.type("logbook.data.context.GlobalContext");
DataType = Java.type("logbook.data.DataType");
ApplicationMain = Java.type("logbook.gui.ApplicationMain");
var VERSION = "1.0.2";
var USER_AGENT = "LogbookEx/" + VERSION;
function update(type, data) {
switch (type) {
case DataType.MAPINFO:
var mapInfo = JSON.parse(data.jsonObject.api_data.api_map_info);
var result = mapInfo
.map(function(map) {
if (map.api_eventmap && map.api_eventmap.api_selected_rank) {
return {
id: map.api_id,
mapLv: map.api_eventmap.api_selected_rank.intValue()
};
} else {
return { id: map.api_id, mapLv: 0 };
}
})
.reduce(function(previous, current) {
previous[current.id] = current.mapLv;
return previous;
}, {});
setTmpData("mapLvInfo", result);
break;
case DataType.BATTLE_RESULT: // 通常戦闘結果
case DataType.COMBINED_BATTLE_RESULT: // 連合戦闘結果
var shipCount = GlobalContext.shipMap.size();
var itemCount = GlobalContext.itemMap.size();
if (
GlobalContext.maxChara() > shipCount &&
GlobalContext.maxSlotitem() > itemCount
) {
sendShipDropData(data);
}
break;
default:
break;
}
}
function sendShipDropData(data) {
var lastBattleDto = GlobalContext.lastBattleDto;
var json = data.jsonObject.api_data;
var mapCellDto = lastBattleDto.mapCellDto;
var mapLvInfo = getData("mapLvInfo");
if (!(lastBattleDto && mapCellDto && mapLvInfo)) return;
var shipId = lastBattleDto.isDropShip() ? lastBattleDto.dropShipId : -1;
var itemId =
json.api_get_useitem && json.api_get_useitem.api_useitem_id
? Number(json.api_get_useitem.api_useitem_id)
: -1;
var map = mapCellDto.map;
var mapId = map[0] * 10 + map[1];
if (mapLvInfo[mapId] === undefined) return;
var quest = lastBattleDto.questName;
var cellId = map[2];
var enemy = lastBattleDto.enemyName;
var rank = lastBattleDto.rank.rank();
var isBoss = mapCellDto.isBoss();
var teitokuLv = lastBattleDto.hqLv;
var mapLv = mapLvInfo[mapId];
var enemyShips1 = Java.from(lastBattleDto.enemy)
.filter(function(enemy) {
return enemy;
})
.map(function(enemy) {
return enemy.shipId;
});
var enemyShips2 = lastBattleDto.isEnemyCombined()
? Java.from(lastBattleDto.enemyCombined)
.filter(function(enemy) {
return enemy;
})
.map(function(enemy) {
return enemy.shipId;
})
: [];
// 文字列でしか受け取れないため
var enemyFormation = Number(lastBattleDto.phase1.json.api_formation[1]);
var baseExp = Number(json.api_get_base_exp);
// var teitokuId = null; 提督IDは渡さない
// var shipCounts = []; ○隻所持しているときにドロップするかどうかしか分からないので渡さない
var origin = USER_AGENT;
var result = {
shipId: shipId,
itemId: itemId,
mapId: mapId,
quest: quest,
cellId: cellId,
enemy: enemy,
rank: rank,
isBoss: isBoss,
teitokuLv: teitokuLv,
mapLv: mapLv,
enemyShips1: enemyShips1,
enemyShips2: enemyShips2,
enemyFormation: enemyFormation,
baseExp: baseExp,
// teitokuId: teitokuId,
// shipCounts: shipCounts,
origin: origin
};
send("drop_ship", result);
}
function send(target, json) {
var result = post(
"http://poi.0u0.moe/api/report/v2/" + target,
"data=" + JSON.stringify(json)
);
ApplicationMain.main.printMessage(
"PoiDBへ送信(code:" + result.statusCode + ")"
);
}
function post(urlString, data) {
var url = new URL(urlString);
var con = null;
var response = null;
try {
con = url.openConnection();
con.setDoOutput(true);
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
var out = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
out.write(data);
out.close();
con.connect();
var reader = new BufferedReader(
new InputStreamReader(con.getInputStream(), "UTF-8")
);
response = reader.lines().collect(Collectors.joining());
} finally {
if (con) {
con.disconnect();
return { statusCode: con.responseCode, data: response };
}
return { statusCode: -1, data: response };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment