1 #include "stdafx.h"
2 #include "game_info.h"
3 #include "creature.h"
4 #include "spell.h"
5 #include "creature_name.h"
6 #include "skill.h"
7 #include "view_id.h"
8 #include "level.h"
9 #include "position.h"
10 #include "creature_attributes.h"
11 #include "view_object.h"
12 #include "spell_map.h"
13 #include "item.h"
14 
CreatureInfo(WConstCreature c)15 CreatureInfo::CreatureInfo(WConstCreature c)
16     : viewId(c->getViewObject().id()),
17       uniqueId(c->getUniqueId()),
18       name(c->getName().bare()),
19       stackName(c->getName().stack()),
20       bestAttack(c->getBestAttack()),
21       morale(c->getMorale()) {
22 }
23 
getFirstName() const24 string PlayerInfo::getFirstName() const {
25   if (!firstName.empty())
26     return firstName;
27   else
28     return capitalFirst(name);
29 }
30 
getTitle() const31 string PlayerInfo::getTitle() const {
32   return title;
33 }
34 
getSkillNames(WConstCreature c)35 vector<PlayerInfo::SkillInfo> getSkillNames(WConstCreature c) {
36   vector<PlayerInfo::SkillInfo> ret;
37   for (auto skill : c->getAttributes().getSkills().getAllDiscrete())
38     ret.push_back(PlayerInfo::SkillInfo{Skill::get(skill)->getName(), Skill::get(skill)->getHelpText()});
39   for (SkillId id : ENUM_ALL(SkillId))
40     if (!Skill::get(id)->isDiscrete() && c->getAttributes().getSkills().getValue(id) > 0)
41       ret.push_back(PlayerInfo::SkillInfo{Skill::get(id)->getNameForCreature(c), Skill::get(id)->getHelpText()});
42   return ret;
43 }
44 
PlayerInfo(WConstCreature c)45 PlayerInfo::PlayerInfo(WConstCreature c) : bestAttack(c) {
46   firstName = c->getName().first().value_or("");
47   name = c->getName().bare();
48   title = c->getName().title();
49   description = capitalFirst(c->getAttributes().getDescription());
50   WItem weapon = c->getWeapon();
51   weaponName = weapon ? weapon->getName() : "";
52   viewId = c->getViewObject().id();
53   morale = c->getMorale();
54   levelName = c->getLevel()->getName();
55   positionHash = c->getPosition().getHash();
56   creatureId = c->getUniqueId();
57   attributes = AttributeInfo::fromCreature(c);
58   levelInfo.level = c->getAttributes().getExpLevel();
59   levelInfo.limit = c->getAttributes().getMaxExpLevel();
60   skills = getSkillNames(c);
61   effects.clear();
62   for (auto& adj : c->getBadAdjectives())
63     effects.push_back({adj.name, adj.help, true});
64   for (auto& adj : c->getGoodAdjectives())
65     effects.push_back({adj.name, adj.help, false});
66   spells.clear();
67   for (::Spell* spell : c->getAttributes().getSpellMap().getAll()) {
68     bool ready = c->isReady(spell);
69     spells.push_back({
70         spell->getId(),
71         spell->getName() + (ready ? "" : " [" + toString<int>(c->getSpellDelay(spell)) + "]"),
72         spell->getDescription(),
73         c->isReady(spell) ? none : optional<int>(c->getSpellDelay(spell))});
74   }
75 }
76 
getMinion(UniqueEntity<Creature>::Id id) const77 const CreatureInfo* CollectiveInfo::getMinion(UniqueEntity<Creature>::Id id) const {
78   for (auto& elem : minions)
79     if (elem.uniqueId == id)
80       return &elem;
81   return nullptr;
82 }
83 
84 
fromCreature(WConstCreature c)85 vector<AttributeInfo> AttributeInfo::fromCreature(WConstCreature c) {
86   auto genInfo = [c](AttrType type, int bonus, const char* help) {
87     return AttributeInfo {
88         getName(type),
89         type,
90         c->getAttr(type),
91         bonus,
92         help
93     };
94   };
95   return {
96       genInfo(
97           AttrType::DAMAGE,
98           c->isAffected(LastingEffect::RAGE) ? 1 : c->isAffected(LastingEffect::PANIC) ? -1 : 0,
99           "Affects if and how much damage is dealt in combat."
100       ),
101       genInfo(
102           AttrType::DEFENSE,
103           c->isAffected(LastingEffect::RAGE) ? -1 : (c->isAffected(LastingEffect::PANIC)) ? 1 : 0,
104           "Affects if and how much damage is taken in combat."
105       ),
106       genInfo(
107           AttrType::SPELL_DAMAGE,
108           0,
109           "Base value of magic attacks."
110       ),
111       genInfo(
112           AttrType::RANGED_DAMAGE,
113           0,
114           "Affects if and how much damage is dealt when shooting a ranged weapon."
115       ),
116       genInfo(
117           AttrType::SPEED,
118           c->isAffected(LastingEffect::SPEED) ? 1 : c->isAffected(LastingEffect::SLOWED) ? -1 : 0,
119           "Affects how much game time every action uses."
120       ),
121     };
122 }
123