feat: Show level up icon when level up is pending

This commit is contained in:
Vsevolod Kremianskii 2021-01-04 17:38:11 +07:00
parent 98f79ab0cd
commit 670b2f5936
8 changed files with 47 additions and 7 deletions

View file

@ -62,6 +62,7 @@ void Console::initCommands() {
addCommand("playanim", bind(&Console::cmdPlayAnim, this, _1));
addCommand("kill", bind(&Console::cmdKill, this, _1));
addCommand("additem", bind(&Console::cmdAddItem, this, _1));
addCommand("givexp", bind(&Console::cmdGiveXP, this, _1));
}
void Console::addCommand(const std::string &name, const CommandHandler &handler) {
@ -166,6 +167,21 @@ void Console::cmdAddItem(vector<string> tokens) {
object->addItem(tokens[1], stackSize);
}
void Console::cmdGiveXP(vector<string> tokens) {
if (tokens.size() < 2) {
print("Usage: givexp amount");
return;
}
ObjectSelector &selector = _game->module()->area()->objectSelector();
auto object = dynamic_pointer_cast<Creature>(selector.selectedObject());
if (!object) {
print("givexp: no creature selected");
return;
}
int amount = stoi(tokens[1]);
object->giveXP(amount);
}
void Console::print(const string &text) {
_output.push_front(text);
trimOutput();

View file

@ -81,6 +81,7 @@ private:
void cmdPlayAnim(std::vector<std::string> tokens);
void cmdKill(std::vector<std::string> tokens);
void cmdAddItem(std::vector<std::string> tokens);
void cmdGiveXP(std::vector<std::string> tokens);
// END Commands
};

View file

@ -104,13 +104,7 @@ void HUD::load() {
hideControl("LBL_INDICATEBG");
hideControl("LBL_ITEMRCVD");
hideControl("LBL_ITEMLOST");
hideControl("LBL_LEVELUP1");
hideControl("LBL_LEVELUP2");
hideControl("LBL_LEVELUP3");
hideControl("LBL_LIGHTSHIFT");
hideControl("LBL_LVLUPBG1");
hideControl("LBL_LVLUPBG2");
hideControl("LBL_LVLUPBG3");
hideControl("LBL_MAP");
hideControl("LBL_MOULDING1");
hideControl("LBL_MOULDING2");
@ -174,9 +168,13 @@ void HUD::update(float dt) {
lblChar.setVisible(true);
lblChar.setBorderFill(member->portrait());
lblBack.setVisible(true);
setControlVisible("LBL_LVLUPBG" + to_string(charIdx), member->isLevelUpPending());
setControlVisible("LBL_LEVELUP" + to_string(charIdx), member->isLevelUpPending());
} else {
lblChar.setVisible(false);
lblBack.setVisible(false);
hideControl("LBL_LVLUPBG" + to_string(charIdx));
hideControl("LBL_LEVELUP" + to_string(charIdx));
}
}

View file

@ -201,7 +201,13 @@ void MainMenu::onModuleSelected(const string &name) {
break;
}
CreatureAttributes attributes;
attributes.addClassLevels(ClassType::Soldier, 1);
playerCfg->setAttributes(attributes);
playerCfg->addEquippedItem("g_a_clothes01");
companionCfg->setAttributes(attributes);
companionCfg->addEquippedItem("g_a_clothes01");
Party &party = _game->party();

View file

@ -443,6 +443,11 @@ bool Creature::isInCombat() const {
return _inCombat;
}
bool Creature::isLevelUpPending() const {
int level = _attributes.getAggregateLevel();
return _xp >= level * (level + 1) * 500;
}
void Creature::setMovementRestricted(bool restricted) {
_movementRestricted = restricted;
}

View file

@ -91,6 +91,7 @@ public:
bool isMovementRestricted() const;
bool isInCombat() const;
bool isLevelUpPending() const;
float getAttackRange() const;

View file

@ -108,6 +108,18 @@ int CreatureAttributes::getClassLevel(ClassType clazz) const {
return maybeClassLevel != _classLevels.end() ? maybeClassLevel->second : 0;
}
int CreatureAttributes::getHitDice() const {
return _hitDice;
}
int CreatureAttributes::getAggregateLevel() const {
int result = 0;
for (auto &level : _classLevels) {
result += level.second;
}
return result;
}
bool CreatureAttributes::hasSkill(Skill skill) const {
auto maybeSkill = _skills.find(skill);
return maybeSkill != _skills.end() ? maybeSkill->second > 0 : false;

View file

@ -34,7 +34,8 @@ public:
ClassType getClassByPosition(int position) const;
int getLevelByPosition(int position) const;
int getClassLevel(ClassType clazz) const;
int getHitDice() const { return _hitDice; }
int getHitDice() const;
int getAggregateLevel() const;
// Abilities