1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 13:20:35 +00:00

Slightly reduce code duplication

This commit is contained in:
capostrophic 2020-01-09 13:55:14 +03:00
parent af2ea477d5
commit 1251b32f0f
3 changed files with 16 additions and 9 deletions

View File

@ -1111,10 +1111,7 @@ namespace MWScript
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
{ {
MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spellId);
store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, ptr)));
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
return; return;
} }
@ -1122,7 +1119,6 @@ namespace MWScript
{ {
MWMechanics::AiCast castPackage(targetId, spellId, true); MWMechanics::AiCast castPackage(targetId, spellId, true);
ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr); ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr);
return; return;
} }
@ -1158,10 +1154,7 @@ namespace MWScript
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
{ {
MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spellId);
store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, ptr)));
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
return; return;
} }

View File

@ -11,6 +11,7 @@
#include <components/esm/loadbsgn.hpp> #include <components/esm/loadbsgn.hpp>
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
@ -19,6 +20,7 @@
#include "../mwmechanics/movement.hpp" #include "../mwmechanics/movement.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include "class.hpp" #include "class.hpp"
#include "ptr.hpp" #include "ptr.hpp"
@ -492,4 +494,14 @@ namespace MWWorld
{ {
mPreviousItems.erase(boundItemId); mPreviousItems.erase(boundItemId);
} }
void Player::setSelectedSpell(const std::string& spellId)
{
Ptr player = getPlayer();
InventoryStore& store = player.getClass().getInventoryStore(player);
store.setSelectedEnchantItem(store.end());
int castChance = int(MWMechanics::getSpellSuccessChance(spellId, player));
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, castChance);
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
}
} }

View File

@ -135,6 +135,8 @@ namespace MWWorld
void setPreviousItem(const std::string& boundItemId, const std::string& previousItemId); void setPreviousItem(const std::string& boundItemId, const std::string& previousItemId);
std::string getPreviousItem(const std::string& boundItemId); std::string getPreviousItem(const std::string& boundItemId);
void erasePreviousItem(const std::string& boundItemId); void erasePreviousItem(const std::string& boundItemId);
void setSelectedSpell(const std::string& spellId);
}; };
} }
#endif #endif