void NPC_Player(NetworkClient &client, net::Packet &packet)
{
while(packet.peekByte() != net::Packet::BREAK)
{
// NPC walks
uint8_t index = packet.getChar();
std::shared_ptr<NPC> npc = client.GetNPCByIndex(index);
/*if(!npc.get())
{
npc.reset(new NPC());
map->AddObject(npc);
}*/
uint8_t x = packet.getChar();
uint8_t y = packet.getChar();
uint8_t direction = packet.getChar();
if((std::abs(client.game.me->x - x)
+ std::abs(client.game.me->y - y)) < 12
&& npc.get())
{
npc->x = x;
npc->y = y;
npc->direction = Direction(direction);
}
else if((std::abs(client.game.me->x - x)
+ std::abs(client.game.me->y - y)) < 12
&& !npc.get())
{
client.RefreshNPC(index);
}
else if((std::abs(client.game.me->x - x)
+ std::abs(client.game.me->y - y)) > 11
&& npc.get())
{
//client.game.map->RemoveObject(npc);
}
}
packet.skip(1); // break
while(packet.peekByte() != net::Packet::BREAK)
{
// NPC attacks
uint8_t index = packet.getChar();
std::shared_ptr<NPC> npc = client.GetNPCByIndex(index);
if(!npc.get()) // this is helpful but shouldn't be here
{
npc.reset(new NPC());
//client.game.map->AddObject(npc);
}
npc->index = index;
packet.getChar(); // ??
npc->direction = Direction(packet.getChar());
uint16_t p_id = packet.getShort();
/*uint32_t damage = */packet.getThree();
packet.getChar(); // NPC hp
if(p_id == client.game.me->id)
{
puts("Danger detected...");
}
}
packet.skip(1); // break
while(packet.peekByte() != net::Packet::BREAK)
{
// npc talk
/*uint8_t index = */packet.getChar();
uint8_t textLen = packet.getChar();
std::string text = packet.getFixedString(textLen);
}
packet.skip(1); // break
if(packet.readPos() < packet.length())
{
client.game.me->hp = packet.getShort();
client.game.me->tp = packet.getShort();
}
}