bool GlobalEnemy::AddSkill(uint32_t skill_id) { if(skill_id == 0) { IF_PRINT_WARNING(GLOBAL_DEBUG) << "function received an invalid skill_id argument: " << skill_id << std::endl; return false; } if(HasSkill(skill_id)) { IF_PRINT_WARNING(GLOBAL_DEBUG) << "failed to add skill because the enemy already knew this skill: " << skill_id << std::endl; return false; } GlobalSkill *skill = new GlobalSkill(skill_id); if(skill->IsValid() == false) { IF_PRINT_WARNING(GLOBAL_DEBUG) << "the skill to add failed to load: " << skill_id << std::endl; delete skill; return false; } // Insert the pointer to the new skill inside of the global skills vectors _skills.push_back(skill); _skills_id.push_back(skill_id); return true; }
void MenuMode::UpdateEquipmentInfo(GlobalCharacter *character, GlobalObject *object, EQUIP_VIEW view_type) { // Only update when necessary if ((_object == object) && (_character == character) && (_equip_view_type == view_type)) return; if (view_type == EQUIP_VIEW_NONE) return; _object = object; _character = character; _equip_view_type = view_type; // Clear the corresponding texts when there is no corresponding data if (!_object) { _object_name.Clear(); _elemental_icons.clear(); _status_icons.clear(); _spirit_number = 0; _equip_skills.clear(); _equip_skill_icons.clear(); _phys_header.Clear(); _mag_header.Clear(); _phys_stat.Clear(); _mag_stat.Clear(); } // Don't show any diff when there no slected character, // or not showing equip/unequip diffs. if (!_character || view_type == EQUIP_VIEW_CHAR) { _phys_stat_diff.Clear(); _mag_stat_diff.Clear(); } // If there is no object, we can return here. if (!_object) return; _object_name.SetText(_object->GetName()); // Loads elemental icons const std::vector<std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> >& elemental_effects = _object->GetElementalEffects(); _elemental_icons.clear(); for(std::vector<std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> >::const_iterator it = elemental_effects.begin(); it != elemental_effects.end(); ++it) { if(it->second != GLOBAL_INTENSITY_NEUTRAL) _elemental_icons.push_back(GlobalManager->Media().GetElementalIcon(it->first, it->second)); } // Loads status effects. const std::vector<std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY> >& status_effects = _object->GetStatusEffects(); _status_icons.clear(); for(std::vector<std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY> >::const_iterator it = status_effects.begin(); it != status_effects.end(); ++it) { if(it->second != GLOBAL_INTENSITY_NEUTRAL) _status_icons.push_back(GlobalManager->Media().GetStatusIcon(it->first, it->second)); } uint32 equip_phys_stat = 0; uint32 equip_mag_stat = 0; switch (_object->GetObjectType()) { default: // Should never happen return; case GLOBAL_OBJECT_WEAPON: { _is_weapon = true; GlobalWeapon* wpn = NULL; // If character view or unequipping, we take the character current weapon as a base if (view_type == EQUIP_VIEW_CHAR || view_type == EQUIP_VIEW_UNEQUIPPING) wpn = _character ? _character->GetWeaponEquipped() : NULL; else // We can take the given object as a base wpn = dynamic_cast<GlobalWeapon *>(_object); _spirit_number = wpn ? wpn->GetSpiritSlots().size() : 0; equip_phys_stat = wpn ? wpn->GetPhysicalAttack() : 0; equip_mag_stat = wpn ? wpn->GetMagicalAttack() : 0; const std::vector<uint32>& equip_skills = wpn->GetEquipmentSkills(); _equip_skills.clear(); _equip_skill_icons.clear(); // Display a max of 5 skills for (uint32 i = 0; i < equip_skills.size() && i < 5; ++i) { GlobalSkill *skill = new GlobalSkill(equip_skills[i]); if (skill && skill->IsValid()) { _equip_skills.push_back(vt_video::TextImage(skill->GetName(), TextStyle("text20"))); _equip_skill_icons.push_back(vt_video::StillImage()); vt_video::StillImage& img = _equip_skill_icons.back(); img.Load(skill->GetIconFilename()); img.SetWidthKeepRatio(15.0f); } delete skill; } break; } case GLOBAL_OBJECT_HEAD_ARMOR: case GLOBAL_OBJECT_TORSO_ARMOR: case GLOBAL_OBJECT_ARM_ARMOR: case GLOBAL_OBJECT_LEG_ARMOR: { _is_weapon = false; GlobalArmor* armor = NULL; // If character view or unequipping, we take the character current armor as a base if (view_type == EQUIP_VIEW_CHAR || view_type == EQUIP_VIEW_UNEQUIPPING) { uint32 equip_index = GetEquipmentPositionFromObjectType(_object->GetObjectType()); armor = _character ? _character->GetArmorEquipped(equip_index) : NULL; } else { // We can take the given object as a base armor = dynamic_cast<GlobalArmor *>(_object); } _spirit_number = armor ? armor->GetSpiritSlots().size() : 0; equip_phys_stat = armor ? armor->GetPhysicalDefense() : 0; equip_mag_stat = armor ? armor->GetMagicalDefense() : 0; const std::vector<uint32>& equip_skills = armor->GetEquipmentSkills(); _equip_skills.clear(); _equip_skill_icons.clear(); // Display a max of 5 skills for (uint32 i = 0; i < equip_skills.size() && i < 5; ++i) { GlobalSkill *skill = new GlobalSkill(equip_skills[i]); if (skill && skill->IsValid()) { _equip_skills.push_back(vt_video::TextImage(skill->GetName(), TextStyle("text20"))); _equip_skill_icons.push_back(vt_video::StillImage()); vt_video::StillImage& img = _equip_skill_icons.back(); img.Load(skill->GetIconFilename()); img.SetWidthKeepRatio(15.0f); } delete skill; } break; } } if (_is_weapon) { _phys_header.SetText(UTranslate("ATK:")); _mag_header.SetText(UTranslate("M.ATK:")); } else { _phys_header.SetText(UTranslate("DEF:")); _mag_header.SetText(UTranslate("M.DEF:")); } _phys_stat.SetText(NumberToString(equip_phys_stat)); _mag_stat.SetText(NumberToString(equip_mag_stat)); // We can stop here if there is no valid character, or simply showing // the object stats if (!_character || view_type == EQUIP_VIEW_CHAR) return; int32 phys_stat_diff = 0; int32 mag_stat_diff = 0; if (_is_weapon) { // Get the character's current attack GlobalWeapon* wpn = _character->GetWeaponEquipped(); uint32 char_phys_stat = 0; uint32 char_mag_stat = 0; if (_equip_view_type == EQUIP_VIEW_EQUIPPING) { char_phys_stat = (wpn ? wpn->GetPhysicalAttack() : 0); char_mag_stat = (wpn ? wpn->GetMagicalAttack() : 0); phys_stat_diff = equip_phys_stat - char_phys_stat; mag_stat_diff = equip_mag_stat - char_mag_stat; } else { // unequipping phys_stat_diff = char_phys_stat - equip_phys_stat; mag_stat_diff = char_mag_stat - equip_mag_stat; } } else { // armors uint32 equip_index = GetEquipmentPositionFromObjectType(_object->GetObjectType()); GlobalArmor* armor = _character->GetArmorEquipped(equip_index); uint32 char_phys_stat = 0; uint32 char_mag_stat = 0; if (_equip_view_type == EQUIP_VIEW_EQUIPPING) { char_phys_stat = (armor ? armor->GetPhysicalDefense() : 0); char_mag_stat = (armor ? armor->GetMagicalDefense() : 0); phys_stat_diff = equip_phys_stat - char_phys_stat; mag_stat_diff = equip_mag_stat - char_mag_stat; } else { // unequiping phys_stat_diff = char_phys_stat - equip_phys_stat; mag_stat_diff = char_mag_stat - equip_mag_stat; } } // Compute the overall stats diff with selected equipment if (phys_stat_diff > 0) { _phys_stat_diff.SetText("+" + NumberToString(phys_stat_diff)); _phys_diff_color.SetColor(Color::green); } else if (phys_stat_diff < 0) { _phys_stat_diff.SetText(NumberToString(phys_stat_diff)); _phys_diff_color.SetColor(Color::red); } else { _phys_stat_diff.Clear(); } if (mag_stat_diff > 0) { _mag_stat_diff.SetText("+" + NumberToString(mag_stat_diff)); _mag_diff_color.SetColor(Color::green); } else if (mag_stat_diff < 0) { _mag_stat_diff.SetText(NumberToString(mag_stat_diff)); _mag_diff_color.SetColor(Color::red); } else { _mag_stat_diff.Clear(); } }