[General] Simplify ActorPackets

pull/249/merge
Koncord 8 years ago
parent fd8e833d6a
commit 2ed1bfe427

@ -26,9 +26,49 @@ void ActorPacket::setActorList(BaseActorList *actorList)
} }
void ActorPacket::Packet(RakNet::BitStream *bs, bool send) void ActorPacket::Packet(RakNet::BitStream *bs, bool send)
{
if(!PacketHeader(bs, send))
return;
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
actor = actorList->baseActors[i];
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
Actor(actor, send);
if (!send)
actorList->baseActors.push_back(actor);
}
}
bool ActorPacket::PacketHeader(RakNet::BitStream *bs, bool send)
{ {
BasePacket::Packet(bs, send); BasePacket::Packet(bs, send);
RW(actorList->cell.mData, send, 1); RW(actorList->cell.mData, send, 1);
RW(actorList->cell.mName, send, 1); RW(actorList->cell.mName, send, 1);
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
actorList->isValid = false;
return actorList->isValid;
}
void ActorPacket::Actor(BaseActor &actor, bool send)
{
} }

@ -20,9 +20,11 @@ namespace mwmp
~ActorPacket(); ~ActorPacket();
void setActorList(BaseActorList *actorList); void setActorList(BaseActorList *actorList);
virtual void Packet(RakNet::BitStream *bs, bool send);
virtual void Packet(RakNet::BitStream *bs, bool send);
protected: protected:
bool PacketHeader(RakNet::BitStream *bs, bool send);
virtual void Actor(BaseActor &actor, bool send);
BaseActorList *actorList; BaseActorList *actorList;
static const int maxActors = 3000; static const int maxActors = 3000;
}; };

