int Game_Battler::ApplyConditions() { int damageTaken = 0; for (int16_t inflicted : GetInflictedStates()) { RPG::State state = Data::states[inflicted - 1]; int hp = state.hp_change_val + (int)(std::ceil(GetMaxHp() * state.hp_change_max / 100.0)); int sp = state.sp_change_val + (int)(std::ceil(GetMaxHp() * state.sp_change_max / 100.0)); int source_hp = this->GetHp(); int source_sp = this->GetSp(); int src_hp = 0; int src_sp = 0; if (state.hp_change_type == state.ChangeType_lose) { src_hp = -std::min(source_hp - 1, hp); if(src_hp > 0) { src_hp = 0; } } else if(state.hp_change_type == state.ChangeType_gain) { src_hp = std::min(source_hp, hp); if(src_hp < 0) { src_hp = 0; } } else { src_hp = 0; } if (state.sp_change_type == state.ChangeType_lose) { src_sp = -std::min(source_sp, sp); if(src_sp > 0) { src_sp = 0; } } else if(state.sp_change_type == state.ChangeType_gain) { src_sp = std::min(source_sp, sp); if(src_sp < 0 ) { src_sp = 0; } } else { src_sp = 0; } this->ChangeHp(src_hp); this->ChangeSp(src_sp); damageTaken += src_hp; } if(damageTaken < 0) { return -damageTaken; } else { return damageTaken; } }
int Game_Battler::ApplyConditions() { int damageTaken = 0; for (int16_t inflicted : GetInflictedStates()) { // States are guaranteed to be valid RPG::State& state = *ReaderUtil::GetElement(Data::states, inflicted); int hp = state.hp_change_val + (int)(std::ceil(GetMaxHp() * state.hp_change_max / 100.0)); int sp = state.sp_change_val + (int)(std::ceil(GetMaxHp() * state.sp_change_max / 100.0)); int source_hp = this->GetHp(); int source_sp = this->GetSp(); int src_hp = 0; int src_sp = 0; if (state.hp_change_type == state.ChangeType_lose) { src_hp = -std::min(source_hp - 1, hp); if(src_hp > 0) { src_hp = 0; } } else if(state.hp_change_type == state.ChangeType_gain) { src_hp = std::min(source_hp, hp); if(src_hp < 0) { src_hp = 0; } } else { src_hp = 0; } if (state.sp_change_type == state.ChangeType_lose) { src_sp = -std::min(source_sp, sp); if(src_sp > 0) { src_sp = 0; } } else if (state.sp_change_type == state.ChangeType_gain) { src_sp = std::min(source_sp, sp); if(src_sp < 0 ) { src_sp = 0; } } else { src_sp = 0; } this->ChangeHp(src_hp); this->ChangeSp(src_sp); damageTaken += src_hp; } return damageTaken; }
void Game_Actor::Init() { const std::vector<RPG::Learning>& skills = Data::actors[data.ID - 1].skills; for (int i = 0; i < (int) skills.size(); i++) if (skills[i].level <= GetLevel()) LearnSkill(skills[i].skill_id); SetHp(GetMaxHp()); SetSp(GetMaxSp()); SetExp(exp_list[GetLevel() - 1]); }
void Game_Enemy::Setup(int enemy_id) { Transform(enemy_id); hp = GetMaxHp(); sp = GetMaxSp(); x = 0; y = 0; hidden = false; cycle = Utils::GetRandomNumber(0, levitation_frame_count - 1) * levitation_frame_cycle; flying_offset = 0; }
void PlayerHpBar::SetFeedback() { auto character = m_player->GetComponent<CharacterComponent>()->GetCharacter(); int hp = character->GetHp(); if (hp == m_lastHp) return; if (hp < 0) m_object->GetParent()->GetComponent<MainGame>()->AnnounceFinish(m_object->GetName()); m_lastHp = hp; int maxHp = character->GetMaxHp(); float perc = (float)hp / maxHp; auto sprite = m_greenBar->GetComponent<SpriteComponent>()->GetSprite(); auto rect = sprite->getTextureRect(); rect.width = (int)(m_barSize.x * perc); sprite->setTextureRect(rect); }
bool Game_Enemy::IsActionValid(const RPG::EnemyAction& action) { if (action.kind == action.Kind_skill) { if (!IsSkillUsable(action.skill_id)) { return false; } } switch (action.condition_type) { case RPG::EnemyAction::ConditionType_always: return true; case RPG::EnemyAction::ConditionType_switch: return Game_Switches[action.switch_id]; case RPG::EnemyAction::ConditionType_turn: { int turns = Game_Battle::GetTurn(); return Game_Battle::CheckTurns(turns, action.condition_param2, action.condition_param1); } case RPG::EnemyAction::ConditionType_actors: { std::vector<Game_Battler*> battlers; GetParty().GetActiveBattlers(battlers); int count = (int)battlers.size(); return count >= action.condition_param1 && count <= action.condition_param2; } case RPG::EnemyAction::ConditionType_hp: { int hp_percent = GetHp() * 100 / GetMaxHp(); return hp_percent >= action.condition_param1 && hp_percent <= action.condition_param2; } case RPG::EnemyAction::ConditionType_sp: { int sp_percent = GetSp() * 100 / GetMaxSp(); return sp_percent >= action.condition_param1 && sp_percent <= action.condition_param2; } case RPG::EnemyAction::ConditionType_party_lvl: { int party_lvl = Main_Data::game_party->GetAverageLevel(); return party_lvl >= action.condition_param1 && party_lvl <= action.condition_param2; } case RPG::EnemyAction::ConditionType_party_fatigue: { int party_exh = Main_Data::game_party->GetFatigue(); return party_exh >= action.condition_param1 && party_exh <= action.condition_param2; } default: return true; } }
void Game_Actor::Init() { const std::vector<RPG::Learning>& skills = GetActor().skills; for (int i = 0; i < (int)skills.size(); i++) { if (skills[i].level <= GetLevel()) { LearnSkill(skills[i].skill_id); } } RemoveInvalidData(); if (GetLevel() > 0) { SetHp(GetMaxHp()); SetSp(GetMaxSp()); SetExp(exp_list[GetLevel() - 1]); } AddEquipmentStates(); }
bool Game_Battler::UseItem(int item_id) { const RPG::Item& item = Data::items[item_id - 1]; if (item.type == RPG::Item::Type_medicine) { int hp_change = item.recover_hp_rate * GetMaxHp() / 100 + item.recover_hp; int sp_change = item.recover_sp_rate * GetMaxSp() / 100 + item.recover_sp; if (IsDead()) { // Check if item can revive if (item.state_set.empty() || !item.state_set[0]) { return false; } // Revive gives at least 1 Hp if (hp_change == 0) { ChangeHp(1); } } else if (item.ko_only) { // Must be dead return false; } ChangeHp(hp_change); SetSp(GetSp() + sp_change); for (std::vector<bool>::const_iterator it = item.state_set.begin(); it != item.state_set.end(); ++it) { if (*it) { RemoveState(*it); } } // TODO return true; } else if (item.type == RPG::Item::Type_material) { // TODO return false; } return false; }
bool Player::HpDraw(coord_def offset_) { d3dx_vprintf(offset_, 1.0f, D3DCOLOR_XRGB(150,150,255), "%2d", level); offset_.x+=30.0f; tex_system_heart.Draw(offset_.x, offset_.y, 1.0f, 0.0f); offset_.x+=30.0f; d3dx_vprintf(offset_, 1.0f, D3DCOLOR_XRGB(255,100,100), "%3d/%3d", GetHp()>0?GetHp():0, GetMaxHp()); return true; }
// constructors Unit(): aCurrentHp(GetMaxHp()) {}
void Game_Actor::SetHp(int hp) { data.current_hp = min(max(hp, 0), GetMaxHp()); }
bool Game_Battler::HasFullHp() const { return GetMaxHp() == GetHp(); }
bool Game_Battler::UseItem(int item_id) { const RPG::Item* item = ReaderUtil::GetElement(Data::items, item_id); if (!item) { Output::Warning("UseItem: Can't use item with invalid ID %d", item_id); return false; } if (item->type == RPG::Item::Type_medicine) { bool was_used = false; int hp_change = item->recover_hp_rate * GetMaxHp() / 100 + item->recover_hp; int sp_change = item->recover_sp_rate * GetMaxSp() / 100 + item->recover_sp; if (IsDead()) { // Check if item can revive if (item->state_set.empty() || !item->state_set[0]) { return false; } // Revive gives at least 1 Hp if (hp_change == 0) { ChangeHp(1); was_used = true; } } else if (item->ko_only) { // Must be dead return false; } if (hp_change > 0 && !HasFullHp()) { ChangeHp(hp_change); was_used = true; } if (sp_change > 0 && !HasFullSp()) { ChangeSp(sp_change); was_used = true; } for (int i = 0; i < (int)item->state_set.size(); i++) { if (item->state_set[i]) { was_used |= HasState(Data::states[i].ID); RemoveState(Data::states[i].ID); } } return was_used; } if (item->type == RPG::Item::Type_switch) { return true; } switch (item->type) { case RPG::Item::Type_weapon: case RPG::Item::Type_shield: case RPG::Item::Type_armor: case RPG::Item::Type_helmet: case RPG::Item::Type_accessory: return item->use_skill && UseSkill(item->skill_id); case RPG::Item::Type_special: return UseSkill(item->skill_id); } return false; }
bool Game_Battler::UseSkill(int skill_id, const Game_Battler* source) { const RPG::Skill* skill = ReaderUtil::GetElement(Data::skills, skill_id); if (!skill) { Output::Warning("UseSkill: Can't use skill with invalid ID %d", skill_id); return false; } bool cure_hp_percentage = false; bool was_used = false; if (skill->type == RPG::Skill::Type_normal || skill->type >= RPG::Skill::Type_subskill) { // Only takes care of healing skills outside of battle, // the other skill logic is in Game_BattleAlgorithm if (!(skill->scope == RPG::Skill::Scope_ally || skill->scope == RPG::Skill::Scope_party || skill->scope == RPG::Skill::Scope_self)) { return false; } // Calculate effect: float mul = GetAttributeMultiplier(skill->attribute_effects); int effect = skill->power; if (source != nullptr) { effect += source->GetAtk() * skill->physical_rate / 20 + source->GetSpi() * skill->magical_rate / 40; } effect *= mul; effect += (effect * Utils::GetRandomNumber(-skill->variance * 10, skill->variance * 10) / 100); if (effect < 0) effect = 0; // Cure states for (int i = 0; i < (int)skill->state_effects.size(); i++) { if (skill->state_effects[i]) { if (skill->reverse_state_effect) { was_used |= !HasState(Data::states[i].ID); AddState(Data::states[i].ID); } else { was_used |= HasState(Data::states[i].ID); RemoveState(Data::states[i].ID); // If Death is cured and HP is not selected, we set a bool so it later heals HP percentage if (i == 0 && !skill->affect_hp) { cure_hp_percentage = true; } } } } // Skills only increase hp and sp outside of battle if (effect > 0 && skill->affect_hp && !HasFullHp() && !IsDead()) { was_used = true; ChangeHp(effect); } else if (effect > 0 && cure_hp_percentage) { was_used = true; ChangeHp(GetMaxHp() * effect / 100); } if (effect > 0 && skill->affect_sp && !HasFullSp() && !IsDead()) { was_used = true; ChangeSp(effect); } } else if (skill->type == RPG::Skill::Type_teleport || skill->type == RPG::Skill::Type_escape) { Game_System::SePlay(skill->sound_effect); was_used = true; } else if (skill->type == RPG::Skill::Type_switch) { Game_System::SePlay(skill->sound_effect); Game_Switches.Set(skill->switch_id, true); was_used = true; } return was_used; }
bool Game_Battler::UseItem(int item_id, const Game_Battler* source) { const RPG::Item* item = ReaderUtil::GetElement(Data::items, item_id); if (!item) { Output::Warning("UseItem: Can't use item with invalid ID %d", item_id); return false; } if (item->type == RPG::Item::Type_medicine) { bool was_used = false; int revived = 0; int hp_change = item->recover_hp_rate * GetMaxHp() / 100 + item->recover_hp; int sp_change = item->recover_sp_rate * GetMaxSp() / 100 + item->recover_sp; if (IsDead()) { // Check if item can revive if (item->state_set.empty() || !item->state_set[0]) { return false; } } else if (item->ko_only) { // Must be dead return false; } for (int i = 0; i < (int)item->state_set.size(); i++) { if (item->state_set[i]) { was_used |= HasState(Data::states[i].ID); if (i == 0 && HasState(i + 1)) revived = 1; RemoveState(Data::states[i].ID); } } if (hp_change > 0 && !HasFullHp()) { ChangeHp(hp_change - revived); was_used = true; } if (sp_change > 0 && !HasFullSp()) { ChangeSp(sp_change); was_used = true; } return was_used; } if (item->type == RPG::Item::Type_switch) { return true; } bool do_skill = (item->type == RPG::Item::Type_special) || (item->use_skill && ( item->type == RPG::Item::Type_weapon || item->type == RPG::Item::Type_shield || item->type == RPG::Item::Type_armor || item->type == RPG::Item::Type_helmet || item->type == RPG::Item::Type_accessory ) ); if (do_skill) { auto* skill = ReaderUtil::GetElement(Data::skills, item->skill_id); if (skill == nullptr) { Output::Warning("UseItem: Can't use item %d skill with invalid ID %d", item->ID, item->skill_id); return false; } UseSkill(item->skill_id, source); } return false; }
void Game_Enemy::SetHp(int _hp) { hp = std::min(std::max(_hp, 0), GetMaxHp()); }