int CmdCast::execute() { int turns = 0; SpellPtr spell = getSpell(); Engine::instance().render(); Engine::instance().flush(); ActorPtr player = Engine::instance().getPlayer(); if ( spell ) { TargetSelectorPtr selector( TargetSelector::create( spell->getTargetType() ) ); if ( selector ) { selector->setRange( spell->getRange() ); selector->setRadius( spell->getRadius() ); MapPtr map = Engine::instance().getWorld().getCurrentMap(); Target target = selector->select([&](ActorPtr a){ return map->isInFov(a->getX(), a->getY()); }); if ( player->performAction( new CastAction(spell, target) ) != ActorActionResult::Ok ) { gui::msgBox("Failed to cast spell!", gui::MsgType::Warning); } } ++turns; } return turns; }
int CmdUseSkill::execute() { int turns(0); if ( SkillPtr skill = getSkill() ) { Engine::instance().render(); Engine::instance().flush(); ActorPtr player = Engine::instance().getPlayer(); TargetSelectorPtr selector( TargetSelector::create( skill->getTargetType() ) ); if ( selector ) { selector->setRadius( skill->getRadius() ); MapPtr map = Engine::instance().getWorld().getCurrentMap(); ActorActionPtr action( new UseSkillAction(skill, selector->select([&](ActorPtr a){ return map->isInFov(a->getX(), a->getY()); })) ); if ( player->performAction( action ) != ActorActionResult::Ok ) { gui::msgBox(skill->getName() + " failed!", gui::MsgType::Warning); } ++turns; } } return turns; }