@ -9,40 +9,7 @@ PacketActorAI::PacketActorAI(RakNet::RakPeerInterface *peer) : ActorPacket(peer)
packetID = ID_ACTOR_AI; packetID = ID_ACTOR_AI;
} }
void PacketActorAI::Packet(RakNet::BitStream *bs, bool send) void PacketActorAI::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); // Placeholder to be filled in later
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
// Placeholder to be filled in later
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorAI(RakNet::RakPeerInterface *peer); PacketActorAI(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,42 +9,9 @@ PacketActorAnimFlags::PacketActorAnimFlags(RakNet::RakPeerInterface *peer) : Act
packetID = ID_ACTOR_ANIM_FLAGS; packetID = ID_ACTOR_ANIM_FLAGS;
} }
void PacketActorAnimFlags::Packet(RakNet::BitStream *bs, bool send) void PacketActorAnimFlags::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); RW(actor.movementFlags, send);
RW(actor.drawState, send);
if (send) RW(actor.isFlying, send);
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.movementFlags, send);
RW(actor.drawState, send);
RW(actor.isFlying, send);
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorAnimFlags(RakNet::RakPeerInterface *peer); PacketActorAnimFlags(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,43 +9,11 @@ PacketActorAnimPlay::PacketActorAnimPlay(RakNet::RakPeerInterface *peer) : Actor
packetID = ID_ACTOR_ANIM_PLAY; packetID = ID_ACTOR_ANIM_PLAY;
} }
void PacketActorAnimPlay::Packet(RakNet::BitStream *bs, bool send) void PacketActorAnimPlay::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send);
if (send) RW(actor.animation.groupname, send);
actorList->count = (unsigned int)(actorList->baseActors.size()); RW(actor.animation.mode, send);
else RW(actor.animation.count, send);
actorList->baseActors.clear(); RW(actor.animation.persist, send);
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.animation.groupname, send);
RW(actor.animation.mode, send);
RW(actor.animation.count, send);
RW(actor.animation.persist, send);
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorAnimPlay(RakNet::RakPeerInterface *peer); PacketActorAnimPlay(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,51 +9,18 @@ PacketActorAttack::PacketActorAttack(RakNet::RakPeerInterface *peer) : ActorPack
packetID = ID_ACTOR_ATTACK; packetID = ID_ACTOR_ATTACK;
} }
void PacketActorAttack::Packet(RakNet::BitStream *bs, bool send) void PacketActorAttack::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); RW(actor.attack.target.refNumIndex, send);
RW(actor.attack.target.mpNum, send);
if (send) RW(actor.attack.target.guid, send);
actorList->count = (unsigned int)(actorList->baseActors.size());
else RW(actor.attack.spellId, send);
actorList->baseActors.clear(); RW(actor.attack.type, send);
RW(actor.attack.success, send);
RW(actorList->count, send); RW(actor.attack.damage, send);
if (actorList->count > maxActors) RW(actor.attack.pressed, send);
{ RW(actor.attack.knockdown, send);
actorList->isValid = false; RW(actor.attack.block, send);
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.attack.target.refNumIndex, send);
RW(actor.attack.target.mpNum, send);
RW(actor.attack.target.guid, send);
RW(actor.attack.spellId, send);
RW(actor.attack.type, send);
RW(actor.attack.success, send);
RW(actor.attack.damage, send);
RW(actor.attack.pressed, send);
RW(actor.attack.knockdown, send);
RW(actor.attack.block, send);
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorAttack(RakNet::RakPeerInterface *peer); PacketActorAttack(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -10,5 +10,8 @@ PacketActorAuthority::PacketActorAuthority(RakNet::RakPeerInterface *peer) : Act
void PacketActorAuthority::Packet(RakNet::BitStream *bs, bool send) void PacketActorAuthority::Packet(RakNet::BitStream *bs, bool send)
{ {
ActorPacket::Packet(bs, send); BasePacket::Packet(bs, send);
RW(actorList->cell.mData, send, 1);
RW(actorList->cell.mName, send, 1);
} }

@ -9,40 +9,11 @@ PacketActorCellChange::PacketActorCellChange(RakNet::RakPeerInterface *peer) : A
packetID = ID_ACTOR_CELL_CHANGE; packetID = ID_ACTOR_CELL_CHANGE;
} }
void PacketActorCellChange::Packet(RakNet::BitStream *bs, bool send) void PacketActorCellChange::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); RW(actor.cell.mData, send, 1);
RW(actor.cell.mName, send, 1);
if (send) RW(actor.position, send, 1);
actorList->count = (unsigned int)(actorList->baseActors.size()); RW(actor.direction, send, 1);
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
actor = actorList->baseActors.at(i);
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.cell.mData, send, 1);
RW(actor.cell.mName, send, 1);
RW(actor.position, send, 1);
RW(actor.direction, send, 1);
if (!send)
actorList->baseActors.push_back(actor);
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorCellChange(RakNet::RakPeerInterface *peer); PacketActorCellChange(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,40 +9,7 @@ PacketActorDeath::PacketActorDeath(RakNet::RakPeerInterface *peer) : ActorPacket
packetID = ID_ACTOR_DEATH; packetID = ID_ACTOR_DEATH;
} }
void PacketActorDeath::Packet(RakNet::BitStream *bs, bool send) void PacketActorDeath::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send);
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
// Placeholder to be filled in later // Placeholder to be filled in later
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorDeath(RakNet::RakPeerInterface *peer); PacketActorDeath(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,45 +9,12 @@ PacketActorEquipment::PacketActorEquipment(RakNet::RakPeerInterface *peer) : Act
packetID = ID_ACTOR_EQUIPMENT; packetID = ID_ACTOR_EQUIPMENT;
} }
void PacketActorEquipment::Packet(RakNet::BitStream *bs, bool send) void PacketActorEquipment::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); for (int j = 0; j < 19; j++)
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{ {
if (send) RW(actor.equipedItems[j].refId, send);
{ RW(actor.equipedItems[j].count, send);
actor = actorList->baseActors.at(i); RW(actor.equipedItems[j].charge, send);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
for (int j = 0; j < 19; j++)
{
RW(actor.equipedItems[j].refId, send);
RW(actor.equipedItems[j].count, send);
RW(actor.equipedItems[j].charge, send);
}
if (!send)
{
actorList->baseActors.push_back(actor);
}
} }
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorEquipment(RakNet::RakPeerInterface *peer); PacketActorEquipment(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -10,31 +10,17 @@ PacketActorList::PacketActorList(RakNet::RakPeerInterface *peer) : ActorPacket(p
void PacketActorList::Packet(RakNet::BitStream *bs, bool send) void PacketActorList::Packet(RakNet::BitStream *bs, bool send)
{ {
ActorPacket::Packet(bs, send); if(!ActorPacket::PacketHeader(bs, send))
return;
RW(actorList->action, send); RW(actorList->action, send);
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor; BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++) for (unsigned int i = 0; i < actorList->count; i++)
{ {
if (send) if (send)
{
actor = actorList->baseActors.at(i); actor = actorList->baseActors.at(i);
}
RW(actor.refId, send); RW(actor.refId, send);
RW(actor.refNumIndex, send); RW(actor.refNumIndex, send);
@ -47,8 +33,6 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send)
} }
if (!send) if (!send)
{
actorList->baseActors.push_back(actor); actorList->baseActors.push_back(actor);
}
} }
} }

