오윤석

아이템 수치 분석 기능 추가

...@@ -94,6 +94,99 @@ const getCharacterInfo = async function(nickname, characterCode) { ...@@ -94,6 +94,99 @@ const getCharacterInfo = async function(nickname, characterCode) {
94 } 94 }
95 } 95 }
96 96
97 +const analyzeEquipment = async function(nickname, characterCode, job) {
98 + try {
99 + const resp = await axios.get("https://maplestory.nexon.com/Common/Character/Detail/" + encodeURI(nickname) + "/Equipment?p=" + characterCode);
100 +
101 + if (resp.data.indexOf("공개하지 않은 정보입니다.") > 0) {
102 + throw new Error("private_character");
103 + }
104 +
105 + const { JSDOM } = require('jsdom');
106 + const dom = new JSDOM(resp.data);
107 + const $ = (require('jquery'))(dom.window);
108 +
109 + // 아케인심볼 분석
110 + let majorArcane = 0;
111 + const arcaneURLs = [];
112 + $(".tab03_con_wrap .arcane_weapon_wrap .item_pot li span a").each(async function() {
113 + arcaneURLs.push("https://maplestory.nexon.com" + $(this).attr("href"));
114 + });
115 +
116 + for (let i = 0; i < arcaneURLs.length; i++) {
117 + const equipmentResp = await axios.get(arcaneURLs[i], {
118 + headers: {
119 + 'X-Requested-With': 'XMLHttpRequest'
120 + }
121 + });
122 +
123 + const equipmentDom = new JSDOM(equipmentResp.data.view);
124 + const $equipment = (require('jquery'))(equipmentDom.window);
125 +
126 + majorArcane += parseInt($equipment(".stet_info ul li:eq(2) .point_td font:eq(0)").text().substring(1));
127 + }
128 +
129 + // 장비 분석
130 + const jobModel = require('../model/job');
131 +
132 + let damagePercent = 0;
133 + let majorPercent = 0;
134 + let attackPowerPercent = 0;
135 + const equipmentURLs = [];
136 + $(".tab01_con_wrap .weapon_wrap .item_pot li span a").each(async function() {
137 + equipmentURLs.push("https://maplestory.nexon.com" + $(this).attr("href"));
138 + });
139 +
140 + for (let i = 0; i < equipmentURLs.length; i++) {
141 + const equipmentResp = await axios.get(equipmentURLs[i], {
142 + headers: {
143 + 'X-Requested-With': 'XMLHttpRequest'
144 + }
145 + });
146 +
147 + const equipmentDom = new JSDOM(equipmentResp.data.view);
148 + const $equipment = (require('jquery'))(equipmentDom.window);
149 +
150 + $equipment(".stet_info ul li").each(function() {
151 + const regexMajor1 = new RegExp(`${jobModel[job].major} : \\+(\\d)%`);
152 + const regexMajor2 = new RegExp(`올스탯 : \\+(\\d)%`);
153 + const regexAttackPower = (jobModel[job].major == "INT") ?
154 + new RegExp(`마력 : \\+(\\d)%`) :
155 + new RegExp(`공격력 : \\+(\\d)%`);
156 + const regexDamage = new RegExp(`데미지 : \\+(\\d)%`);
157 +
158 + if ($(this).find(".stet_th span").text() == "올스탯") {
159 + majorPercent += parseInt($(this).find(".point_td font:eq(0)").text().substring(1));
160 + } else if ($(this).find(".stet_th span").text().indexOf("잠재옵션") >= 0) {
161 + const values = $(this).find(".point_td").html().split("<br>");
162 + for (let j = 0; j < values.length; j++) {
163 + const value = values[j].trim();
164 + let regexResult;
165 +
166 + if (regexResult = (regexMajor1.exec(value) || regexMajor2.exec(value))) {
167 + majorPercent += parseInt(regexResult[1]);
168 + } else if (regexResult = regexAttackPower.exec(value)) {
169 + attackPowerPercent += parseInt(regexResult[1]);
170 + } else if (regexResult = regexDamage.exec(value)) {
171 + damagePercent += parseInt(regexResult[1]);
172 + }
173 + }
174 + }
175 + })
176 + }
177 +
178 + return {
179 + majorArcane: majorArcane,
180 + majorPercent: majorPercent,
181 + attackPowerPercent: attackPowerPercent,
182 + damagePercent: damagePercent
183 + };
184 + } catch (error) {
185 + console.log(error);
186 + return false;
187 + }
188 +}
189 +
97 module.exports = { 190 module.exports = {
98 getCharacter: async function(req, res) { 191 getCharacter: async function(req, res) {
99 if (!req.query.nickname) { 192 if (!req.query.nickname) {
...@@ -115,6 +208,13 @@ module.exports = { ...@@ -115,6 +208,13 @@ module.exports = {
115 return; 208 return;
116 } 209 }
117 210
211 + const analysisEquipment = await analyzeEquipment(nickname, characterCode, characterInfo.character.job);
212 + if (!analysisEquipment) {
213 + res.status(403).send();
214 + return;
215 + }
216 + console.log(analysisEquipment);
217 +
118 res.send(characterInfo); 218 res.send(characterInfo);
119 } 219 }
120 }; 220 };
...\ No newline at end of file ...\ No newline at end of file
......