private int ReadFloor(Internal.ByteArray message, int z, int skip) { for (int x = 0; x <= Constants.MapSizeX - 1; x++) { for (int y = 0; y <= Constants.MapSizeY - 1; y++) { if (skip > 0) { skip--; } else { skip = ReadField(message, x, y, z); } UnityEngine.Vector3Int mapPosition = new UnityEngine.Vector3Int(x, y, z); UnityEngine.Vector3Int absolutePosition = WorldMapStorage.ToAbsolute(mapPosition); if (absolutePosition.z == MiniMapStorage.PositionZ) { WorldMapStorage.UpdateMiniMap(mapPosition); uint color = WorldMapStorage.GetMiniMapColour(mapPosition); int cost = WorldMapStorage.GetMiniMapCost(mapPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } } } return(skip); }
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; }
public RenderError Render(RenderTexture renderTarget) { if (MiniMapStorage == null || !OpenTibiaUnity.GameManager.IsGameRunning || !WorldMapStorage.Valid) { return(RenderError.MiniMapNotValid); } var commandBuffer = new CommandBuffer(); commandBuffer.SetRenderTarget(renderTarget); commandBuffer.ClearRenderTarget(false, true, Color.black); var zoom = new Vector2() { x = Screen.width / (float)Constants.MiniMapSideBarViewWidth, y = Screen.height / (float)Constants.MiniMapSideBarViewHeight, }; zoom *= _zoomScale; var drawnSectors = new List <MiniMapSector>(); // 4 is the maximum number of sectors to be drawn (pre-calculated) // todo; provide a function to calculate it (if someone plans to use minimap differently) Vector3Int curPosition = new Vector3Int(0, 0, PositionZ); for (int i = 0; i < 4; i++) { curPosition.x = _positionRect.x + i % 2 * _positionRect.width; curPosition.y = _positionRect.y + (i / 2) * _positionRect.height; var sector = MiniMapStorage.AcquireSector(curPosition, false); if (sector == null || drawnSectors.IndexOf(sector) != -1) { continue; } drawnSectors.Add(sector); var sectorRect = new RectInt(sector.SectorX, sector.SectorY, Constants.MiniMapSectorSize, Constants.MiniMapSectorSize); var translation = sectorRect.position - _positionRect.position; Matrix4x4 transformation = Matrix4x4.TRS(translation * zoom, Quaternion.Euler(180, 0, 0), Constants.MiniMapSectorSize * zoom); var props = new MaterialPropertyBlock(); props.SetTexture("_MainTex", sector.SafeDrawTexture); props.SetVector("_MainTex_UV", new Vector4(1, 1, 0, 0)); props.SetFloat("_HighlightOpacity", 0); Utils.GraphicsUtility.Draw(commandBuffer, transformation, OpenTibiaUnity.GameManager.AppearanceTypeMaterial, props); } Graphics.ExecuteCommandBuffer(commandBuffer); commandBuffer.Dispose(); return(RenderError.None); }
private int ReadArea(Internal.ByteArray message, int startx, int starty, int endx, int endy) { UnityEngine.Vector3Int position = WorldMapStorage.Position; int z, endz, zstep; if (position.z <= Constants.GroundLayer) { z = 0; endz = Constants.GroundLayer + 1; zstep = 1; } else { z = 2 * Constants.UndergroundLayer; endz = System.Math.Max(-1, position.z - Constants.MapMaxZ + 1); zstep = -1; } int skip = 0; for (; z != endz; z += zstep) { for (int x = startx; x <= endx; x++) { for (int y = starty; y <= endy; y++) { if (skip > 0) { skip--; } else { skip = ReadField(message, x, y, z); } UnityEngine.Vector3Int mapPosition = new UnityEngine.Vector3Int(x, y, z); UnityEngine.Vector3Int absolutePosition = WorldMapStorage.ToAbsolute(mapPosition); if (absolutePosition.z == MiniMapStorage.PositionZ) { WorldMapStorage.UpdateMiniMap(mapPosition); uint color = WorldMapStorage.GetMiniMapColour(mapPosition); int cost = WorldMapStorage.GetMiniMapCost(mapPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } } } } return(skip); }
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 ParseMapBottomFloor(Internal.ByteArray 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) { 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 = ReadFloor(message, zposition, skip); } } Player.StopAutowalk(true); WorldMapStorage.InvalidateOnscreenMessages(); UnityEngine.Vector3Int tmpPosition = WorldMapStorage.ToMap(position); for (int x = 0; x < Constants.MapSizeX; x++) { for (int y = 0; x < Constants.MapSizeY; y++) { tmpPosition.x = x; tmpPosition.y = y; UnityEngine.Vector3Int absolutePosition = WorldMapStorage.ToAbsolute(tmpPosition); WorldMapStorage.UpdateMiniMap(tmpPosition); uint color = WorldMapStorage.GetMiniMapColour(tmpPosition); int cost = WorldMapStorage.GetMiniMapCost(tmpPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } } }
public void SaveMiniMap() { if (!IsGameRunning) { if (!m_LastMiniMapSaveWasSuccessfull) { return; } else { m_LastMiniMapSaveWasSuccessfull = false; } } else { m_LastMiniMapSaveWasSuccessfull = true; } MiniMapStorage.OnIOTimer(); }
private void ParseFieldData(Internal.ByteArray 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); 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); } }
public RenderError Render(Material material) { if (MiniMapStorage == null || !OpenTibiaUnity.GameManager.IsGameRunning || !WorldMapStorage.Valid) { return(RenderError.MiniMapNotValid); } GL.Clear(false, true, Color.black); if (PositionX < Constants.MapMinX || PositionX > Constants.MapMaxX || PositionY < Constants.MapMinY || PositionY > Constants.MapMaxY || PositionZ < Constants.MapMinZ || PositionZ > Constants.MapMaxZ) { return(RenderError.PositionNotValid); } Vector2 screenZoom = new Vector2() { x = Screen.width * m_ZoomScale / Constants.MiniMapSideBarViewWidth, y = Screen.height * m_ZoomScale / Constants.MiniMapSideBarViewHeight, }; Vector2 zoom = new Vector2() { x = Constants.MiniMapSideBarViewWidth / m_ZoomScale, y = Constants.MiniMapSideBarViewHeight / m_ZoomScale }; m_PositionRect.x = PositionX - zoom.x / 2; m_PositionRect.y = PositionY - zoom.y / 2; m_PositionRect.width = zoom.x; m_PositionRect.height = zoom.y; var drawnSectors = new List <MiniMapSector>(); Vector3Int position = Vector3Int.zero; var transformationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(m_ZoomScale, m_ZoomScale, 1)); for (int i = 0; i < 4; i++) { position.Set( (int)(m_PositionRect.x + i % 2 * m_PositionRect.width), (int)(m_PositionRect.y + (int)(i / 2) * m_PositionRect.height), PositionZ); var sector = MiniMapStorage.AcquireSector(position, false); if (drawnSectors.IndexOf(sector) == -1) { drawnSectors.Add(sector); var otherRect = new Rect(sector.SectorX, sector.SectorY, Constants.MiniMapSectorSize, Constants.MiniMapSectorSize); var intersectingRect = Intersection(m_PositionRect, otherRect); Rect screenRect = new Rect() { x = (intersectingRect.x - m_PositionRect.x) * screenZoom.x, y = (intersectingRect.y - m_PositionRect.y) * screenZoom.y, width = intersectingRect.width * screenZoom.x, height = intersectingRect.height * screenZoom.y }; sector.ApplyPixelChanges(); Graphics.DrawTexture(screenRect, sector.Texture2D, OpenTibiaUnity.GameManager.DefaultMaterial); } } return(RenderError.None); }
private void ParseCreatureMove(Internal.ByteArray message) { int x = message.ReadUnsignedShort(); UnityEngine.Vector3Int oldAbsolutePosition; UnityEngine.Vector3Int oldMapPosition; int stackPos = -1; Appearances.ObjectInstance @object; Creatures.Creature creature; if (x != 65535) { oldAbsolutePosition = message.ReadPosition(x); if (!WorldMapStorage.IsVisible(oldAbsolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseCreatureMove: Start Co-ordinate " + oldAbsolutePosition + " is out of range."); } oldMapPosition = WorldMapStorage.ToMap(oldAbsolutePosition); stackPos = message.ReadUnsignedByte(); @object = WorldMapStorage.GetObject(oldMapPosition, stackPos); if (!@object || [email protected] || !(creature = CreatureStorage.GetCreature(@object.Data))) { throw new System.Exception("ProtocolGame.ParseCreatureMove: No creature at position " + oldAbsolutePosition); } } else { uint creatureId = message.ReadUnsignedInt(); @object = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creatureId); if (!(creature = CreatureStorage.GetCreature(creatureId))) { throw new System.Exception("ProtocolGame.ParseCreatureMove: Creature " + creatureId + " not found"); } oldAbsolutePosition = creature.Position; if (!WorldMapStorage.IsVisible(oldAbsolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseCreatureMove: Start Co-ordinate " + oldAbsolutePosition + " is out of range."); } oldMapPosition = WorldMapStorage.ToMap(oldAbsolutePosition); } var newAbsolutePosition = message.ReadPosition(); if (!WorldMapStorage.IsVisible(newAbsolutePosition, true)) { throw new System.Exception("ProtocolGame.ParseCreatureMove: Target Co-ordinate " + oldAbsolutePosition + " is out of range."); } var newMapPosition = WorldMapStorage.ToMap(newAbsolutePosition); var delta = newMapPosition - oldMapPosition; // if the movement is not actually a move (usually he is teleported) bool pushMovement = delta.z != 0 || System.Math.Abs(delta.x) > 1 || System.Math.Abs(delta.y) > 1; Appearances.ObjectInstance otherObj = null; if (!pushMovement && (!(otherObj = WorldMapStorage.GetObject(newMapPosition, 0)) || !otherObj.Type || !otherObj.Type.IsGround)) { throw new System.Exception("ProtocolGame.ParseCreatureMove: Target field " + newAbsolutePosition + " has no BANK."); } if (x != 65535) { WorldMapStorage.DeleteObject(oldMapPosition, stackPos); } WorldMapStorage.PutObject(newMapPosition, @object); creature.Position = newAbsolutePosition; if (pushMovement) { if (creature.Id == Player.Id) { Player.StopAutowalk(true); } if (delta.x > 0) { creature.Direction = Direction.East; } else if (delta.x < 0) { creature.Direction = Direction.West; } else if (delta.y < 0) { creature.Direction = Direction.North; } else if (delta.y > 0) { creature.Direction = Direction.South; } if (creature.Id != Player.Id) { creature.StopMovementAnimation(); } } else { creature.StartMovementAnimation(delta.x, delta.y, (int)otherObj.Type.GroundSpeed); } CreatureStorage.MarkOpponentVisible(creature, true); CreatureStorage.InvalidateOpponents(); if (oldAbsolutePosition.z == MiniMapStorage.PositionZ) { WorldMapStorage.UpdateMiniMap(oldMapPosition); uint color = WorldMapStorage.GetMiniMapColour(oldMapPosition); int cost = WorldMapStorage.GetMiniMapCost(oldMapPosition); MiniMapStorage.UpdateField(oldAbsolutePosition, color, cost, false); } if (newAbsolutePosition.z == MiniMapStorage.PositionZ) { WorldMapStorage.UpdateMiniMap(newMapPosition); uint color = WorldMapStorage.GetMiniMapColour(newMapPosition); int cost = WorldMapStorage.GetMiniMapCost(newMapPosition); MiniMapStorage.UpdateField(newAbsolutePosition, color, cost, false); } }
private void ParseDeleteOnMap(Internal.ByteArray 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.ParseDeleteOnMap: Co-oridnate ({absolutePosition.x}, {absolutePosition.y}, {absolutePosition.z}) is out of range."); } mapPosition = WorldMapStorage.ToMap(absolutePosition); int stackPos = message.ReadUnsignedByte(); if (!(objectInstance = WorldMapStorage.GetObject(mapPosition, stackPos))) { throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Object not found."); } if (objectInstance.IsCreature && (creature = CreatureStorage.GetCreature(objectInstance.Data)) == null) { throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Creature not found."); } WorldMapStorage.DeleteObject(mapPosition, stackPos); } else { uint creatureId = message.ReadUnsignedInt(); if ((creature = CreatureStorage.GetCreature(creatureId)) == null) { throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Object not found."); } absolutePosition = creature.Position; if (!WorldMapStorage.IsVisible(absolutePosition, true)) { throw new System.Exception($"ProtocolGame.ParseDeleteOnMap: Co-oridnate ({absolutePosition.x}, {absolutePosition.y}, {absolutePosition.z}) is out of range."); } mapPosition = WorldMapStorage.ToMap(absolutePosition); } if (!!creature) { CreatureStorage.MarkOpponentVisible(creature, false); } if (absolutePosition.z == MiniMapStorage.Position.z) { WorldMapStorage.UpdateMiniMap(mapPosition); uint color = WorldMapStorage.GetMiniMapColour(mapPosition); int cost = WorldMapStorage.GetMiniMapCost(mapPosition); MiniMapStorage.UpdateField(absolutePosition, color, cost, false); } }
private void ParseChangeOnMap(Internal.ByteArray 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 = ReadCreatureInstance(message, typeOrId, absolutePosition); objectInstance = AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creature.Id); } else { objectInstance = 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 = 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); } }