[Client] Add MechanicsHelper methods for easily getting Attacks from Ptr

This commit is contained in:
David Cernat 2017-04-19 10:36:23 +03:00
parent 82e455f736
commit 17c4b6d4de
2 changed files with 26 additions and 2 deletions

View file

@ -13,6 +13,7 @@
#include "Main.hpp" #include "Main.hpp"
#include "LocalPlayer.hpp" #include "LocalPlayer.hpp"
#include "DedicatedPlayer.hpp" #include "DedicatedPlayer.hpp"
#include "CellController.hpp"
using namespace mwmp; using namespace mwmp;
@ -33,13 +34,33 @@ osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f
return (start + osg::componentMultiply(position, (end - start))); return (start + osg::componentMultiply(position, (end - start)));
} }
Attack *MechanicsHelper::getLocalAttack(const MWWorld::Ptr& ptr)
{
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
return &mwmp::Main::get().getLocalPlayer()->attack;
else if (mwmp::Main::get().getCellController()->isLocalActor(ptr))
return &mwmp::Main::get().getCellController()->getLocalActor(ptr)->attack;
return NULL;
}
Attack *MechanicsHelper::getDedicatedAttack(const MWWorld::Ptr& ptr)
{
if (mwmp::PlayerList::isDedicatedPlayer(ptr))
return &mwmp::PlayerList::getPlayer(ptr)->attack;
else if (mwmp::Main::get().getCellController()->isDedicatedActor(ptr))
return &mwmp::Main::get().getCellController()->getDedicatedActor(ptr)->attack;
return NULL;
}
void MechanicsHelper::processAttack(const MWWorld::Ptr& attacker, Attack attack) void MechanicsHelper::processAttack(const MWWorld::Ptr& attacker, Attack attack)
{ {
if (attack.pressed == 0) if (attack.pressed == false)
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", attack.success ? "true" : "false"); LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", attack.success ? "true" : "false");
if (attack.success == 1) if (attack.success == true)
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", attack.damage); LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", attack.damage);
} }

View file

@ -16,6 +16,9 @@ namespace mwmp
osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent); osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent);
Attack *getLocalAttack(const MWWorld::Ptr& ptr);
Attack *getDedicatedAttack(const MWWorld::Ptr& ptr);
void processAttack(const MWWorld::Ptr& attacker, Attack attack); void processAttack(const MWWorld::Ptr& attacker, Attack attack);
}; };
} }