poi-plugin-lock-reminder
Version:
A poi plugin for reminding to lock new kanmusu.
159 lines (115 loc) • 4.05 kB
JavaScript
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _lodash = _interopRequireDefault(require("lodash"));
var _i18next = _interopRequireDefault(require("views/env-parts/i18next"));
var _utils = require("./utils");
var _redux = require("./redux");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const {
toast,
getStore
} = window;
class Reminder {
constructor() {
this.shipIds = [];
this.currentRes = {};
this.handler = e => {
const {
path,
body,
postBody
} = e.detail;
_utils.logger.log('\npath', path, '\nbody', body);
this.currentRes = {
path,
body
};
switch (path) {
case '/kcsapi/api_req_map/start':
this.start();
break;
case '/kcsapi/api_req_sortie/battleresult':
case '/kcsapi/api_req_combined_battle/battleresult':
{
const dropShipId = _lodash.default.get(this.currentRes, 'body.api_get_ship.api_ship_id', null);
_utils.logger.log('dropShipId: ', dropShipId); // 海域攻略報酬 イベント海域突破時のみ存在
const eventItems = _lodash.default.get(this.currentRes, 'body.api_get_eventitem', []);
const eventRewardShipIds = [];
_lodash.default.each(eventItems, item => {
// 報酬種別 1=アイテム, 2=艦娘, 3=装備, 5=家具
if (+item.api_type === 2) {
eventRewardShipIds.push(item.api_id);
}
});
this.checkPush(dropShipId, ...eventRewardShipIds);
break;
}
case '/kcsapi/api_req_quest/clearitemget':
{
const bonus = _lodash.default.get(this.currentRes, 'body.api_bounus', []);
_utils.logger.log('quest clear bonus: ', bonus);
const bonusShipIds = _lodash.default.map( // 11=艦船
_lodash.default.filter(bonus, i => +i.api_type === 11), ship => _lodash.default.get(ship, 'api_item.api_ship_id', null));
this.checkPush(...bonusShipIds);
break;
}
case '/kcsapi/api_get_member/picture_book':
{
if (_lodash.default.get(postBody, 'api_type') === '1') {
this.handleEnterPictureBook(_lodash.default.get(postBody, 'api_no', '1'));
}
break;
}
case '/kcsapi/api_port/port':
this.publish();
break;
default:
_utils.logger.log('default, path: ', path);
break;
}
};
this.start = () => {
this.reset();
};
this.checkPush = (...ids) => {
_utils.logger.log('checkPush ids: ', ids);
_lodash.default.each(ids, id => {
_utils.logger.log('id, canBePushed', id, (0, _utils.canBePushed)(id));
if ((0, _utils.canBePushed)(id)) {
this.shipIds.push(id);
}
});
};
this.reset = () => {
this.shipIds = [];
this.currentRes = {};
};
this.handleEnterPictureBook = page => {
(0, _redux.recordPictureData)(this.currentRes.body, page);
};
this.publish = () => {
if (_lodash.default.isEmpty(this.shipIds)) {
_utils.logger.log('current ship queue is empty, nothing to do');
return;
}
const shipNames = _lodash.default.map(this.shipIds, id => getStore(`const.$ships.${id}.api_name`) || '');
_utils.logger.log('shipNames: ', shipNames);
if (!_lodash.default.isEmpty(_lodash.default.compact(shipNames))) {
const text = _i18next.default.t(`${_utils.PLUGIN_NAME}:New KanMusu {{ships}} joined, remember to lock`, {
ships: shipNames.join(', ')
});
toast(text, {
intent: 'success',
icon: 'tick',
timeout: 0
});
window.notify(text);
}
this.reset();
};
}
}
var _default = new Reminder();
exports.default = _default;
module.exports = exports.default;