Skip to content

Commit

Permalink
Make Player->Cast select the spell instead (bug #5056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Capostrophic committed Jun 8, 2019
1 parent ef2a716 commit 295ee11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
Bug #5038: Enchanting success chance calculations are blatantly wrong
Bug #5047: # in cell names sets color
Bug #5050: Invalid spell effects are not handled gracefully
Bug #5056: Calling Cast function on player doesn't equip the spell but casts it
Feature #1774: Handle AvoidNode
Feature #2229: Improve pathfinding AI
Feature #3025: Analogue gamepad movement controls
Expand Down
18 changes: 13 additions & 5 deletions apps/openmw/mwscript/miscextensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,21 +1096,29 @@ namespace MWScript
std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral (runtime[0].mInteger));
runtime.pop();

const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (spellId);
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId);
if (!spell)
{
runtime.getContext().report("spellcasting failed: can not find spell \""+spellId+"\"");
runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\"");
return;
}

if (spell->mData.mType != ESM::Spell::ST_Spell && spell->mData.mType != ESM::Spell::ST_Power)
{
runtime.getContext().report("spellcasting failed: you can cast only spells and powers.");
runtime.getContext().report("spellcasting failed: you can only cast spells and powers.");
return;
}

// Obviously we can not use casting animation for player here
if (ptr.getClass().isActor() && ptr != MWMechanics::getPlayer())
if (ptr == MWMechanics::getPlayer())
{
MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr);
store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, ptr)));
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
return;
}

if (ptr.getClass().isActor())
{
MWMechanics::AiCast castPackage(targetId, spellId, true);
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr);
Expand Down

0 comments on commit 295ee11

Please sign in to comment.