character.js
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const characterModel = require('../model/character');
const analysisModel = require('../model/analysis');
module.exports = {
getCharacter: async function(req, res) {
if (!req.query.nickname) {
res.status(204).send();
return;
}
const nickname = req.query.nickname;
const characterCode = await characterModel.crwalCharacterCode(req.query.nickname);
if (characterCode == -1) {
res.status(500).send();
return;
} else if (characterCode == -2) {
res.status(404).send();
return;
}
const characterInfo = await characterModel.getCharacterInfo(nickname, characterCode);
if (characterInfo == -1) {
// 접근 권한 설정 필요
res.status(403).send();
return;
} else if (characterInfo == -2) {
// 점검중
res.status(503).send();
return;
} else if (characterInfo == -3) {
// 데이터를 받아오지 못함
res.status(502).send();
return;
} else if (characterInfo < 0) {
res.status(400).send();
return;
}
const analysisEquipment = await characterModel.analyzeEquipment(nickname, characterCode, characterInfo.character.job);
if (analysisEquipment == -1) {
// 접근 권한 설정 필요
res.status(403).send();
return;
} else if (analysisEquipment == -2) {
// 점검중
res.status(503).send();
return;
} else if (analysisEquipment < 0) {
res.status(400).send();
return;
}
const stats = analysisModel.analyzeStats(characterInfo, analysisEquipment);
const buffStats = analysisModel.getBuffStats(stats, characterInfo.character.job);
const result = {
info: characterInfo.character,
analysis: {
default: {
stats: stats,
efficiency: analysisModel.calculateEfficiency(stats, characterInfo.character.job, analysisEquipment.weapon)
},
buff: {
stats: buffStats,
efficiency: analysisModel.calculateEfficiency(buffStats, characterInfo.character.job, analysisEquipment.weapon)
}
}
};
console.log(JSON.stringify(result));
res.send(result);
}
};