Added MWMechanics::isPlayerInCombat()

This commit is contained in:
dteviot 2015-09-10 18:48:34 +12:00
parent 84e1801bbc
commit e9c796166a
9 changed files with 27 additions and 11 deletions

View file

@ -3,10 +3,17 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwworld/player.hpp"
namespace MWMechanics namespace MWMechanics
{ {
MWWorld::Ptr getPlayer() MWWorld::Ptr getPlayer()
{ {
return MWBase::Environment::get().getWorld()->getPlayerPtr(); return MWBase::Environment::get().getWorld()->getPlayerPtr();
} }
bool isPlayerInCombat()
{
return MWBase::Environment::get().getWorld()->getPlayer().isInCombat();
}
} }

View file

@ -9,6 +9,7 @@ namespace MWWorld
namespace MWMechanics namespace MWMechanics
{ {
MWWorld::Ptr getPlayer(); MWWorld::Ptr getPlayer();
bool isPlayerInCombat();
} }
#endif #endif

View file

@ -927,7 +927,7 @@ namespace MWMechanics
return true; return true;
} }
if(MWBase::Environment::get().getWorld()->getPlayer().isInCombat()) { if(MWMechanics::isPlayerInCombat()) {
MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage2}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage2}");
return true; return true;
} }

View file

@ -5,15 +5,16 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWWorld namespace MWWorld
{ {
void ActionAlchemy::executeImp (const Ptr& actor) void ActionAlchemy::executeImp (const Ptr& actor)
{ {
if (actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor != MWMechanics::getPlayer())
return; return;
if(MWBase::Environment::get().getWorld()->getPlayer().isInCombat()) { //Ensure we're not in combat if(MWMechanics::isPlayerInCombat()) { //Ensure we're not in combat
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage3}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage3}");
return; return;
} }

View file

@ -7,6 +7,8 @@
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWWorld namespace MWWorld
{ {
ActionApply::ActionApply (const Ptr& object, const std::string& id) ActionApply::ActionApply (const Ptr& object, const std::string& id)
@ -32,7 +34,7 @@ namespace MWWorld
{ {
MWBase::Environment::get().getWorld()->breakInvisibility(actor); MWBase::Environment::get().getWorld()->breakInvisibility(actor);
if (actor.getClass().apply (actor, mId, actor) && mUsageType!=-1 && actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor.getClass().apply (actor, mId, actor) && mUsageType!=-1 && actor == MWMechanics::getPlayer())
actor.getClass().skillUsageSucceeded (actor, mSkillIndex, mUsageType); actor.getClass().skillUsageSucceeded (actor, mSkillIndex, mUsageType);
actor.getClass().getContainerStore(actor).remove(getTarget(), 1, actor); actor.getClass().getContainerStore(actor).remove(getTarget(), 1, actor);

View file

@ -7,6 +7,8 @@
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "class.hpp" #include "class.hpp"
namespace MWWorld namespace MWWorld
@ -19,7 +21,7 @@ namespace MWWorld
// apply to actor // apply to actor
std::string id = getTarget().getClass().getId (getTarget()); std::string id = getTarget().getClass().getId (getTarget());
if (actor.getClass().apply (actor, id, actor) && actor == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor.getClass().apply (actor, id, actor) && actor == MWMechanics::getPlayer())
actor.getClass().skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1); actor.getClass().skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1);
} }

View file

@ -5,6 +5,7 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "player.hpp" #include "player.hpp"
#include "class.hpp" #include "class.hpp"
@ -18,11 +19,11 @@ namespace MWWorld
void ActionRead::executeImp (const MWWorld::Ptr& actor) { void ActionRead::executeImp (const MWWorld::Ptr& actor) {
if (actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor != MWMechanics::getPlayer())
return; return;
//Ensure we're not in combat //Ensure we're not in combat
if(MWBase::Environment::get().getWorld()->getPlayer().isInCombat() if(MWMechanics::isPlayerInCombat()
// Reading in combat is still allowed if the scroll/book is not in the player inventory yet // Reading in combat is still allowed if the scroll/book is not in the player inventory yet
// (since otherwise, there would be no way to pick it up) // (since otherwise, there would be no way to pick it up)
&& getTarget().getContainerStore() == &actor.getClass().getContainerStore(actor) && getTarget().getContainerStore() == &actor.getClass().getContainerStore(actor)

View file

@ -4,6 +4,7 @@
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWWorld namespace MWWorld
{ {
@ -14,10 +15,10 @@ namespace MWWorld
void ActionRepair::executeImp (const Ptr& actor) void ActionRepair::executeImp (const Ptr& actor)
{ {
if (actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor != MWMechanics::getPlayer())
return; return;
if(MWBase::Environment::get().getWorld()->getPlayer().isInCombat()) { if(MWMechanics::isPlayerInCombat()) {
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage2}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage2}");
return; return;
} }

View file

@ -4,6 +4,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace MWWorld namespace MWWorld
{ {
@ -16,10 +17,10 @@ namespace MWWorld
void ActionSoulgem::executeImp(const Ptr &actor) void ActionSoulgem::executeImp(const Ptr &actor)
{ {
if (actor != MWBase::Environment::get().getWorld()->getPlayerPtr()) if (actor != MWMechanics::getPlayer())
return; return;
if(MWBase::Environment::get().getWorld()->getPlayer().isInCombat()) { //Ensure we're not in combat if(MWMechanics::isPlayerInCombat()) { //Ensure we're not in combat
MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage5}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sInventoryMessage5}");
return; return;
} }