[General] Add and use Target struct in mwmp::Attack

0.6.1
David Cernat 8 years ago
parent 9882ceedf3
commit a650683bae

@ -26,7 +26,7 @@ namespace mwmp
if (!player.creatureStats.mDead) if (!player.creatureStats.mDead)
{ {
Player *target = Players::getPlayer(player.attack.targetGuid); Player *target = Players::getPlayer(player.attack.target.guid);
if (target == nullptr) if (target == nullptr)
target = &player; target = &player;
@ -46,7 +46,7 @@ namespace mwmp
//packet.Send(player, true); //packet.Send(player, true);
player.sendToLoaded(&packet); player.sendToLoaded(&packet);
playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(player.attack.targetGuid); playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(player.attack.target.guid);
} }
} }
}; };

@ -629,7 +629,7 @@ namespace MWClass
mwmp::Main::get().getLocalPlayer()->attack.success = true; mwmp::Main::get().getLocalPlayer()->attack.success = true;
mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::getPlayer(victim); mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::getPlayer(victim);
if (dedicatedPlayer != nullptr) if (dedicatedPlayer != nullptr)
mwmp::Main::get().getLocalPlayer()->attack.targetGuid = dedicatedPlayer->guid; mwmp::Main::get().getLocalPlayer()->attack.target.guid = dedicatedPlayer->guid;
} }
/* /*
End of tes3mp addition End of tes3mp addition
@ -930,7 +930,7 @@ namespace MWClass
{ {
mwmp::Attack *attack = &mwmp::Main::get().getLocalPlayer()->attack; mwmp::Attack *attack = &mwmp::Main::get().getLocalPlayer()->attack;
attack->damage = damage; attack->damage = damage;
attack->targetGuid = victimPlayer->guid; attack->target.guid = victimPlayer->guid;
attack->knockdown = getCreatureStats(ptr).getKnockedDown(); attack->knockdown = getCreatureStats(ptr).getKnockedDown();
mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types
} }

@ -1195,7 +1195,7 @@ void LocalPlayer::prepareAttack(Attack::TYPE type, bool state)
attack.type = type; attack.type = type;
attack.knockdown = false; attack.knockdown = false;
attack.block = false; attack.block = false;
attack.targetGuid = RakNet::RakNetGUID(); attack.target.guid = RakNet::RakNetGUID();
getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->Send();

@ -48,10 +48,10 @@ void MechanicsHelper::processAttack(const MWWorld::Ptr& attacker, Attack attack)
MWWorld::Ptr victim; MWWorld::Ptr victim;
if (attack.targetGuid == mwmp::Main::get().getLocalPlayer()->guid) if (attack.target.guid == mwmp::Main::get().getLocalPlayer()->guid)
victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); victim = MWBase::Environment::get().getWorld()->getPlayerPtr();
else if (Players::getPlayer(attack.targetGuid) != 0) else if (Players::getPlayer(attack.target.guid) != 0)
victim = Players::getPlayer(attack.targetGuid)->getPtr(); victim = Players::getPlayer(attack.target.guid)->getPtr();
// Get the weapon used (if hand-to-hand, weapon = inv.end()) // Get the weapon used (if hand-to-hand, weapon = inv.end())
if (attackerStats.getDrawState() == MWMechanics::DrawState_Weapon) if (attackerStats.getDrawState() == MWMechanics::DrawState_Weapon)

@ -5,10 +5,20 @@
namespace mwmp namespace mwmp
{ {
struct Target
{
std::string refId;
int refNumIndex;
int mpNum;
RakNet::RakNetGUID guid;
};
class Attack class Attack
{ {
public: public:
RakNet::RakNetGUID targetGuid;
Target target;
char type; // 0 - melee, 1 - magic, 2 - throwable char type; // 0 - melee, 1 - magic, 2 - throwable
enum TYPE enum TYPE

@ -16,7 +16,7 @@ void PacketPlayerAttack::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->attack.targetGuid, send); RW(player->attack.target.guid, send);
RW(player->attack.spellId, send); RW(player->attack.spellId, send);
RW(player->attack.type, send); RW(player->attack.type, send);

Loading…
Cancel
Save