[Client] Convert MechanicsHelper to namespace

0.6.1
Koncord 8 years ago
parent 7d3e08f031
commit 6222c20e82

@ -301,12 +301,12 @@ namespace MWClass
If the attacker is a LocalPlayer or LocalActor, get their Attack and
assign data for its target
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(ptr);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(ptr);
if (localAttack)
{
localAttack->success = true;
mwmp::Main::get().getMechanicsHelper()->assignAttackTarget(localAttack, victim);
MechanicsHelper::assignAttackTarget(localAttack, victim);
}
/*
End of tes3mp addition
@ -485,7 +485,7 @@ namespace MWClass
If the attacker is a DedicatedPlayer or DedicatedActor with a successful knockdown, apply the knockdown;
otherwise, use default probability roll
*/
mwmp::Attack *dedicatedAttack = mwmp::Main::get().getMechanicsHelper()->getDedicatedAttack(attacker);
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(attacker);
if (dedicatedAttack && dedicatedAttack->knockdown)
stats.setKnockedDown(true);
@ -527,7 +527,7 @@ namespace MWClass
If the attacker was the LocalPlayer or LocalActor, record their target and send a packet with it
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(attacker);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(attacker);
if (localAttack)
{
@ -535,7 +535,7 @@ namespace MWClass
localAttack->damage = damage;
localAttack->knockdown = getCreatureStats(ptr).getKnockedDown();
mwmp::Main::get().getMechanicsHelper()->assignAttackTarget(localAttack, ptr);
MechanicsHelper::assignAttackTarget(localAttack, ptr);
localAttack->shouldSend = true;
}

@ -628,12 +628,12 @@ namespace MWClass
If the attacker is a LocalPlayer or LocalActor, get their Attack and
assign data for its target
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(ptr);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(ptr);
if (localAttack)
{
localAttack->success = true;
mwmp::Main::get().getMechanicsHelper()->assignAttackTarget(localAttack, victim);
MechanicsHelper::assignAttackTarget(localAttack, victim);
}
/*
End of tes3mp addition
@ -823,7 +823,7 @@ namespace MWClass
If the attacker is a DedicatedPlayer or DedicatedActor with a successful knockdown, apply the knockdown;
otherwise, use default probability roll
*/
mwmp::Attack *dedicatedAttack = mwmp::Main::get().getMechanicsHelper()->getDedicatedAttack(attacker);
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(attacker);
if (dedicatedAttack && dedicatedAttack->knockdown)
stats.setKnockedDown(true);
@ -940,7 +940,7 @@ namespace MWClass
If the victim was the LocalPlayer, check whether packets should be sent about
their new dynamic stats and position
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(attacker);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(attacker);
if (localAttack)
{
@ -948,7 +948,7 @@ namespace MWClass
localAttack->damage = damage;
localAttack->knockdown = getCreatureStats(ptr).getKnockedDown();
mwmp::Main::get().getMechanicsHelper()->assignAttackTarget(localAttack, ptr);
MechanicsHelper::assignAttackTarget(localAttack, ptr);
localAttack->shouldSend = true;
}

