private Thing internalGetThing(NetworkMessage incMsg, NetworkMessage outMsg) { //get thing type ushort thingId = incMsg.GetUInt16(); outMsg.AddUInt16(thingId); if (thingId == 0x0061 || thingId == 0x0062) { //creatures Creature creature = null; if (thingId == 0x0062) { //creature is known uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); creature = Creatures.GetInstance().GetCreature(creatureID); } else if (thingId == 0x0061) { //creature is not known //perhaps we have to remove a known creature uint removeID = incMsg.GetUInt32(); outMsg.AddUInt32(removeID); Creatures.GetInstance().RemoveCreature(removeID); //add a new creature uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); creature = Creatures.GetInstance().AddCreature(creatureID); if (creature == null) return null; creature.SetName(incMsg.GetString()); outMsg.AddString(creature.GetName()); } if (creature == null) return null; //read creature properties creature.SetHealth(incMsg.GetByte()); outMsg.AddByte(creature.GetHealth()); if (creature.GetHealth() > 100) return null; byte direction = incMsg.GetByte(); outMsg.AddByte(direction); if (direction > 3) return null; creature.SetTurnDirection((Direction)direction); creature.SetOutfit(incMsg.GetOutfit()); outMsg.AddOutfit(creature.GetOutfit()); //check if we can read 6 bytes if (!incMsg.CanRead(6)) return null; creature.SetLightLevel(incMsg.GetByte()); outMsg.AddByte(creature.GetLightLevel()); creature.SetLightColor(incMsg.GetByte()); outMsg.AddByte(creature.GetLightColor()); creature.SetSpeed(incMsg.GetUInt16()); outMsg.AddUInt16(creature.GetSpeed()); creature.SetSkull(incMsg.GetByte()); outMsg.AddByte(creature.GetSkull()); creature.SetShield(incMsg.GetByte()); outMsg.AddByte(creature.GetShield()); if (thingId == 0x0061) { // emblem is sent only in packet type 0x61 creature.SetEmblem(incMsg.GetByte()); outMsg.AddByte(creature.GetEmblem()); } byte impassable = incMsg.GetByte(); creature.SetImpassable(impassable == 0x01); outMsg.AddByte(impassable); return creature; } else if (thingId == 0x0063) { //creature turn uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); Creature creature = Creatures.GetInstance().GetCreature(creatureID); if (creature == null) return null; //check if we can read 1 byte byte direction = incMsg.GetByte(); outMsg.AddByte(direction); if (direction > 3) return null; creature.SetTurnDirection((Direction)direction); return creature; } else { //item return internalGetItem(incMsg, outMsg, thingId); } }
private Item internalGetItem(NetworkMessage incMsg, NetworkMessage outMsg, uint itemId) { if (itemId == 0xFFFFFFFF) { if (incMsg.CanRead(2)) { itemId = incMsg.GetUInt16(); outMsg.AddUInt16((ushort)itemId); } else return null; } TibiaEzBot.Core.Entities.ObjectType it = Objects.GetInstance().GetItemType((ushort)itemId); if (it == null) return null; byte count = 0; if (it.IsStackable || it.IsSplash || it.IsFluidContainer || it.IsRune) { count = incMsg.GetByte(); outMsg.AddByte(count); } return new Item((ushort)itemId, count, it); }