private void ParseCreateOnMap(Internal.CommunicationStream message) { var absolutePosition = message.ReadPosition(); if (!WorldMapStorage.IsVisible(absolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseCreateOnMap: Co-ordinate " + absolutePosition + " is out of range."); } var mapPosition = WorldMapStorage.ToMap(absolutePosition); int stackPos = 255; if (OpenTibiaUnity.GameManager.ClientVersion >= 841) { stackPos = message.ReadUnsignedByte(); } int typeOrId = message.ReadUnsignedShort(); Appearances.ObjectInstance @object; if (typeOrId == Appearances.AppearanceInstance.Creature || typeOrId == Appearances.AppearanceInstance.OutdatedCreature || typeOrId == Appearances.AppearanceInstance.UnknownCreature) { var creature = ProtocolGameExtentions.ReadCreatureInstance(message, typeOrId, absolutePosition); if (creature.Id == Player.Id) { Player.StopAutowalk(true); } @object = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id); } else { @object = ProtocolGameExtentions.ReadObjectInstance(message, typeOrId); } if (stackPos == 255) { WorldMapStorage.PutObject(mapPosition, @object); } else { if (stackPos > Constants.MapSizeW) { throw new System.Exception("ProtocolGame.ParseCreateOnMap: Invalid stack position (" + stackPos + ")."); } WorldMapStorage.InsertObject(mapPosition, stackPos, @object); } if (absolutePosition.z == MiniMapStorage.PositionZ) { WorldMapStorage.UpdateMiniMap(mapPosition); uint color = WorldMapStorage.GetMiniMapColour(mapPosition); int cost = WorldMapStorage.GetMiniMapCost(mapPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } WorldMapStorage.CacheRefresh = true; }
private void ParseChangeOnMap(Internal.CommunicationStream message) { int x = message.ReadUnsignedShort(); Appearances.ObjectInstance objectInstance; Creatures.Creature creature = null; UnityEngine.Vector3Int absolutePosition; UnityEngine.Vector3Int mapPosition; if (x != 65535) { absolutePosition = message.ReadPosition(x); if (!WorldMapStorage.IsVisible(absolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Co-ordinate " + absolutePosition + " is out of range."); } mapPosition = WorldMapStorage.ToMap(absolutePosition); int stackPos = message.ReadUnsignedByte(); if (!(objectInstance = WorldMapStorage.GetObject(mapPosition, stackPos))) { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Object not found."); } if (objectInstance.IsCreature && !(creature = CreatureStorage.GetCreature(objectInstance.Data))) { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature not found: " + objectInstance.Data); } if (!!creature) { CreatureStorage.MarkOpponentVisible(creature, false); } int typeOrId = message.ReadUnsignedShort(); if (typeOrId == Appearances.AppearanceInstance.UnknownCreature || typeOrId == Appearances.AppearanceInstance.OutdatedCreature || typeOrId == Appearances.AppearanceInstance.Creature) { creature = ProtocolGameExtentions.ReadCreatureInstance(message, typeOrId, absolutePosition); objectInstance = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id); } else { objectInstance = ProtocolGameExtentions.ReadObjectInstance(message, typeOrId); } WorldMapStorage.ChangeObject(mapPosition, stackPos, objectInstance); } else { uint creatureId = message.ReadUnsignedInt(); if (!(creature = CreatureStorage.GetCreature(creatureId))) { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature " + creatureId + " not found"); } absolutePosition = creature.Position; if (!WorldMapStorage.IsVisible(absolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Co-ordinate " + absolutePosition + " is out of range."); } mapPosition = WorldMapStorage.ToMap(absolutePosition); CreatureStorage.MarkOpponentVisible(creature, false); int otherType = message.ReadUnsignedShort(); if (otherType == Appearances.AppearanceInstance.Creature || otherType == Appearances.AppearanceInstance.OutdatedCreature || otherType == Appearances.AppearanceInstance.UnknownCreature) { creature = ProtocolGameExtentions.ReadCreatureInstance(message, otherType); } else { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Received object of type " + otherType + " when a creature was expected."); } } if (absolutePosition.z == MiniMapStorage.PositionZ) { WorldMapStorage.UpdateMiniMap(mapPosition); uint color = WorldMapStorage.GetMiniMapColour(mapPosition); int cost = WorldMapStorage.GetMiniMapCost(mapPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } WorldMapStorage.CacheRefresh = true; }