@ -9,39 +9,10 @@ PacketActorPosition::PacketActorPosition(RakNet::RakPeerInterface *peer) : Actor
packetID = ID_ACTOR_POSITION; packetID = ID_ACTOR_POSITION;
} }
void PacketActorPosition::Packet(RakNet::BitStream *bs, bool send) void PacketActorPosition::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); RW(actor.position, send, 1);
RW(actor.direction, send, 1);
if (send) actor.hasPositionData = true;
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
actor = actorList->baseActors.at(i);
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.position, send, 1);
RW(actor.direction, send, 1);
actor.hasPositionData = true;
if (!send)
actorList->baseActors.push_back(actor);
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorPosition(RakNet::RakPeerInterface *peer); PacketActorPosition(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,41 +9,8 @@ PacketActorSpeech::PacketActorSpeech(RakNet::RakPeerInterface *peer) : ActorPack
packetID = ID_ACTOR_SPEECH; packetID = ID_ACTOR_SPEECH;
} }
void PacketActorSpeech::Packet(RakNet::BitStream *bs, bool send) void PacketActorSpeech::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); RW(actor.response, send);
RW(actor.sound, send);
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.response, send);
RW(actor.sound, send);
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorSpeech(RakNet::RakPeerInterface *peer); PacketActorSpeech(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -10,44 +10,9 @@ PacketActorStatsDynamic::PacketActorStatsDynamic(RakNet::RakPeerInterface *peer)
packetID = ID_ACTOR_STATS_DYNAMIC; packetID = ID_ACTOR_STATS_DYNAMIC;
} }
void PacketActorStatsDynamic::Packet(RakNet::BitStream *bs, bool send) void PacketActorStatsDynamic::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send); RW(actor.creatureStats.mDynamic, send);
if (send) actor.hasStatsDynamicData = true;
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
RW(actor.creatureStats.mDynamic[0], send); // health
RW(actor.creatureStats.mDynamic[1], send); // magic
RW(actor.creatureStats.mDynamic[2], send); // fatigue
actor.hasStatsDynamicData = true;
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorStatsDynamic(RakNet::RakPeerInterface *peer); PacketActorStatsDynamic(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

@ -9,38 +9,7 @@ PacketActorTest::PacketActorTest(RakNet::RakPeerInterface *peer) : ActorPacket(p
packetID = ID_ACTOR_TEST; packetID = ID_ACTOR_TEST;
} }
void PacketActorTest::Packet(RakNet::BitStream *bs, bool send) void PacketActorTest::Actor(BaseActor &actor, bool send)
{ {
ActorPacket::Packet(bs, send);
if (send)
actorList->count = (unsigned int)(actorList->baseActors.size());
else
actorList->baseActors.clear();
RW(actorList->count, send);
if (actorList->count > maxActors)
{
actorList->isValid = false;
return;
}
BaseActor actor;
for (unsigned int i = 0; i < actorList->count; i++)
{
if (send)
{
actor = actorList->baseActors.at(i);
}
RW(actor.refNumIndex, send);
RW(actor.mpNum, send);
if (!send)
{
actorList->baseActors.push_back(actor);
}
}
} }

@ -10,7 +10,7 @@ namespace mwmp
public: public:
PacketActorTest(RakNet::RakPeerInterface *peer); PacketActorTest(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send); virtual void Actor(BaseActor &actor, bool send);
}; };
} }

Loading…
Cancel
Save