private void ParseSetInventory(Internal.CommunicationStream message) { var slot = message.ReadEnum <ClothSlots>(); var @object = ProtocolGameExtentions.ReadObjectInstance(message); OpenTibiaUnity.ContainerStorage.BodyContainerView.SetObject(slot, @object); }
private void ParseDeleteInContainer(Internal.CommunicationStream message) { byte containerId = message.ReadUnsignedByte(); ushort slot; Appearances.ObjectInstance appendObject = null; if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination)) { slot = message.ReadUnsignedShort(); ushort itemId = message.ReadUnsignedShort(); if (itemId != 0) { appendObject = ProtocolGameExtentions.ReadObjectInstance(message, itemId); } } else { slot = message.ReadUnsignedByte(); } var containerView = ContainerStorage.GetContainerView(containerId); if (!!containerView) { containerView.RemoveObject(slot, appendObject); } }
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 ParseOpenContainer(Internal.CommunicationStream message) { byte containerId = message.ReadUnsignedByte(); var objectIcon = ProtocolGameExtentions.ReadObjectInstance(message); string name = message.ReadString(); byte nOfSlotsPerPage = message.ReadUnsignedByte(); // capacity of shown view bool isSubContainer = message.ReadBoolean(); bool canUseDepotSearch = false; bool isDragAndDropEnabled = true; bool isPaginationEnabled = false; int nOfTotalObjects; int indexOfFirstObject = 0; int nOfContentObjects; // objects in the current shown view // if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination)) { if (OpenTibiaUnity.GameManager.ClientVersion >= 1220) { canUseDepotSearch = message.ReadBoolean(); } isDragAndDropEnabled = message.ReadBoolean(); isPaginationEnabled = message.ReadBoolean(); nOfTotalObjects = message.ReadUnsignedShort(); indexOfFirstObject = message.ReadUnsignedShort(); nOfContentObjects = message.ReadUnsignedByte(); if (nOfContentObjects > nOfSlotsPerPage) { throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds number of slots per page " + nOfSlotsPerPage); } if (nOfContentObjects > nOfTotalObjects) { throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds number of total objects " + nOfTotalObjects); } } else { nOfContentObjects = message.ReadUnsignedByte(); nOfTotalObjects = nOfContentObjects; if (nOfContentObjects > nOfSlotsPerPage) { throw new System.Exception("ProtocolGame.ParseOpenContainer: Number of content objects " + nOfContentObjects + " exceeds the capaciy " + nOfSlotsPerPage); } } var containerView = ContainerStorage.CreateContainerView(containerId, objectIcon, name, isSubContainer, isDragAndDropEnabled, isPaginationEnabled, nOfSlotsPerPage, nOfTotalObjects - nOfContentObjects, indexOfFirstObject, nOfContentObjects); for (int i = 0; i < nOfContentObjects; i++) { containerView.AddObject(indexOfFirstObject + i, ProtocolGameExtentions.ReadObjectInstance(message)); } }
private void ParseMapBottomRow(Internal.CommunicationStream message) { UnityEngine.Vector3Int position = WorldMapStorage.Position; position.y++; WorldMapStorage.Position = position; MiniMapStorage.Position = position; WorldMapStorage.ScrollMap(0, -1); WorldMapStorage.InvalidateOnscreenMessages(); ProtocolGameExtentions.ReadArea(message, 0, Constants.MapSizeY - 1, Constants.MapSizeX - 1, Constants.MapSizeY - 1); WorldMapStorage.CacheRefresh = true; }
private void ParseMapTopRow(Internal.CommunicationStream message) { UnityEngine.Vector3Int position = WorldMapStorage.Position; position.y--; //NewGameManager.inst.RenderGroundRow(NewGameManager.rowType.top); WorldMapStorage.Position = position; MiniMapStorage.Position = position; WorldMapStorage.ScrollMap(0, 1); WorldMapStorage.InvalidateOnscreenMessages(); ProtocolGameExtentions.ReadArea(message, 0, 0, Constants.MapSizeX - 1, 0); WorldMapStorage.CacheRefresh = true; }
private void ParseOwnOffer(Internal.CommunicationStream message) { string creatureName = message.ReadString(); var objects = new List <Appearances.ObjectInstance>(); int size = message.ReadUnsignedByte(); for (int i = 0; i < size; i++) { objects.Add(ProtocolGameExtentions.ReadObjectInstance(message)); } OpenTibiaUnity.GameManager.onRequestOwnOffer.Invoke(creatureName, objects); }
private void ParseMapBottomFloor(Internal.CommunicationStream message) { UnityEngine.Vector3Int position = WorldMapStorage.Position; position.x--; position.y--; position.z++; WorldMapStorage.Position = position; MiniMapStorage.Position = position; if (position.z > Constants.GroundLayer + 1) { WorldMapStorage.ScrollMap(0, 0, 1); if (position.z <= Constants.MapMaxZ - Constants.UndergroundLayer) { ProtocolGameExtentions.ReadFloor(message, 2 * Constants.UndergroundLayer, 0); } } else if (position.z == Constants.GroundLayer + 1) { WorldMapStorage.ScrollMap(0, 0, Constants.UndergroundLayer + 1); int skip = 0; for (int zposition = Constants.UndergroundLayer; zposition >= 0; zposition--) { skip = ProtocolGameExtentions.ReadFloor(message, zposition, skip); } } Player.StopAutowalk(true); WorldMapStorage.InvalidateOnscreenMessages(); var mapPosition = WorldMapStorage.ToMap(position); for (int x = 0; x < Constants.MapSizeX; x++) { for (int y = 0; y < Constants.MapSizeY; y++) { mapPosition.x = x; mapPosition.y = y; var absolutePosition = WorldMapStorage.ToAbsolute(mapPosition); WorldMapStorage.UpdateMiniMap(mapPosition); uint color = WorldMapStorage.GetMiniMapColour(mapPosition); int cost = WorldMapStorage.GetMiniMapCost(mapPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } } WorldMapStorage.CacheRefresh = true; }
private void ParseFullMap(Internal.CommunicationStream message) { UnityEngine.Vector3Int position = message.ReadPosition(); Player.StopAutowalk(true); CreatureStorage.MarkAllOpponentsVisible(false); MiniMapStorage.Position = position; WorldMapStorage.ResetMap(); WorldMapStorage.InvalidateOnscreenMessages(); WorldMapStorage.Position = position; ProtocolGameExtentions.ReadArea(message, 0, 0, Constants.MapSizeX - 1, Constants.MapSizeY - 1); WorldMapStorage.Valid = true; WorldMapStorage.CacheRefresh = true; }
private void ParseCreatureOutfit(Internal.CommunicationStream message) { uint creatureId = message.ReadUnsignedInt(); var outfit = ProtocolGameExtentions.ReadCreatureOutfit(message); var creature = CreatureStorage.GetCreature(creatureId); if (!!creature) { creature.Outfit = outfit; if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts)) { creature.MountOutfit = ProtocolGameExtentions.ReadMountOutfit(message, creature.MountOutfit); } }/*else { * throw new System.Exception("ProtocolGame.ParseCreatureOutfit: Unknown creature id: " + creatureId); * }*/ }
private void ParseCreateInContainer(Internal.CommunicationStream message) { byte containerId = message.ReadUnsignedByte(); ushort slot = 0; if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameContainerPagination)) { slot = message.ReadUnsignedShort(); } var @object = ProtocolGameExtentions.ReadObjectInstance(message); var containerView = ContainerStorage.GetContainerView(containerId); if (!!containerView) { containerView.AddObject(slot, @object); } }
private void ParseFieldData(Internal.CommunicationStream message) { UnityEngine.Vector3Int absolutePosition = message.ReadPosition(); if (!WorldMapStorage.IsVisible(absolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseFieldData: Co-ordinate " + absolutePosition + " is out of range."); } var mapPosition = WorldMapStorage.ToMap(absolutePosition); WorldMapStorage.ResetField(mapPosition, true, false); ProtocolGameExtentions.ReadField(message, mapPosition.x, mapPosition.y, mapPosition.z); 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 ParseOutfitDialog(Internal.CommunicationStream message) { var outfit = ProtocolGameExtentions.ReadCreatureOutfit(message); Appearances.AppearanceInstance mountOutfit = null; if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts)) { mountOutfit = ProtocolGameExtentions.ReadMountOutfit(message); } var outfitList = new List <ProtocolOutfit>(); if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameNewOutfitProtocol)) { int count; if (OpenTibiaUnity.GameManager.ClientVersion >= 1185) { count = message.ReadUnsignedShort(); } else { count = message.ReadUnsignedByte(); } for (int i = 0; i < count; i++) { outfitList.Add(ReadNewProtocolOutfit(message)); } } else { ushort outfitStart, outfitEnd; if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameOutfitIdU16)) { outfitStart = message.ReadUnsignedShort(); outfitEnd = message.ReadUnsignedShort(); } else { outfitStart = message.ReadUnsignedByte(); outfitEnd = message.ReadUnsignedByte(); } for (ushort i = outfitStart; i <= outfitEnd; i++) { outfitList.Add(new ProtocolOutfit() { _id = i }); } } List <ProtocolMount> mountList = null; if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GamePlayerMounts)) { mountList = new List <ProtocolMount>(); int count; if (OpenTibiaUnity.GameManager.ClientVersion >= 1185) { count = message.ReadUnsignedShort(); } else { count = message.ReadUnsignedByte(); } for (int i = 0; i < count; i++) { mountList.Add(ReadProtocolMount(message)); } } OutfitDialogType type = 0; if (OpenTibiaUnity.GameManager.ClientVersion >= 1185) { type = message.ReadEnum <OutfitDialogType>(); bool mounted = message.ReadBoolean(); } OpenTibiaUnity.GameManager.onRequestOutfitDialog.Invoke(outfit, mountOutfit, outfitList, mountList); }
public void ParseMapRightRow(Internal.CommunicationStream message) { UnityEngine.Vector3Int position = WorldMapStorage.Position; position.x++; //NewGameManager.inst.RenderGroundRow(NewGameManager.rowType.right); var allFields = WorldMapStorage.GetFields(); /* * int x = allFields[0].ObjectsNetwork[0]._lastPatternX; * int y = allFields[0].ObjectsNetwork[0]._lastPatternY; * int z = allFields[0].ObjectsNetwork[0]._lastPatternZ; */ for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { for (int o = 0; o < 20; o++) { try { WorldMap.Field _field = WorldMapStorage.GetField(new Vector3Int(i, j, o)); int countItem = _field.ObjectsNetwork.Where(c => c != null).Count(); if (countItem > 4) { Debug.Log(WorldMapStorage.Position); Debug.Log(Player.Position); Debug.Log("not null" + i + " " + j + " " + o); } break; } catch (Exception ex) { //Debug.Log("null"); } } } } /////////////// /* * int last_index = 0; * int count = 0; * for(int i=0; i<allFields.Length; i++) * { * for(int j=0; j<allFields[i].ObjectsNetwork.Length; j++) * { * if (allFields[i].ObjectsNetwork[j] != null) * { * last_index = j; * count++; * } * * } * if (count > 2) * { * int posX = allFields[i].ObjectsNetwork[last_index]._lastPatternX; * int posY = allFields[i].ObjectsNetwork[last_index]._lastPatternY; * int posZ = allFields[i].ObjectsNetwork[last_index]._lastPatternZ; * Debug.Log(count +" "+posX+ " "+posY+" "+posZ); * } * // * count = 0; * } * */ //List<ObjItem> RightMapObj = new List<ObjItem>(); /* * for(int i=0; i<5; i++) * { * UnityEngine.Vector3Int pos = new Vector3Int(position.x, position.y, position.z); * WorldMap.Field _field = (WorldMapStorage.GetField(pos)); * _field.ObjectsNetwork[0].las * } */ //////// // var fields = WorldMapStorage.GetFields(); // foreach(var field in fields) // { /// var cos = field.ObjectsNetwork; /// foreach (var tmp1 in cos) // { // if (tmp1 == null) // Debug.Log("null"); /// else // Debug.Log("not null"); //UnityEngine.Vector3 pos = new UnityEngine.Vector3(tmp1._lastPatternX, tmp1._lastPatternY, tmp1._lastPatternZ); //ObjItem item = new ObjItem((int)tmp1.Id, pos); //NewGameManager.AddObjToList(item); // } // } ///// WorldMapStorage.Position = position; MiniMapStorage.Position = position; WorldMapStorage.ScrollMap(-1, 0); WorldMapStorage.InvalidateOnscreenMessages(); ProtocolGameExtentions.ReadArea(message, Constants.MapSizeX - 1, 0, Constants.MapSizeX - 1, Constants.MapSizeY - 1); WorldMapStorage.CacheRefresh = true; }
private void ParseChangeOnMap(Internal.CommunicationStream message) { int x = message.ReadUnsignedShort(); Appearances.ObjectInstance objectInstance; Creatures.Creature creature = null; Creatures.Creature other = 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.GetCreatureById(objectInstance.Data))) { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Creature not found: " + objectInstance.Data); } int typeOrId = message.ReadUnsignedShort(); if (typeOrId == Appearances.AppearanceInstance.UnknownCreature || typeOrId == Appearances.AppearanceInstance.OutdatedCreature || typeOrId == Appearances.AppearanceInstance.Creature) { other = ProtocolGameExtentions.ReadCreatureInstance(message, typeOrId, absolutePosition); objectInstance = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, other.Id); } else { objectInstance = ProtocolGameExtentions.ReadObjectInstance(message, typeOrId); } WorldMapStorage.ChangeObject(mapPosition, stackPos, objectInstance); } else { uint creatureId = message.ReadUnsignedInt(); if (!(creature = CreatureStorage.GetCreatureById(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); int otherType = message.ReadUnsignedShort(); if (otherType == Appearances.AppearanceInstance.Creature || otherType == Appearances.AppearanceInstance.OutdatedCreature || otherType == Appearances.AppearanceInstance.UnknownCreature) { other = ProtocolGameExtentions.ReadCreatureInstance(message, otherType); } else { throw new System.Exception("ProtocolGame.ParseChangeOnMap: Received object of type " + otherType + " when a creature was expected."); } } // most of the time it updates the same creature // so set the creature's visiblity when nessecary if (!!creature && creature != other) { CreatureStorage.MarkOpponentVisible(creature, false); } 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; }