swdb.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. //const fs = require('fs-extra');
  2. //const csv = require('fast-csv');
  3. const dateFormat = require('dateformat');
  4. //const path = require('path');
  5. //const sanitize = require('sanitize-filename');
  6. module.exports = {
  7. defaultConfig: {
  8. enabled: true,
  9. debug: true
  10. },
  11. pluginName: 'SWDB',
  12. pluginDescription: 'Saves runs to SWDB.',
  13. target_host: 'http://localhost',
  14. target_port: '80',
  15. target_url: '/API/v1/log-run',
  16. temp: {},
  17. proxy: null,
  18. config: null,
  19. /**
  20. * Initializes he plugin.
  21. *
  22. * @param proxy The proxy.
  23. * @param Global configurations.
  24. */
  25. init(proxy, config) {
  26. this.proxy = proxy;
  27. this.config = config;
  28. proxy.on('apiCommand', (req, resp) => {
  29. try {
  30. wizardID = '';
  31. command = '';
  32. if (config.Config.Plugins[this.pluginName].enabled) {
  33. //const { command, wizard_id: wizardID } = req;
  34. command = req["command"];
  35. wizardID = req["wizard_id"];
  36. }
  37. if (!this.temp[wizardID]) {
  38. this.temp[wizardID] = {};
  39. }
  40. if (command === 'BattleScenarioStart') {
  41. //for (var key in req) {
  42. // this.log('DEBUG', `IVV SCE START: ${key}: ${req[key]}`);
  43. //}
  44. if (req["helper_list"] != null || req["mentor_helper_list"] != null || req["npc_friend_helper_list"] != null ){
  45. this.temp[wizardID].helper = 1;
  46. }
  47. else{
  48. this.temp[wizardID].helper = 0;
  49. }
  50. this.temp[wizardID].area = req.region_id;
  51. this.temp[wizardID].stage = req.stage_no;
  52. this.temp[wizardID].difficulty = req.difficulty;
  53. }
  54. if (command === 'BattleScenarioResult' || command === 'BattleDungeonResult' || command === 'BattleDimensionHoleDungeonResult') {
  55. //proxy.log({ type: 'info', source: 'plugin', name: this.pluginName, message: `IVV RUN RESULT: ${resp}` })
  56. for (var key in req) {
  57. this.log("info", `IVV REQ: ${key}: ${req[key]}`);
  58. }
  59. for (var key in resp) {
  60. this.log("info", `IVV RES: ${key}: ${resp[key]}`);
  61. }
  62. this.parse_normal(req, resp);
  63. }
  64. if (command === 'BattleRiftOfWorldsRaidResult') {
  65. this.parse_raid_rift(req, resp);
  66. }
  67. if (command === 'BattleRiftDungeonResult') {
  68. this.parse_elemental_rift(req, resp);
  69. }
  70. }
  71. catch (e) {
  72. proxy.log({ type: 'error', source: 'plugin', name: this.pluginName, message: `An unexpected error occured: ${e.message}` });
  73. }
  74. });
  75. },
  76. /**
  77. * Parses a reward item (no runes!).
  78. *
  79. * @param crate The crate object.
  80. * @return array of {item, unit, pieces, quantity, shapeshifting}
  81. */
  82. getItem(crate) {
  83. item = 0;
  84. unit = 0;
  85. pieces = 0;
  86. quantity = 0;
  87. shapeshifting = 0;
  88. if (crate.random_scroll && (crate.random_scroll.item_master_id === 1 || crate.random_scroll.item_master_id === 8 || crate.random_scroll.item_master_id === 2)){
  89. // 1: Unknown scroll
  90. // 2: Mystical Scroll
  91. // 8: Summoning Stones
  92. item = crate.random_scroll.item_master_id;
  93. quantity = crate.random_scroll.item_quantity;
  94. }
  95. if (crate.costume_point) {
  96. shapeshifting = crate.costume_point;
  97. }
  98. if (crate.rune_upgrade_stone) {
  99. item = 'Power Stone'; // TODO: Do they exist?
  100. quantity = crate.rune_upgrade_stone.item_quantity;
  101. }
  102. if (crate.unit_info) {
  103. unit = crate.unit_info.unit_master_id;
  104. }
  105. if (crate.material) {
  106. item = crate.material.item_master_id;
  107. quantity = crate.material.item_quantity;
  108. }
  109. if (crate.summon_pieces) {
  110. pieces = crate.summon_pieces.item_master_id;
  111. quantity = crate.summon_pieces.item_quantity;
  112. }
  113. if (crate.craft_stuff) {
  114. item = crate.craft_stuff.item_master_id;
  115. quantity = crate.craft_stuff.item_quantity;
  116. }
  117. drop = {item, unit, pieces, quantity, shapeshifting}
  118. return drop;
  119. },
  120. /**
  121. * TODO! Unaddapted.
  122. * Parses a rift reward item (no runes!).
  123. *
  124. * @param crate The crate object.
  125. * @return array of {item, unit, pieces, quantity}
  126. */
  127. getItemRift(item, entry) {
  128. if (item.type === 8) {
  129. const rune = item.info;
  130. entry.drop = 'Rune';
  131. entry.grade = `${rune.class}*`;
  132. entry.sell_value = rune.sell_value;
  133. entry.set = gMapping.rune.sets[rune.set_id];
  134. entry.slot = rune.slot_no;
  135. entry.efficiency = gMapping.getRuneEfficiency(rune).current;
  136. entry.rarity = gMapping.rune.class[rune.sec_eff.length];
  137. entry.main_stat = gMapping.getRuneEffect(rune.pri_eff);
  138. entry.prefix_stat = gMapping.getRuneEffect(rune.prefix_eff);
  139. rune.sec_eff.forEach((substat, i) => {
  140. entry[`sub${i + 1}`] = gMapping.getRuneEffect(substat);
  141. });
  142. }
  143. if (item.info.craft_type_id) {
  144. enhancement = this.getEnchantVals(item.info.craft_type_id, item.info.craft_type);
  145. entry.drop = enhancement.drop;
  146. entry.sell_value = item.sell_value;
  147. entry.set = enhancement.set;
  148. entry.main_stat = enhancement.type;
  149. entry.sub1 = enhancement.min;
  150. entry.sub2 = enhancement.max;
  151. }
  152. return entry;
  153. },
  154. /**
  155. * TODO! Will I need this.
  156. * Saves run data to a file in CSV format.
  157. *
  158. */
  159. saveToFile(entry, filename, headers, proxy) {
  160. const csvData = [];
  161. const self = this;
  162. fs.ensureFile(path.join(config.Config.App.filesPath, filename), err => {
  163. if (err) {
  164. return;
  165. }
  166. csv
  167. .fromPath(path.join(config.Config.App.filesPath, filename), { ignoreEmpty: true, headers, renameHeaders: true })
  168. .on('data', data => {
  169. csvData.push(data);
  170. })
  171. .on('end', () => {
  172. csvData.push(entry);
  173. csv.writeToPath(path.join(config.Config.App.filesPath, filename), csvData, { headers }).on('finish', () => {
  174. proxy.log({ type: 'success', source: 'plugin', name: self.pluginName, message: `Saved run data to ${filename}` });
  175. });
  176. });
  177. });
  178. },
  179. /**
  180. * Parses a battle data.
  181. * Valid for scenario, dungeons and Dimensional Hole.
  182. *
  183. * @param req The request
  184. * @param resp The response.
  185. */
  186. parse_normal(req, resp) {
  187. const { command } = req;
  188. const { wizard_id: wizardID, wizard_name: wizardName } = resp.wizard_info;
  189. const run = {};
  190. const run_party = {};
  191. const run_k_party = {};
  192. log = true;
  193. if (command === 'BattleDungeonResult') {
  194. //for (var key in req) {
  195. // this.log("DEBUG", `IVV DUNGEON REQ: ${key}: ${req[key]}`);
  196. //}
  197. if (req.dungeon_id > 10000){
  198. // Hall of Heroes or unknown
  199. log = false;
  200. }
  201. run.area = req.dungeon_id;
  202. run.stage = req.stage_id;
  203. run.difficulty = 0
  204. // TODO: Read request
  205. run.helper = 0;
  206. }
  207. if (command === 'BattleScenarioResult') {
  208. //for (var key in this.temp[wizardID]) {
  209. // this.log("DEBUG", `IVV TEMP: ${key}: ${this.temp[wizardID][key]}`);
  210. //}
  211. //for (var key in req) {
  212. // this.log("DEBUG", `IVV REQ: ${key}: ${req[key]}`);
  213. //}
  214. run.helper = this.temp[wizardID].helper;
  215. run.area = this.temp[wizardID].area;
  216. run.stage = this.temp[wizardID].stage;
  217. run.difficulty = this.temp[wizardID].difficulty;
  218. }
  219. if (command === 'BattleDimensionHoleDungeonResult') {
  220. //if (gMapping.dungeon[resp.dungeon_id]) {
  221. // run.dungeon = `${gMapping.dungeon[resp.dungeon_id]} Level ${resp.difficulty}`;
  222. //}
  223. //for (var key in req) {
  224. // this.log("DEBUG", `IVV DIMENSONALE REQ: ${key}: ${req[key]}`);
  225. //}
  226. run.area = resp.dungeon_id;
  227. run.stage = resp.difficulty;
  228. run.difficulty = 0
  229. run.helper = 0;
  230. }
  231. run.uid = wizardID;
  232. run.win = resp.win_lose; // 1/0 2 is lost in scenario
  233. run.dtime = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss');
  234. const reward = resp.reward ? resp.reward : {};
  235. run.time = req.clear_time ? req.clear_time : 0;
  236. run.mana = reward.mana ? reward.mana : 0;
  237. run.energy = reward.energy ? reward.energy : 0;
  238. run.crystal = reward.crystal ? reward.crystal : 0;
  239. // TODO: GET
  240. //run.helper = 0;
  241. run.rune = {};
  242. run.unit = 0;
  243. run.unit_pieces = {};
  244. run.sd = 0;
  245. run.item = {};
  246. run.shapeshifting = 0;
  247. if (reward.crate) {
  248. run.mana = reward.crate.mana ? run.mana + reward.crate.mana : run.mana;
  249. run.energy = reward.crate.energy ? run.energy + reward.crate.energy : run.energy;
  250. run.crystal = reward.crate.crystal ? run.crystal + reward.crate.crystal : run.crystal;
  251. if (reward.crate.rune) {
  252. const rune = reward.crate.rune;
  253. //for (var key in rune) {
  254. // this.proxy.log({ type: 'info', source: 'plugin', name: this.pluginName, message: `IVV RUNE: ${key}: ${rune[key]}` })
  255. //}
  256. run.rune.id = rune.rune_id;
  257. run.rune.grade = rune.class;
  258. run.rune.value = rune.sell_value;
  259. run.rune.set = rune.set_id;
  260. run.rune.slot = rune.slot_no;
  261. run.rune.efficiency = gMapping.getRuneEfficiency(rune).current;
  262. run.rune.quality = rune.rank;
  263. run.rune.main = rune.pri_eff[0];
  264. run.rune.main_value = rune.pri_eff[1];
  265. if (rune.prefix_eff){
  266. run.rune.innate = rune.prefix_eff[0];
  267. run.rune.innate_value = rune.prefix_eff[1];
  268. }
  269. run.rune['substat_1'] = 0;
  270. run.rune['substat_1_value'] = 0;
  271. run.rune['substat_2'] = 0;
  272. run.rune['substat_2_value'] = 0;
  273. run.rune['substat_3'] = 0;
  274. run.rune['substat_3_value'] = 0;
  275. run.rune['substat_4'] = 0;
  276. run.rune['substat_4_value'] = 0;
  277. rune.sec_eff.forEach((substat, i) => {
  278. run.rune[`substat_${i + 1}`] = substat[0];
  279. run.rune[`substat_${i + 1}_value`] = substat[1];
  280. });
  281. }
  282. else {
  283. for (var key in reward.crate) {
  284. this.proxy.log({ type: 'info', source: 'plugin', name: this.pluginName, message: `IVV ITEM: ${key}: ${reward.crate[key]}` })
  285. }
  286. drop = this.getItem(reward.crate);
  287. if (drop.unit){
  288. run.unit.id = drop.unit;
  289. }
  290. if (drop.pieces){
  291. run.unit_pieces.id = drop.pieces;
  292. run.unit_pieces.quantity = drop.quantity;
  293. }
  294. if (drop.item){
  295. run.item.id = drop.item;
  296. run.item.quantity = drop.quantity;
  297. }
  298. run.shapeshifting = drop.shapeshifting;
  299. }
  300. }
  301. if (resp.instance_info) {
  302. run.sd = resp.instance_info;
  303. }
  304. if (resp.unit_list && resp.unit_list.length > 0) {
  305. resp.unit_list.forEach((unit, i) => {
  306. run_party[i] = unit.unit_master_id;
  307. run_k_party[i] = unit.unit_id;
  308. });
  309. }
  310. json_rune = '[';
  311. if (run.rune.id != undefined){
  312. json_rune += '{';
  313. json_rune += `"id": "${run.rune.id}", `;
  314. json_rune += `"stars": "${run.rune.grade}", `;
  315. json_rune += `"type": "${run.rune.set}", `;
  316. json_rune += `"slot": "${run.rune.slot}", `;
  317. json_rune += `"efficiency": "${run.rune.efficiency}", `;
  318. json_rune += `"quality": "${run.rune.quality}", `;
  319. // TODO: Get
  320. json_rune += `"ancient": 0, `;
  321. json_rune += `"value": "${run.rune.value}", `;
  322. json_rune += `"main_stat": "${run.rune.main}", `;
  323. json_rune += `"main_stat_value": "${run.rune.main_value}", `;
  324. json_rune += `"innate_stat": "${run.rune.innate}", `;
  325. json_rune += `"innate_stat_value": "${run.rune.innate_value}", `;
  326. json_rune += `"substat_1": "${run.rune.substat_1}", `;
  327. json_rune += `"substat_1_value": "${run.rune.substat_1_value}", `;
  328. json_rune += `"substat_2": "${run.rune.substat_2}", `;
  329. json_rune += `"substat_2_value": "${run.rune.substat_2_value}", `;
  330. json_rune += `"substat_3": "${run.rune.substat_3}", `;
  331. json_rune += `"substat_3_value": "${run.rune.substat_3_value}", `;
  332. json_rune += `"substat_4": "${run.rune.substat_4}", `;
  333. json_rune += `"substat_4_value": "${run.rune.substat_4_value}"`;
  334. json_rune += '}';
  335. }
  336. json_rune = json_rune + "]";
  337. json_item = '[';
  338. if (run.item.id != undefined){
  339. json_item += '{';
  340. json_item += `"id": "${run.item.id}", `;
  341. json_item += `"quantity": "${run.item.quantity}"`;
  342. json_item += '}';
  343. }
  344. json_item = json_item + "]";
  345. json_unit_pieces = '[';
  346. if (run.unit_pieces.length > 0){
  347. json_unit_pieces += '{';
  348. json_unit_pieces += `"id": "${run.unit_pieces.id}", `;
  349. json_unit_pieces += `"quantity": "${run.unit_pieces.quantity}"`;
  350. json_unit_pieces += '}';
  351. }
  352. json_unit_pieces = json_unit_pieces + "]";
  353. json_party = '[';
  354. resp.unit_list.forEach((unit, i) => {
  355. json_party = json_party + '{"unit_id": ' + run_party[i] + ', "unit_master_id": ' + run_k_party[i] + '},';
  356. });
  357. json_party = json_party.slice(0, -1) + "]";
  358. json = `{`;
  359. json += `"uid": "${run.uid}", `;
  360. json += `"dtime": "${run.dtime}", `;
  361. json += `"area": "${run.area}", `;
  362. json += `"stage": "${run.stage}", `;
  363. json += `"difficulty": "${run.difficulty}", `;
  364. json += `"win": "${run.win}", `;
  365. json += `"time": "${run.time}", `;
  366. json += `"mana": "${run.mana}", `;
  367. json += `"energy": "${run.energy}", `;
  368. json += `"crystal": "${run.crystal}", `;
  369. json += `"rune": ${json_rune}, `;
  370. json += `"sd": ${run.sd}, `;
  371. json += `"item": ${json_item}, `;
  372. json += `"unit": ${run.unit}, `;
  373. json += `"unit_pieces": ${json_unit_pieces}, `;
  374. json += `"shapeshifting": ${run.shapeshifting}, `;
  375. json += `"party": ${json_party}, `;
  376. json += `"helper": "${run.helper}"`;
  377. json += `}`;
  378. this.log('DEBUG', `json: ${json}`)
  379. //const filename = sanitize(`${wizardName}-${wizardID}-runs.csv`);
  380. //const filename = sanitize(`IVV-${wizardName}-${wizardID}-runs.csv`);
  381. //this.saveToFile(entry, filename, headers, proxy);
  382. // Make the request
  383. //var inspect = require('eyespect').inspector();
  384. var request = require('request')
  385. var postData = {
  386. name: 'data',
  387. value: json
  388. }
  389. var querystring = require('querystring');
  390. var http = require('http');
  391. var fs = require('fs');
  392. var post_data = querystring.stringify({
  393. 'data' : json
  394. });
  395. // An object of options to indicate where to post to
  396. var post_options = {
  397. host: '192.168.1.101',//this.target_host,
  398. port: this.target_port,
  399. path: this.target_url,
  400. method: 'POST',
  401. headers: {
  402. 'Content-Type': 'application/x-www-form-urlencoded',
  403. 'Content-Length': Buffer.byteLength(post_data)
  404. }
  405. };
  406. // Set up the request
  407. var resp = ""
  408. var post_req = http.request(post_options, function(res) {
  409. res.setEncoding('utf8');
  410. res.on('data', function (chunk) {
  411. resp = chunk;
  412. });
  413. });
  414. // post the data
  415. post_req.write(post_data);
  416. post_req.end();
  417. },
  418. /**
  419. * TODO Unaddapted.
  420. * Parses a battle data.
  421. * Valid for Rift Raids.
  422. *
  423. * @param req The request
  424. * @param resp The response.
  425. */
  426. parse_raid_rift(req, resp) {
  427. const { wizard_id: wizardID, wizard_name: wizardName } = resp.wizard_info;
  428. let run = {};
  429. if (gMapping.dungeon[req.dungeon_id]) {
  430. run.dungeon = `${gMapping.elemental_rift_dungeon[req.dungeon_id]}`;
  431. isElemental = true;
  432. }
  433. //const winLost = resp.win_lose === 1 ? 'Win' : 'Did not kill';
  434. run.dtime = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss');
  435. //run.result = winLost;
  436. run.win = resp.win_lose;
  437. run.rune = {};
  438. run.unit = 0;
  439. run.unit_pieces = {};
  440. run.sd = 0;
  441. run.item = {};
  442. run.shapeshifting = 0;
  443. run.time = req.clear_time ? req.clear_time : 0;
  444. const reward = resp.reward ? resp.reward : {};
  445. if (resp.win_lose === 1) {
  446. // No crate: Mana of shapeshifting stones
  447. if (!reward.crate) {
  448. const reward = resp.battle_reward_list.find(value => value.wizard_id === resp.wizard_info.wizard_id).reward_list[0];
  449. if (reward.item_master_id === 6) {
  450. run.shapeshifting = reward.item_quantity;
  451. }
  452. else {
  453. run.mana = reward.item_quantity;
  454. }
  455. }
  456. // Rune craft item
  457. else if (reward.crate.changestones) {
  458. const item = {
  459. info: {
  460. craft_type: reward.crate.changestones[0].craft_type,
  461. craft_type_id: reward.crate.changestones[0].craft_type_id
  462. },
  463. sell_value: reward.crate.changestones[0].sell_value
  464. };
  465. run.drop= this.getItemRift(item, run);
  466. }
  467. // Rune
  468. else if (reward.crate.rune) {
  469. const rune = reward.crate.rune;
  470. //for (var key in rune) {
  471. // this.proxy.log({ type: 'info', source: 'plugin', name: this.pluginName, message: `IVV RUNE: ${key}: ${rune[key]}` })
  472. //}
  473. run.rune.id = rune.rune_id;
  474. run.rune.grade = rune.class;
  475. run.rune.value = rune.sell_value;
  476. run.rune.set = rune.set_id;
  477. run.rune.slot = rune.slot_no;
  478. run.rune.efficiency = gMapping.getRuneEfficiency(rune).current;
  479. run.rune.quality = rune.rank;
  480. run.rune.main = rune.pri_eff[0];
  481. run.rune.main_value = rune.pri_eff[1];
  482. if (rune.prefix_eff){
  483. run.rune.innate = rune.prefix_eff[0];
  484. run.rune.innate_value = rune.prefix_eff[1];
  485. }
  486. rune.sec_eff.forEach((substat, i) => {
  487. run.rune[`substat_${i + 1}`] = substat[0];
  488. run.rune[`substat_${i + 1}_value`] = substat[1];
  489. });
  490. }
  491. // Unit (Rainbowmon)
  492. else if (reward.crate.unit_info && reward.crate.unit_info.unit_master_id > 0) {
  493. run.unit.id = reward.crate.unit_info.unit_master_id;
  494. }
  495. // Item
  496. else if (!run.drop && resp.reward.crate) {
  497. //run.drop = this.getItem(reward.resp.reward.crate);
  498. if (resp.reward.crate.random_scroll && (resp.reward.crate.random_scroll.item_master_id === 1 || resp.reward.crate.random_scroll.item_master_id === 8 || resp.reward.crate.random_scroll.item_master_id === 2)){
  499. // 1: Unknown scroll
  500. // 2: Mystical Scroll
  501. // 8: Summoning Stones
  502. run.item.id = resp.reward.crate.random_scroll.item_master_id;
  503. run.item.quantity = resp.reward.crate.random_scroll.item_quantity;
  504. }
  505. //if (resp.reward.crate.costume_point) {
  506. // shapeshifting = resp.reward.crate.costume_point;
  507. //}
  508. //if (resp.reward.crate.rune_upgrade_stone) {
  509. // item = 'Power Stone'; // TODO: Do they exist?
  510. // quantity = resp.reward.crate.rune_upgrade_stone.item_quantity;
  511. //}
  512. //if (resp.reward.crate.unit_info) {
  513. // unit = resp.reward.crate.unit_info.unit_master_id;
  514. //}
  515. if (resp.reward.crate.material) {
  516. item = resp.reward.crate.material.item_master_id;
  517. quantity = resp.reward.crate.material.item_quantity;
  518. }
  519. //if (resp.reward.crate.summon_pieces) {
  520. // pieces = resp.reward.crate.summon_pieces.item_master_id;
  521. // quantity = resp.reward.crate.summon_pieces.item_quantity;
  522. //}
  523. if (resp.reward.crate.craft_stuff) {
  524. item = resp.reward.crate.craft_stuff.item_master_id;
  525. quantity = resp.reward.crate.craft_stuff.item_quantity;
  526. }
  527. }
  528. else {
  529. run.drop = 'unknown';
  530. }
  531. }
  532. if (resp.unit_list && resp.unit_list.length > 0) {
  533. resp.unit_list.forEach((unit, i) => {
  534. run_party[i] = unit.unit_master_id;
  535. run_k_party[i] = unit.unit_id;
  536. });
  537. }
  538. //const filename = sanitize(`${wizardName}-${wizardID}-raid-runs.csv`);
  539. //this.saveToFile(run. filename, headers, proxy);
  540. },
  541. /**
  542. * TODO Unaddapted.
  543. * Parses a battle data.
  544. * Valid for Rift Dungeons.
  545. *
  546. * @param req The request
  547. * @param resp The response.
  548. */
  549. parse_elemental_rift(req, resp) {
  550. const { wizard_id: wizardID, wizard_name: wizardName } = resp.wizard_info;
  551. let entry = {};
  552. if (gMapping.dungeon[req.dungeon_id]) {
  553. entry.dungeon = `${gMapping.elemental_rift_dungeon[req.dungeon_id]}`;
  554. isElemental = true;
  555. }
  556. const winLost = req.battle_result === 1 ? 'Win' : 'Did not kill';
  557. entry.date = dateFormat(new Date(), 'yyyy-mm-dd HH:MM');
  558. entry.result = winLost;
  559. if (resp.item_list && resp.item_list.length > 0) {
  560. resp.item_list.forEach((item, i) => {
  561. if (item.is_boxing !== 1 || item.id === 2001) {
  562. entry[`item${i + 1}`] = `${gMapping.craftMaterial[item.id]} x${item.quantity}`;
  563. } else {
  564. if (item.id === 2) {
  565. entry.drop = 'Mystical Scroll';
  566. }
  567. if (item.id === 8) {
  568. entry.drop = `Summoning Stones x${item.item_quantity}`;
  569. }
  570. if (item.info && item.info.unit_master_id > 0) {
  571. entry.drop = `${gMapping.getMonsterName(item.info.unit_master_id)} ${item.class}`;
  572. }
  573. if ((item.info && item.info.craft_type_id) || item.type === 8) {
  574. entry = this.getItemRift(item, entry);
  575. }
  576. }
  577. });
  578. }
  579. if (resp.unit_list && resp.unit_list.length > 0) {
  580. resp.unit_list.forEach((unit, i) => {
  581. entry[`team${i + 1}`] = gMapping.getMonsterName(unit.unit_master_id);
  582. });
  583. }
  584. json_rune = '[';
  585. if (run.rune.length() > 0){
  586. json_rune += `"id": "${run.rune.id}", `;
  587. json_rune += `"grade": "${run.rune.grade}", `;
  588. json_rune += `"set": "${run.rune.set}", `;
  589. json_rune += `"slot": "${run.rune.slot}", `;
  590. json_rune += `"efficiency": "${run.rune.efficiency}", `;
  591. json_rune += `"quality": "${run.rune.quality}", `;
  592. json_rune += `"value": "${run.rune.value}", `;
  593. json_rune += `"main_stat": "${run.rune.main}", `;
  594. json_rune += `"main_stat_value": "${run.rune.main_value}", `;
  595. json_rune += `"innate_stat": "${run.rune.innate}", `;
  596. json_rune += `"innate_stat_value": "${run.rune.innate_value}", `;
  597. json_rune += `"substat_1": "${run.rune.substat_1}", `;
  598. json_rune += `"substat_1_value": "${run.rune.substat_1_value}", `;
  599. json_rune += `"substat_2": "${run.rune.substat_2}", `;
  600. json_rune += `"substat_2_value": "${run.rune.substat_2_value}", `;
  601. json_rune += `"substat_3": "${run.rune.substat_3}", `;
  602. json_rune += `"substat_4_value": "${run.rune.substat_3_value}", `;
  603. json_rune += `"substat_4": "${run.rune.substat_4}", `;
  604. json_rune += `"substat_4_value": "${run.rune.substat_4_value}", `;
  605. }
  606. json_rune = json_party.slice(0, -1) + "]";
  607. json_item = '[';
  608. if (run.item.length() > 0){
  609. json_item += `"id": "${run.item.id}", `;
  610. json_item += `"quantity": "${run.item.quantity}", `;
  611. }
  612. json_item = json_party.slice(0, -1) + "]";
  613. json_unit_pieces = '[';
  614. if (run.unit_pieces.length() > 0){
  615. json_unit_pieces += `"id": "${run.unit_pieces.id}", `;
  616. json_unit_pieces += `"quantity": "${run.unit_pieces.quantity}", `;
  617. }
  618. json_unit_pieces = json_party.slice(0, -1) + "]";
  619. json_party = '[';
  620. resp.unit_list.forEach((unit, i) => {
  621. json_party = json_party + '{"unit_id": ' + run_party[i] + ', "unit_master_id": ' + run_k_party[i] + '},';
  622. });
  623. json_party = json_party.slice(0, -1) + "]";
  624. //this.log('DEBUG', `IVV json_party: ${json_party}`)
  625. json = `{`;
  626. json += `"dtime": "${run.dtime}", `;
  627. json += `"area": "${run.dungeon}", `;
  628. json += `"stage": "${run.stage}", `;
  629. json += `"difficulty": "${run.difficulty}", `;
  630. json += `"win": "${run.win}", `;
  631. json += `"time": "${run.time}", `;
  632. json += `"mana": "${run.mana}", `;
  633. json += `"energy": "${run.energy}", `;
  634. json += `"crystal": "${run.crystal}", `;
  635. json += `"rune": ${json_rune}, `;
  636. json += `"sd": ${run.sd}, `;
  637. json += `"item": ${json_item}, `;
  638. json += `"unit": ${run.unit}, `;
  639. json += `"unit_pieces": ${json_unit_pieces}, `;
  640. json += `"sapeshifting": ${run.sapeshifting}, `;
  641. json += `"party": ${json_party}`;
  642. json += `}`;
  643. this.log('DEBUG', `json: ${json}`)
  644. },
  645. /**
  646. * TODO ???
  647. */
  648. getEnchantVals(craftID, craftType) {
  649. const map = {};
  650. const typeNumber = Number(craftID.toString().slice(-4, -2));
  651. map.set = gMapping.rune.sets[Number(craftID.toString().slice(0, -4))];
  652. map.grade = gMapping.rune.quality[Number(craftID.toString().slice(-1))];
  653. map.type = gMapping.rune.effectTypes[typeNumber];
  654. if (craftType === 2) {
  655. map.min = gMapping.grindstone[typeNumber].range[Number(craftID.toString().slice(-1))].min;
  656. map.max = gMapping.grindstone[typeNumber].range[Number(craftID.toString().slice(-1))].max;
  657. map.drop = 'Grindstone';
  658. } else {
  659. map.min = gMapping.enchanted_gem[typeNumber].range[Number(craftID.toString().slice(-1))].min;
  660. map.max = gMapping.enchanted_gem[typeNumber].range[Number(craftID.toString().slice(-1))].max;
  661. map.drop = 'Enchanted Gem';
  662. }
  663. return map;
  664. },
  665. /**
  666. * Prints a messageto the SWEX output.
  667. *
  668. * @param type Log type. Debug type will be printed depending on config.
  669. * @param msg The message to log.
  670. */
  671. log(type, msg){
  672. //if (type != "debug" || this.config.Config.Plugins[this.pluginName].debug == true){
  673. this.proxy.log({ type: type, source: 'plugin', name: this.pluginName, message: msg });
  674. //}
  675. }
  676. };