swdb.js 28 KB

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