void Creature::rest() { if (healthCurr == 0) return; healthCurr += getCreatureType().getHealthRestIncrease(); if (healthCurr > healthMax) { healthCurr = healthMax; } }
bool Creature::updateLevel(){ //level maxes out at 9 if(level < 9){ ++level; //POSSIBLY UPDATE CURRENT HEALTH healthMax += getCreatureType().getHealthMaxPerLevel(); //attack stats update handled in getAttackStrength() return true; } return false; }
void update() { // BB Update // Creature Update for (auto i : Global_BB.m_creature_list) { i->identifyTarget(&Global_BB); if (getCreatureType(i) == (getCreatureType(i->m_target) + 1)%3) { flee.m_pOwner = i; flee.m_target_position = i->m_target->m_pos; flee.execute(); } else { approach.m_pOwner = i; approach.m_target_position = i->m_target->m_pos; approach.execute(); } } }
// room data void CreatureManager::setRoom(rapidjson::Document& data) { namespace rj = rapidjson; // process loading/unloading creatures // first populate creatures used in room std::vector<CreatureType> dataCrTypes; const rj::Value& crData = data["creatures"]; dataCrTypes.reserve(crData.Size()); for (rj::Value::ConstValueIterator it = crData.Begin(); it != crData.End(); ++it) { const CreatureType cType = getCreatureType((*it)["name"].GetString()); assert(cType != CreatureType::NONE); dataCrTypes.push_back(cType); } // convert to set for fast set operations CreatureTypeSet roomCreatures{dataCrTypes.cbegin(), dataCrTypes.cend()}; // find creatures to unload for (auto it = loaded.cbegin(); it != loaded.cend();) { if (roomCreatures.count(it->first) == 0) { unloadCreature(it->first); it = loaded.erase(it); } else ++it; } // find creatures to load for (const auto ct : roomCreatures) { if (loaded.count(ct) == 0) { loadCreature(ct); } } // spawn creatures std::size_t i = 0; int x; int y; for (rj::Value::ConstValueIterator it = crData.Begin(); it != crData.End(); ++it, ++i) { x = (*it)["x"].GetInt(); y = (*it)["y"].GetInt(); spawn(dataCrTypes[i], x, y); } }
int Creature::getElementalStrength() { return getCreatureType().getElementalStrength(); }
int Creature::getElementalWeakness() { return getCreatureType().getElementalWeakness(); }
int Creature::getAttackElement() { return getCreatureType().getElementalAttackType(); }
int Creature::getAttackStrength() { int attack = getCreatureType().getAttackBase(); attack += getLevel() * getCreatureType().getAttackPerLevel(); return attack; }
void Creature::setLevel(int num) { level = num; healthMax = getCreatureType().getHealthMaxPerLevel() * level + getCreatureType().getHealthMaxBase(); }