private Creatures.Creature ReadCreatureInstance(Internal.ByteArray message, int type = -1, UnityEngine.Vector3Int?absolutePosition = null) { if (type == -1) { type = message.ReadUnsignedShort(); } if (type != AppearanceInstance.Creature && type != AppearanceInstance.OutdatedCreature && type != AppearanceInstance.UnknownCreature) { throw new System.Exception("ProtocolGame.ReadCreatureInstance: Invalid creature type"); } var gameManager = OpenTibiaUnity.GameManager; Creatures.Creature creature; switch (type) { case AppearanceInstance.UnknownCreature: case AppearanceInstance.OutdatedCreature: { if (type == AppearanceInstance.UnknownCreature) { uint removeID = message.ReadUnsignedInt(); uint newID = message.ReadUnsignedInt(); CreatureType creatureType; if (gameManager.ClientVersion >= 910) { creatureType = message.ReadEnum <CreatureType>(); } else { if (newID >= Constants.PlayerStartID && newID < Constants.PlayerEndID) { creatureType = CreatureType.Player; } else if (newID >= Constants.MonsterStartID && newID < Constants.MonsterEndID) { creatureType = CreatureType.Monster; } else { creatureType = CreatureType.NPC; } } if (newID == Player.ID) { creature = Player; } else { creature = new Creatures.Creature(newID); } creature = CreatureStorage.ReplaceCreature(creature, removeID); if (!creature) { throw new System.Exception("ProtocolGame.ReadCreatureInstance: Failed to append creature."); } creature.Type = creatureType; if (gameManager.ClientVersion >= 1120) { creature.SetSummonerID(creature.IsSummon ? message.ReadUnsignedInt() : 0); } creature.Name = message.ReadString(); } else { uint creatureId = message.ReadUnsignedInt(); creature = CreatureStorage.GetCreature(creatureId); if (!creature) { throw new System.Exception("ProtocolGame.ReadCreatureInstance: Outdated creature not found."); } } creature.SetSkill(SkillType.HealthPercent, message.ReadUnsignedByte()); creature.Direction = message.ReadEnum <Direction>(); creature.Outfit = ReadCreatureOutfit(message, creature.Outfit); if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts)) { creature.MountOutfit = ReadMountOutfit(message, creature.MountOutfit); } creature.Brightness = message.ReadUnsignedByte(); creature.LightColor = Colors.ColorFrom8Bit(message.ReadUnsignedByte()); creature.SetSkill(SkillType.Speed, message.ReadUnsignedShort()); creature.SetPKFlag(message.ReadEnum <PKFlag>()); creature.SetPartyFlag(message.ReadEnum <PartyFlag>()); if (gameManager.GetFeature(GameFeature.GameCreatureEmblems) && type == AppearanceInstance.UnknownCreature) { creature.SetGuildFlag(message.ReadEnum <GuildFlag>()); } if (gameManager.GetFeature(GameFeature.GameCreatureMarks)) { creature.Type = message.ReadEnum <CreatureType>(); if (gameManager.ClientVersion >= 1120) { creature.SetSummonerID(creature.IsSummon ? message.ReadUnsignedInt() : 0); } } if (gameManager.GetFeature(GameFeature.GameCreatureIcons)) { creature.SetSpeechCategory(message.ReadEnum <SpeechCategory>()); } if (gameManager.GetFeature(GameFeature.GameCreatureMarks)) { creature.Marks.SetMark(MarkType.Permenant, message.ReadUnsignedByte()); if (gameManager.GetFeature(GameFeature.GameInspectionWindow)) { message.ReadUnsignedByte(); // inspection state } if (gameManager.ClientVersion < 1185) { creature.NumberOfPvPHelpers = message.ReadUnsignedShort(); } } if (gameManager.ClientVersion >= 854) { creature.Unpassable = message.ReadUnsignedByte() != 0; } else { creature.Unpassable = true; } break; } case AppearanceInstance.Creature: { uint creatureId = message.ReadUnsignedInt(); creature = CreatureStorage.GetCreature(creatureId); if (!creature) { throw new System.Exception(string.Format("ProtocolGame.ReadCreatureInstance: Known creature not found ({0}).", creatureId)); } creature.Direction = message.ReadEnum <Direction>(); if (gameManager.ClientVersion >= 953) { creature.Unpassable = message.ReadUnsignedByte() != 0; } break; } default: throw new System.Exception("ProtocolGame.ReadCreatureInstance: unknown creature identity type."); } if (absolutePosition.HasValue) { creature.Position = absolutePosition.Value; } CreatureStorage.MarkOpponentVisible(creature, true); CreatureStorage.InvalidateOpponents(); return(creature); }