From b66b1bb587ee33d140c43e743506167ec45be182 Mon Sep 17 00:00:00 2001 From: gk Date: Thu, 6 Jun 2019 15:47:49 +0900 Subject: [PATCH 1/2] feat: report ship stats from construction --- reporters/ship-stat.es | 68 ++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/reporters/ship-stat.es b/reporters/ship-stat.es index 25a4156..e0a3657 100644 --- a/reporters/ship-stat.es +++ b/reporters/ship-stat.es @@ -1,35 +1,53 @@ import _, { get } from 'lodash' import BaseReporter from './base' +const makeShipStatReport = (ship, eqStats = { evasion: 0, asw: 0, los: 0 }) => ({ + id: ship.api_ship_id, + lv: ship.api_lv, + evasion: ship.api_kaihi[0] - eqStats.evasion, + evasion_max: ship.api_kaihi[1], + asw: ship.api_taisen[0] - ship.api_kyouka[6] - eqStats.asw, + asw_max: ship.api_taisen[1], + los: ship.api_sakuteki[0] - eqStats.los, + los_max: ship.api_sakuteki[1], +}) + export default class ShipStatReporter extends BaseReporter { handle = (method, path, body, postBody, time) => { - if (path !== '/kcsapi/api_get_member/ship3') { - return - } + switch (path) { + case '/kcsapi/api_req_kousyou/getship': + { + const eqStats = { evasion: 0, asw: 0, los: 0 } + for (const { api_slotitem_id } of body.api_slotitem) { + const e = window.$slotitems[api_slotitem_id] + if (!e) { + return + } + eqStats.evasion += e.api_houk + eqStats.asw += e.api_tais + eqStats.los += e.api_saku + } - const ship = get(body, ['api_ship_data', 0]) + this.report('/api/report/v2/ship_stat', makeShipStatReport(body.api_ship, eqStats)) + } + break + case '/kcsapi/api_get_member/ship3': + { + const ship = get(body, ['api_ship_data', 0]) - // check if all slots are empty - // api_slot_ex could be 0 (not enabled) or -1 (no item) - if ( - _(ship.api_slot) - .concat(ship.api_slot_ex) - .some(id => id > 0) - ) { - return - } + // check if all slots are empty + // api_slot_ex could be 0 (not enabled) or -1 (no item) + if ( + _(ship.api_slot) + .concat(ship.api_slot_ex) + .some(id => id > 0) + ) { + return + } - const taisenKyouka = ship.api_kyouka[6] - - this.report('/api/report/v2/ship_stat', { - id: ship.api_ship_id, - lv: ship.api_lv, - los: ship.api_sakuteki[0], - los_max: ship.api_sakuteki[1], - asw: ship.api_taisen[0] - taisenKyouka, - asw_max: ship.api_taisen[1], - evasion: ship.api_kaihi[0], - evasion_max: ship.api_kaihi[1], - }) + this.report('/api/report/v2/ship_stat', makeShipStatReport(ship)) + } + break + } } } From c9c86c83a260b39fba984efd1e3f80a0eaa8e686 Mon Sep 17 00:00:00 2001 From: gk Date: Thu, 6 Jun 2019 15:51:06 +0900 Subject: [PATCH 2/2] chore: run eslint fix --- index.es | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.es b/index.es index 6cc01ed..88e9c24 100644 --- a/index.es +++ b/index.es @@ -11,20 +11,19 @@ import { } from './reporters' let reporters = [] -const handleResponse = (e) => { - const {method, path, body, postBody, time = Date.now()} = e.detail +const handleResponse = e => { + const { method, path, body, postBody, time = Date.now() } = e.detail for (const reporter of reporters) { try { reporter.handle(method, path, body, postBody, time) - } - catch (err) { + } catch (err) { console.error(err.stack) } } } export const show = false -export const pluginDidLoad = (e) => { +export const pluginDidLoad = e => { reporters = [ new QuestReporter(), new CreateShipReporter(), @@ -38,6 +37,6 @@ export const pluginDidLoad = (e) => { ] window.addEventListener('game.response', handleResponse) } -export const pluginWillUnload = (e) => { +export const pluginWillUnload = e => { window.removeEventListener('game.response', handleResponse) }