void Battle::EagleEyeSkillAction(HeroBase & hero, const SpellStorage & spells, bool local) { if(spells.empty() || !hero.HaveSpellBook()) return; SpellStorage new_spells; new_spells.reserve(10); const Skill::Secondary eagleeye(Skill::Secondary::EAGLEEYE, hero.GetLevelSkill(Skill::Secondary::EAGLEEYE)); // filter spells for(SpellStorage::const_iterator it = spells.begin(); it != spells.end(); ++it) { const Spell & sp = *it; if(!hero.HaveSpell(sp)) { switch(eagleeye.Level()) { case Skill::Level::BASIC: // 20% if(3 > sp.Level() && eagleeye.GetValues() >= Rand::Get(1, 100)) new_spells.push_back(sp); break; case Skill::Level::ADVANCED: // 30% if(4 > sp.Level() && eagleeye.GetValues() >= Rand::Get(1, 100)) new_spells.push_back(sp); break; case Skill::Level::EXPERT: // 40% if(5 > sp.Level() && eagleeye.GetValues() >= Rand::Get(1, 100)) new_spells.push_back(sp); break; default: break; } } } // add new spell for(SpellStorage::const_iterator it = new_spells.begin(); it != new_spells.end(); ++it) { const Spell & sp = *it; if(local) { std::string msg = _("Through eagle-eyed observation, %{name} is able to learn the magic spell %{spell}."); String::Replace(msg, "%{name}", hero.GetName()); String::Replace(msg, "%{spell}", sp.GetName()); Game::PlayPickupSound(); Dialog::SpellInfo("", msg, sp); } } hero.AppendSpellsToBook(new_spells, true); }
void Skill::SecSkills::AddSkill(const Skill::Secondary & skill) { iterator it = std::find_if(begin(), end(), std::bind2nd(std::mem_fun_ref(&Secondary::isSkill), skill.Skill())); if(it != end()) (*it).SetLevel(skill.Level()); else { it = std::find_if(begin(), end(), std::not1(std::mem_fun_ref(&Secondary::isValid))); if(it != end()) (*it).Set(skill); else push_back(skill); } }
void Dialog::SecondarySkillInfo(const std::string & header, const std::string & message, const Skill::Secondary & skill, const bool ok_button) { Display & display = Display::Get(); const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; // preload AGG::PreloadObject(system); // cursor Cursor & cursor = Cursor::Get(); cursor.Hide(); cursor.SetThemes(cursor.POINTER); TextBox box1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); TextBox box2(message, Font::BIG, BOXAREA_WIDTH); const Sprite & border = AGG::GetICN(ICN::SECSKILL, 15); const u8 spacer = Settings::Get().QVGA() ? 5 : 10; Box box(box1.h() + spacer + box2.h() + spacer + border.h(), ok_button); Rect pos = box.GetArea(); if(header.size()) box1.Blit(pos); pos.y += box1.h() + spacer; if(message.size()) box2.Blit(pos); pos.y += box2.h() + spacer; // blit sprite pos.x = box.GetArea().x + (pos.w - border.w()) / 2; border.Blit(pos.x, pos.y); const Sprite & sprite = AGG::GetICN(ICN::SECSKILL, skill.GetIndexSprite1()); pos.x = box.GetArea().x + (pos.w - sprite.w()) / 2; sprite.Blit(pos.x, pos.y + 3); Text text; // small text text.Set(Skill::Secondary::String(skill.Skill()), Font::SMALL); pos.x = box.GetArea().x + (pos.w - text.w()) / 2; text.Blit(pos.x, pos.y + 3); text.Set(Skill::Level::String(skill.Level())); pos.x = box.GetArea().x + (pos.w - text.w()) / 2; text.Blit(pos.x, pos.y + 55); LocalEvent & le = LocalEvent::Get(); Button *button = NULL; Point pt; if(ok_button) { pt.x = box.GetArea().x + (box.GetArea().w - AGG::GetICN(system, 1).w()) / 2; pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h(); button = new Button(pt, system, 1, 2); } if(button) (*button).Draw(); cursor.Show(); display.Flip(); // message loop while(le.HandleEvents()) { if(!ok_button && !le.MousePressRight()) break; if(button) le.MousePressLeft(*button) ? button->PressDraw() : button->ReleaseDraw(); if(button && le.MouseClickLeft(*button)){ break; } if(HotKeyCloseWindow){ break; } } cursor.Hide(); if(button) delete button; }