@ -1163,11 +1163,11 @@ namespace MWMechanics
if (dstate == DrawState_Weapon)
{
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(iter->first);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(iter->first);
if (localAttack->pressed != state)
{
mwmp::Main::get().getMechanicsHelper()->resetAttack(localAttack);
MechanicsHelper::resetAttack(localAttack);
localAttack->type = mwmp::Attack::MELEE;
localAttack->pressed = state;
localAttack->shouldSend = true;
@ -1183,7 +1183,7 @@ namespace MWMechanics
If this actor is a DedicatedPlayer or DedicatedActor, update their mAttackingOrSpell
*/
mwmp::Attack *dedicatedAttack = mwmp::Main::get().getMechanicsHelper()->getDedicatedAttack(iter->first);
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(iter->first);
if (dedicatedAttack)
iter->second->getCharacterController()->setAttackingOrSpell(dedicatedAttack->pressed);

@ -216,11 +216,11 @@ namespace MWMechanics
Record that this actor is updating an attack so that a packet will be sent about it
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(actor);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(actor);
if (localAttack && localAttack->pressed != storage.mAttack)
{
mwmp::Main::get().getMechanicsHelper()->resetAttack(localAttack);
MechanicsHelper::resetAttack(localAttack);
localAttack->type = mwmp::Attack::MELEE;
localAttack->pressed = storage.mAttack;
localAttack->shouldSend = true;
@ -288,11 +288,11 @@ namespace MWMechanics
Record that this actor is stopping an attack so that a packet will be sent about it
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(actor);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(actor);
if (localAttack && localAttack->pressed != false)
{
mwmp::Main::get().getMechanicsHelper()->resetAttack(localAttack);
MechanicsHelper::resetAttack(localAttack);
localAttack->type = mwmp::Attack::MELEE;
localAttack->pressed = false;
localAttack->shouldSend = true;
@ -641,11 +641,11 @@ namespace MWMechanics
Record that this actor is starting an attack so that a packet will be sent about it
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(actor);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(actor);
if (localAttack && localAttack->pressed != true)
{
mwmp::Main::get().getMechanicsHelper()->resetAttack(localAttack);
MechanicsHelper::resetAttack(localAttack);
localAttack->type = mwmp::Attack::MELEE;
localAttack->pressed = true;
localAttack->shouldSend = true;

@ -1276,11 +1276,11 @@ bool CharacterController::updateWeaponState()
If this mPtr belongs to a LocalPlayer or LocalActor, get their Attack and prepare
it for sending
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(mPtr);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(mPtr);
if (localAttack)
{
mwmp::Main::get().getMechanicsHelper()->resetAttack(localAttack);
MechanicsHelper::resetAttack(localAttack);
localAttack->type = mwmp::Attack::MAGIC;
localAttack->pressed = true;
localAttack->shouldSend = true;

@ -133,14 +133,14 @@ namespace MWMechanics
Only calculate block chance for LocalPlayers and LocalActors; otherwise,
get the block state from the relevant DedicatedPlayer or DedicatedActor
*/
mwmp::Attack *localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(attacker);
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(attacker);
if (localAttack)
{
localAttack->block = false;
}
mwmp::Attack *dedicatedAttack = mwmp::Main::get().getMechanicsHelper()->getDedicatedAttack(blocker);
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(blocker);
if ((dedicatedAttack && dedicatedAttack->block == true) ||
Misc::Rng::roll0to99() < x)

@ -874,12 +874,12 @@ namespace MWMechanics
can be accounted for like it is in OpenMW's corresponding code
*/
mwmp::Attack *localAttack = NULL;
mwmp::Attack *dedicatedAttack = mwmp::Main::get().getMechanicsHelper()->getDedicatedAttack(mCaster);
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(mCaster);
if (dedicatedAttack)
dedicatedAttack->pressed = false;
else
localAttack = mwmp::Main::get().getMechanicsHelper()->getLocalAttack(mCaster);
localAttack = MechanicsHelper::getLocalAttack(mCaster);
// Check success
if ((localAttack && localAttack->success == false) ||

@ -287,7 +287,7 @@ void Cell::readAttack(ActorList& actorList)
actor->setAnimFlags();
}
mwmp::Main::get().getMechanicsHelper()->processAttack(actor->attack, actor->getPtr());
MechanicsHelper::processAttack(actor->attack, actor->getPtr());
}
}
}

@ -81,7 +81,7 @@ void DedicatedActor::move(float dt)
if (shouldInterpolate && !hasChangedCell)
{
static const int timeMultiplier = 15;
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
osg::Vec3f lerp = MechanicsHelper::getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
refPos.pos[0] = lerp.x();
refPos.pos[1] = lerp.y();
refPos.pos[2] = lerp.z();

@ -106,7 +106,7 @@ void DedicatedPlayer::move(float dt)
if (shouldInterpolate)
{
static const int timeMultiplier = 15;
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
osg::Vec3f lerp = MechanicsHelper::getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
refPos.pos[0] = lerp.x();
refPos.pos[1] = lerp.y();
refPos.pos[2] = lerp.z();

@ -238,7 +238,7 @@ void LocalActor::updateAttack()
{
MWMechanics::CreatureStats &attackerStats = ptr.getClass().getCreatureStats(ptr);
attack.spellId = attackerStats.getSpells().getSelectedSpell();
attack.success = mwmp::Main::get().getMechanicsHelper()->getSpellSuccess(attack.spellId, ptr);
attack.success = MechanicsHelper::getSpellSuccess(attack.spellId, ptr);
}
mwmp::Main::get().getNetworking()->getActorList()->addAttackActor(*this);

@ -533,7 +533,7 @@ void LocalPlayer::updateAttack()
if (attack.type == Attack::MAGIC)
{
attack.spellId = MWBase::Environment::get().getWindowManager()->getSelectedSpell();
attack.success = mwmp::Main::get().getMechanicsHelper()->getSpellSuccess(attack.spellId, getPlayerPtr());
attack.success = MechanicsHelper::getSpellSuccess(attack.spellId, getPlayerPtr());
}
getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->setPlayer(this);

@ -90,7 +90,6 @@ Main::Main()
mLocalPlayer = new LocalPlayer();
mGUIController = new GUIController();
mCellController = new CellController();
mMechanicsHelper = new MechanicsHelper();
//mLocalPlayer->CharGen(0, 4);
server = "mp.tes3mp.com";
@ -104,7 +103,6 @@ Main::~Main()
delete mLocalPlayer;
delete mCellController;
delete mGUIController;
delete mMechanicsHelper;
PlayerList::cleanUp();
}
@ -264,11 +262,6 @@ CellController *Main::getCellController() const
return mCellController;
}
MechanicsHelper *Main::getMechanicsHelper() const
{
return mMechanicsHelper;
}
void Main::pressedKey(int key)
{
if (pMain == nullptr) return;

@ -9,7 +9,6 @@ namespace mwmp
{
class GUIController;
class CellController;
class MechanicsHelper;
class LocalPlayer;
class Networking;
@ -35,7 +34,6 @@ namespace mwmp
LocalPlayer *getLocalPlayer() const;
GUIController *getGUIController() const;
CellController *getCellController() const;
MechanicsHelper *getMechanicsHelper() const;
void updateWorld(float dt) const;
@ -53,7 +51,6 @@ namespace mwmp
GUIController *mGUIController;
CellController *mCellController;
MechanicsHelper *mMechanicsHelper;
std::string server;
unsigned short port;

@ -24,16 +24,6 @@
using namespace mwmp;
mwmp::MechanicsHelper::MechanicsHelper()
{
}
mwmp::MechanicsHelper::~MechanicsHelper()
{
}
osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent)
{
osg::Vec3f position(percent, percent, percent);
@ -50,21 +40,19 @@ void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore)
int spawnCount = 0;
for (typename MWWorld::CellRefList<ESM::CreatureLevList>::List::iterator listIter(creatureLevList->mList.begin());
listIter != creatureLevList->mList.end(); ++listIter)
for(auto &lref : creatureLevList->mList)
{
MWWorld::Ptr ptr(&*listIter, cellStore);
MWWorld::Ptr ptr(&lref, cellStore);
MWWorld::LiveCellRef<ESM::CreatureLevList> *ref = ptr.get<ESM::CreatureLevList>();
std::string id = MWMechanics::getLevelledItem(ref->mBase, true);
std::string id = MWMechanics::getLevelledItem(ptr.get<ESM::CreatureLevList>()->mBase, true);
if (!id.empty())
{
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
MWWorld::ManualRef manualRef(store, id);
manualRef.getPtr().getCellRef().setPosition(ptr.getCellRef().getPosition());
MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(manualRef.getPtr(), ptr.getCell(), ptr.getCellRef().getPosition());
MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(manualRef.getPtr(), ptr.getCell(),
ptr.getCellRef().getPosition());
worldEvent->addObjectSpawn(placed);
MWBase::Environment::get().getWorld()->deleteObject(placed);
@ -147,16 +135,14 @@ bool MechanicsHelper::getSpellSuccess(std::string spellId, const MWWorld::Ptr& c
void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker)
{
if (attack.pressed == false)
if (!attack.pressed)
{
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Processing attack from %s",
attacker.getCellRef().getRefId().c_str());
LOG_APPEND(Log::LOG_VERBOSE, "- success: %s", attack.success ? "true" : "false");
if (attack.success == true)
{
if (attack.success)
LOG_APPEND(Log::LOG_VERBOSE, "- damage: %f", attack.damage);
}
}
MWMechanics::CreatureStats &attackerStats = attacker.getClass().getCreatureStats(attacker);
@ -167,24 +153,17 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker)
if (attack.target.refId.empty())
{
if (attack.target.guid == mwmp::Main::get().getLocalPlayer()->guid)
{
victim = MWBase::Environment::get().getWorld()->getPlayerPtr();
}
else if (PlayerList::getPlayer(attack.target.guid) != NULL)
{
victim = PlayerList::getPlayer(attack.target.guid)->getPtr();
}
}
else
{
if (mwmp::Main::get().getCellController()->isLocalActor(attack.target.refNumIndex, attack.target.mpNum))
{
victim = mwmp::Main::get().getCellController()->getLocalActor(attack.target.refNumIndex, attack.target.mpNum)->getPtr();
}
else if (mwmp::Main::get().getCellController()->isDedicatedActor(attack.target.refNumIndex, attack.target.mpNum))
{
victim = mwmp::Main::get().getCellController()->getDedicatedActor(attack.target.refNumIndex, attack.target.mpNum)->getPtr();
}
auto controller = mwmp::Main::get().getCellController();
if (controller->isLocalActor(attack.target.refNumIndex, attack.target.mpNum))
victim = controller->getLocalActor(attack.target.refNumIndex, attack.target.mpNum)->getPtr();
else if (controller->isDedicatedActor(attack.target.refNumIndex, attack.target.mpNum))
victim = controller->getDedicatedActor(attack.target.refNumIndex, attack.target.mpNum)->getPtr();
}
// Get the weapon used (if hand-to-hand, weapon = inv.end())

@ -5,31 +5,25 @@
#include <osg/Vec3f>
namespace mwmp
{
class MechanicsHelper
{
public:
MechanicsHelper();
~MechanicsHelper();
osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent);
namespace MechanicsHelper
{
osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent);
void spawnLeveledCreatures(MWWorld::CellStore* cellStore);
void spawnLeveledCreatures(MWWorld::CellStore* cellStore);
Attack *getLocalAttack(const MWWorld::Ptr& ptr);
Attack *getDedicatedAttack(const MWWorld::Ptr& ptr);
mwmp::Attack *getLocalAttack(const MWWorld::Ptr& ptr);
mwmp::Attack *getDedicatedAttack(const MWWorld::Ptr& ptr);
MWWorld::Ptr getPlayerPtr(const Target& target);
MWWorld::Ptr getPlayerPtr(const mwmp::Target& target);
void assignAttackTarget(Attack* attack, const MWWorld::Ptr& target);
void resetAttack(Attack* attack);
void assignAttackTarget(mwmp::Attack* attack, const MWWorld::Ptr& target);
void resetAttack(mwmp::Attack* attack);
bool getSpellSuccess(std::string spellId, const MWWorld::Ptr& caster);
bool getSpellSuccess(std::string spellId, const MWWorld::Ptr& caster);
void processAttack(Attack attack, const MWWorld::Ptr& attacker);
};
void processAttack(mwmp::Attack attack, const MWWorld::Ptr& attacker);
}
#endif //OPENMW_MECHANICSHELPER_HPP

@ -205,7 +205,7 @@ void WorldEvent::spawnObjects(MWWorld::CellStore* cellStore)
MWWorld::Ptr masterPtr;
if (worldObject.master.refId.empty())
masterPtr = mwmp::Main::get().getMechanicsHelper()->getPlayerPtr(worldObject.master);
masterPtr = MechanicsHelper::getPlayerPtr(worldObject.master);
else
masterPtr = cellStore->searchExact(worldObject.master.refNumIndex, worldObject.master.mpNum);

@ -28,7 +28,7 @@ namespace mwmp
// If we've received a request for information, comply with it
if (actorList.action == mwmp::BaseActorList::REQUEST)
{
mwmp::Main::get().getMechanicsHelper()->spawnLeveledCreatures(ptrCellStore);
MechanicsHelper::spawnLeveledCreatures(ptrCellStore);
actorList.sendActorsInCell(ptrCellStore);
}
}

@ -28,7 +28,7 @@ namespace mwmp
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
if (player != 0)
Main::get().getMechanicsHelper()->processAttack(player->attack, static_cast<DedicatedPlayer*>(player)->getPtr());
MechanicsHelper::processAttack(player->attack, static_cast<DedicatedPlayer*>(player)->getPtr());
}
};
}

Loading…
Cancel
Save