示例#1
0
        public Appearances.ObjectInstance PutObject(Appearances.ObjectInstance objectInstance, int stackPos)
        {
            if (!objectInstance)
            {
                return(null);
            }

            if (stackPos < 0)
            {
                stackPos = 0;
                int priority = GetObjectPriority(objectInstance);
                while (stackPos < ObjectsCount)
                {
                    int tmpPriority = GetObjectPriority(ObjectsNetwork[stackPos]);
                    if (tmpPriority > priority || (tmpPriority == priority && priority == 5))
                    {
                        break;
                    }
                    stackPos++;
                }

                if (stackPos >= Constants.MapSizeW)
                {
                    return(null);
                }
            }
            else if (stackPos <= ObjectsCount || stackPos == Constants.MapSizeW)
            {
                stackPos = System.Math.Min(System.Math.Min(stackPos, ObjectsCount), Constants.MapSizeW - 1);
            }
            else
            {
                return(null);
            }

            Appearances.ObjectInstance otherObject = null;
            if (ObjectsCount >= Constants.MapSizeW)
            {
                ObjectsCount = Constants.MapSizeW;
                otherObject  = ObjectsNetwork[Constants.MapSizeW - 1];
            }
            else
            {
                ObjectsCount++;
            }

            int index = ObjectsCount - 1;

            while (index > stackPos)
            {
                ObjectsNetwork[index] = ObjectsNetwork[index - 1];
                if (!!ObjectsNetwork[index])
                {
                    ObjectsNetwork[index].MapData = index;
                }
                index--;
            }

            objectInstance.MapData   = stackPos;
            ObjectsNetwork[stackPos] = objectInstance;
            CacheObjectsDirty        = true;
            MiniMapDirty             = true;
            return(otherObject);
        }
示例#2
0
        public Appearances.ObjectInstance ChangeObject(UnityEngine.Vector3Int mapPosition, int stackPos, Appearances.ObjectInstance @object)
        {
            AssertNullObject(@object, "WorldMapStorage.ChangeObject");
            Appearances.ObjectInstance otherObj = GetField(mapPosition).ChangeObject(@object, stackPos);
            if (!!otherObj && otherObj.IsCreature &&
                !!@object && @object.IsCreature && @object.Data != otherObj.Data)
            {
                OpenTibiaUnity.CreatureStorage.MarkOpponentVisible(otherObj.Data, false);
            }

            if (!!otherObj && otherObj.Type.IsFullGround || @object.Type.IsFullGround)
            {
                CacheFullbank = false;
            }

            return(otherObj);
        }
示例#3
0
        private void NextAutowalkStep()
        {
            if (m_MovementRunning || m_AutowalkPathAborting || m_AutowalkPathDelta != UnityEngine.Vector3Int.zero || m_AutowalkPathSteps.Count == 0)
            {
                return;
            }

            var protocolGame    = OpenTibiaUnity.ProtocolGame;
            var worldMapStorage = OpenTibiaUnity.WorldMapStorage;

            if (protocolGame == null || !protocolGame.IsGameRunning || worldMapStorage == null)
            {
                return;
            }

            switch ((PathDirection)(m_AutowalkPathSteps[0] & 65535))
            {
            case PathDirection.East:
                m_AutowalkPathDelta.x = 1;
                break;

            case PathDirection.NorthEast:
                m_AutowalkPathDelta.x = 1;
                m_AutowalkPathDelta.y = -1;
                break;

            case PathDirection.North:
                m_AutowalkPathDelta.y = -1;
                break;

            case PathDirection.NorthWest:
                m_AutowalkPathDelta.x = -1;
                m_AutowalkPathDelta.y = -1;
                break;

            case PathDirection.West:
                m_AutowalkPathDelta.x = -1;
                break;

            case PathDirection.SouthWest:
                m_AutowalkPathDelta.x = -1;
                m_AutowalkPathDelta.y = 1;
                break;

            case PathDirection.South:
                m_AutowalkPathDelta.y = 1;
                break;

            case PathDirection.SouthEast:
                m_AutowalkPathDelta.x = 1;
                m_AutowalkPathDelta.y = 1;
                break;

            default:
                throw new System.Exception("Player.NextAutowalkStep: Invalid step(1): " + (m_AutowalkPathSteps[0] & 65535));
            }

            var s_v1 = worldMapStorage.ToMap(m_Position);
            var s_v2 = worldMapStorage.ToMap(m_Position);

            s_v2.x += m_AutowalkPathDelta.x;
            s_v2.y += m_AutowalkPathDelta.y;

            // Tile should be walkable (full ground)
            Appearances.ObjectInstance obj = null;
            if (!(obj = worldMapStorage.GetObject(s_v2.x, s_v2.y, s_v2.z, 0)) || !obj.Type || !obj.Type.IsBank)
            {
                m_AutowalkPathDelta.Set(0, 0, 0);
                return;
            }

            uint possibleFlag = worldMapStorage.GetEnterPossibleFlag(s_v2.x, s_v2.y, s_v2.z, false);

            if (possibleFlag == Constants.FieldEnterNotPossible || worldMapStorage.GetFieldHeight(s_v1.x, s_v1.y, s_v1.z) + 1 < worldMapStorage.GetFieldHeight(s_v2.x, s_v2.y, s_v2.z))
            {
                m_AutowalkPathDelta.Set(0, 0, 0);
                return;
            }

            if (possibleFlag == Constants.FieldEnterPossible)
            {
                base.StartMovementAnimation(m_AutowalkPathDelta.x, m_AutowalkPathDelta.y, (int)obj.Type.Waypoints);
                m_AnimationDelta.x = m_AnimationDelta.x + m_AutowalkPathDelta.x * Constants.FieldSize;
                m_AnimationDelta.y = m_AnimationDelta.y + m_AutowalkPathDelta.y * Constants.FieldSize;
            }
            else if (possibleFlag == Constants.FieldEnterPossibleNoAnimation)
            {
                m_AnimationDelta.Set(0, 0, 0);
            }

            for (int i = 1; i < m_AutowalkPathSteps.Count; i++)
            {
                var rawDirection = m_AutowalkPathSteps[i] & 65535;
                var mapCost      = ((uint)m_AutowalkPathSteps[i] & 4294901760U) >> 16;
                switch ((PathDirection)rawDirection)
                {
                case PathDirection.East:
                    s_v2.x = s_v2.x + 1;
                    break;

                case PathDirection.NorthEast:
                    s_v2.x = s_v2.x + 1;
                    s_v2.y = s_v2.y - 1;
                    break;

                case PathDirection.North:
                    s_v2.y = s_v2.y - 1;
                    break;

                case PathDirection.NorthWest:
                    s_v2.x = s_v2.x - 1;
                    s_v2.y = s_v2.y - 1;
                    break;

                case PathDirection.West:
                    s_v2.x = s_v2.x - 1;
                    break;

                case PathDirection.SouthWest:
                    s_v2.x = s_v2.x - 1;
                    s_v2.y = s_v2.y + 1;
                    break;

                case PathDirection.South:
                    s_v2.y = s_v2.y + 1;
                    break;

                case PathDirection.SouthEast:
                    s_v2.x = s_v2.x + 1;
                    s_v2.y = s_v2.y + 1;
                    break;

                default:
                    throw new System.Exception("Player.NextAutowalkStep: Invalid step(2): " + (m_AutowalkPathSteps[i] & 65535));
                }

                if (s_v2.x < 0 || s_v2.x >= Constants.MapSizeX || s_v2.y < 0 || s_v2.y >= Constants.MapSizeY)
                {
                    break;
                }

                if (worldMapStorage.GetMiniMapCost(s_v2.x, s_v2.y, s_v2.z) > mapCost)
                {
                    protocolGame.SendStop();
                    m_AutowalkPathAborting = true;
                    break;
                }
            }
        }
示例#4
0
 internal int GetTopCreatureObject(UnityEngine.Vector3Int mapPosition, out Appearances.ObjectInstance @object)
 {
     return(GetField(mapPosition).GetTopCreatureObject(out @object));
 }
示例#5
0
 public Appearances.ObjectInstance PutObject(UnityEngine.Vector3Int mapPosition, Appearances.ObjectInstance @object)
 {
     AssertNullObject(@object, "WorldMapStorage.PutObject");
     return(InsertObject(mapPosition, -1, @object));
 }
示例#6
0
 public void ResetEffects()
 {
     Effects.Clear();
     EffectsCount        = 0;
     EnvironmentalEffect = null;
 }
示例#7
0
        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);
            }
        }
示例#8
0
        public static AppearanceActions ResolveActionForAppearanceOrCreature(AppearanceActions action, object obj)
        {
            if (obj == null)
            {
                throw new System.ArgumentNullException("MouseActionHelper.ResolveActionForAppearanceOrCreature: obj must be ObjectInstance or Creature");
            }

            Appearances.ObjectInstance objectInstance = null;
            Creatures.Creature         creature       = null;
            if (obj is Appearances.ObjectInstance)
            {
                objectInstance = obj as Appearances.ObjectInstance;
                if (objectInstance.IsCreature)
                {
                    creature = OpenTibiaUnity.CreatureStorage.GetCreature(objectInstance.Data);
                }
            }
            else
            {
                creature = obj as Creatures.Creature;
            }

            if (action == AppearanceActions.SmartClick)
            {
                if (creature == OpenTibiaUnity.Player)
                {
                    action = AppearanceActions.None;
                }
                else if (!!objectInstance && objectInstance.Type.DefaultAction != 0)
                {
                    action = (AppearanceActions)objectInstance.Type.DefaultAction;
                }
                else if (!!creature)
                {
                    action = AppearanceActions.AttackOrTalk;
                }
                else if (!!objectInstance && objectInstance.Type.IsUsable)
                {
                    action = AppearanceActions.UseOrOpen;
                }
                else
                {
                    action = AppearanceActions.Look;
                }
            }

            if (action == AppearanceActions.UseOrOpen)
            {
                action = AppearanceActions.Use;
                if (!!objectInstance && objectInstance.Type.IsContainer)
                {
                    action = AppearanceActions.Open;
                }
            }

            if (action == AppearanceActions.AttackOrTalk)
            {
                action = AppearanceActions.Attack;
                if (!!creature && creature.IsNPC)
                {
                    action = AppearanceActions.Talk;
                }
            }

            if (action == AppearanceActions.AutoWalk && !!objectInstance && objectInstance.Type.DefaultAction == (int)AppearanceActions.AutoWalkHighlight)
            {
                action = AppearanceActions.AutoWalkHighlight;
            }

            return(action);
        }
示例#9
0
        private void InternalDrawField(float rectX, float rectY, int absoluteX, int absoluteY, int absoluteZ, int positionX, int positionY, int positionZ, bool drawLyingObjects)
        {
            Field field = m_WorldMapStorage.GetField(positionX, positionY, positionZ);

            int  objCount            = field.ObjectsCount;
            int  mz                  = positionY * Constants.MapSizeX + positionX;
            bool isExplicitlyVisible = positionZ > m_MinZPlane[mz] ||
                                       (positionX == 0 || positionZ >= m_MinZPlane[mz - 1]) ||
                                       (positionY == 0 || positionZ >= m_MinZPlane[mz - Constants.MapSizeX]) ||
                                       (positionX == 0 && positionY == 0 || positionZ >= m_MinZPlane[mz - Constants.MapSizeX - 1]);

            int objectsHeight = 0;

            Appearances.ObjectInstance previousHang = null;

            if (drawLyingObjects && objCount > 0 && isExplicitlyVisible)
            {
                Appearances.ObjectInstance obj;
                bool isLying = false;

                // cached objects don't have lights, animations or anything!
                for (int i = 0; i < field.CacheObjectsCount; i++)
                {
                    if (!(obj = field.ObjectsRenderer[i]))
                    {
                        break;
                    }

                    var screenPosition = new Vector2(rectX - objectsHeight, rectY - objectsHeight);
                    obj.DrawTo(screenPosition, m_ScreenZoom, absoluteX, absoluteY, absoluteZ);

                    objectsHeight += (int)obj.Type.Elevation;
                    if (objectsHeight > Constants.FieldHeight)
                    {
                        objectsHeight = Constants.FieldHeight;
                    }
                }

                for (int i = field.CacheObjectsCount; i < objCount; i++)
                {
                    if (!(obj = field.ObjectsRenderer[i]) || obj.ID == Appearances.AppearanceInstance.Creature || obj.Type.IsTop)
                    {
                        break;
                    }

                    if (m_OptionStorage.ShowLightEffects && obj.Type.IsLight)
                    {
                        // check how correct those are
                        int     lightX  = ((int)rectX - objectsHeight - obj.Type.DisplacementX) / Constants.FieldSize;
                        int     lightY  = ((int)rectY - objectsHeight - obj.Type.DisplacementY) / Constants.FieldSize;
                        Color32 color32 = Colors.ColorFrom8Bit((byte)obj.Type.LightColor);

                        m_LightmapRenderer.SetLightSource(lightX, lightY, positionZ, obj.Type.Brightness, color32);
                    }

                    var screenPosition = new Vector2(rectX - objectsHeight, rectY - objectsHeight);
                    obj.DrawTo(screenPosition, m_ScreenZoom, absoluteX, absoluteY, absoluteZ);
                    if (obj == m_HighlightObject)
                    {
                        m_ObjectCursor.DrawTo(rectX - objectsHeight, rectY - objectsHeight);
                    }

                    isLying = isLying || obj.Type.IsLyingObject;
                    if (obj.Type.IsHangable && obj.Hang == Appearances.AppearanceInstance.HookSouth)
                    {
                        previousHang = obj;
                    }

                    objectsHeight += (int)obj.Type.Elevation;
                    if (objectsHeight > Constants.FieldHeight)
                    {
                        objectsHeight = Constants.FieldHeight;
                    }
                }

                // isLying corpse? draw cached lying objects
                if (isLying || field.CacheLyingObject)
                {
                    int fieldSize = Constants.FieldSize;
                    if (positionX > 0 && positionY > 0)
                    {
                        InternalDrawField(rectX - fieldSize, rectY - fieldSize, absoluteX - 1, absoluteY - 1, absoluteZ, positionX - 1, positionY - 1, positionZ, false);
                    }
                    else if (positionX > 0)
                    {
                        InternalDrawField(rectX - fieldSize, rectY, absoluteX - 1, absoluteY, absoluteZ, positionX - 1, positionY, positionZ, false);
                    }
                    else if (positionY > 0)
                    {
                        InternalDrawField(rectX, rectY - fieldSize, absoluteX, absoluteY - 1, absoluteZ, positionX, positionY - 1, positionZ, false);
                    }
                }

                // draw hang object
                if (!!m_PreviousHang)
                {
                    var screenPosition = new Vector2(m_HangPixelX, m_HangPixelY);
                    m_PreviousHang.DrawTo(screenPosition, m_ScreenZoom, m_HangPatternX, m_HangPatternY, m_HangPatternZ);
                    if (m_PreviousHang == m_HighlightObject)
                    {
                        m_ObjectCursor.DrawTo(m_HangPixelX, m_HangPixelY);
                    }
                }

                if (!!previousHang)
                {
                    m_PreviousHang = previousHang;
                    m_HangPixelX   = rectX;
                    m_HangPixelY   = rectY;
                    m_HangPatternX = absoluteX;
                    m_HangPatternY = absoluteY;
                    m_HangPatternZ = absoluteZ;
                }
                else
                {
                    m_PreviousHang = null;
                }
            }

            RenderAtom[] renderAtomArray = m_CreatureField[positionY * Constants.MapSizeX + positionX];
            int          creatureCount   = m_CreatureCount[positionY * Constants.MapSizeX + positionX];

            for (int i = 0; i < creatureCount; i++)
            {
                RenderAtom         renderAtom = null;
                Creatures.Creature creature   = null;
                if (!(renderAtom = renderAtomArray[i]) || !(creature = renderAtom.Object as Creatures.Creature) || !creature.Outfit)
                {
                    continue;
                }

                if (drawLyingObjects)
                {
                    renderAtom.x -= objectsHeight;
                    renderAtom.y -= objectsHeight;
                }

                // Draw Marks
                m_HelperPoint.Set(renderAtom.x - Constants.FieldSize, renderAtom.y - Constants.FieldSize);
                creature.Marks.Draw(OpenTibiaUnity.GameManager.MarksViewTexture, m_HelperPoint.x, m_HelperPoint.y, m_ScreenZoom, Appearances.Marks.MarkType_ClientMapWindow);

                Vector2Int displacement = new Vector2Int(0, 0);
                if (isExplicitlyVisible && !!creature.MountOutfit)
                {
                    displacement += creature.MountOutfit.Type.Displacement;

                    var screenPosition = new Vector2(renderAtom.x + displacement.x, renderAtom.y + displacement.y);
                    creature.MountOutfit.DrawTo(screenPosition, m_ScreenZoom, (int)creature.Direction, 0, 0);
                }

                if (isExplicitlyVisible)
                {
                    displacement += creature.Outfit.Type.Displacement;
                    var screenPosition = new Vector2(renderAtom.x + displacement.x, renderAtom.y + displacement.y);
                    creature.Outfit.DrawTo(screenPosition, m_ScreenZoom, (int)creature.Direction, 0, !!creature.MountOutfit ? 1 : 0);
                }

                Appearances.ObjectInstance obj;
                if (isExplicitlyVisible && m_HighlightObject != null && (!!(obj = m_HighlightObject as Appearances.ObjectInstance) && creature.ID == obj.Data) || (m_HighlightObject is Creatures.Creature && m_HighlightObject == creature))
                {
                    m_ObjectCursor.DrawTo(renderAtom.x + displacement.x, renderAtom.y + displacement.y);
                }

                if (positionZ == m_PlayerZPlane && (m_CreatureStorage.IsOpponent(creature) || creature.ID == m_Player.ID))
                {
                    m_DrawnCreatures[m_DrawnCreaturesCount].Assign(renderAtom);
                    m_DrawnCreaturesCount++;
                }

                if (isExplicitlyVisible && drawLyingObjects && m_OptionStorage.ShowLightEffects)
                {
                    int lightX = renderAtom.x / Constants.FieldSize;
                    int lightY = renderAtom.y / Constants.FieldSize;

                    m_LightmapRenderer.SetLightSource(lightX, lightY, positionZ, (uint)creature.Brightness, creature.LightColor);

                    if (!!creature.MountOutfit && creature.MountOutfit.Type.IsLight)
                    {
                        var color = Colors.ColorFrom8Bit((byte)creature.MountOutfit.Type.LightColor);
                        m_LightmapRenderer.SetLightSource(lightX, lightY, positionZ, creature.MountOutfit.Type.Brightness, color);
                    }

                    if (!!creature.Outfit && creature.Outfit.Type.IsLight)
                    {
                        var color = Colors.ColorFrom8Bit((byte)creature.Outfit.Type.LightColor);
                        m_LightmapRenderer.SetLightSource(lightX, lightY, positionZ, creature.Outfit.Type.Brightness, color);
                    }

                    if (creature.ID == m_Player.ID && creature.Brightness < 2)
                    {
                        var color = new Color32(255, 255, 255, 255);
                        m_LightmapRenderer.SetLightSource(lightX, lightY, positionZ, 2, color);
                    }
                }
            }

            int effectRectX  = (int)rectX - objectsHeight;
            int effectRectY  = (int)rectY - objectsHeight;
            int effectLightX = effectRectX / Constants.FieldSize;
            int effectLightY = effectRectY / Constants.FieldSize;

            int loc29 = 0;
            int loc30 = 0;

            for (int i = field.EffectsCount - 1; i >= 0; i--)
            {
                var effect = field.Effects[i];
                if (!effect)
                {
                    continue;
                }

                if (effect is Appearances.TextualEffectInstance)
                {
                    if (drawLyingObjects)
                    {
                        var renderAtom = m_DrawnTextualEffects[m_DrawnTextualEffectsCount];
                        renderAtom.Update(effect, effectRectX - Constants.FieldSize / 2 + loc29, effectRectY - Constants.FieldSize - 2 * effect.Phase, 0);

                        if (renderAtom.y + (effect as Appearances.TextualEffectInstance).Height > loc30)
                        {
                            loc29 += (effect as Appearances.TextualEffectInstance).Width;
                        }

                        if (loc29 < 2 * Constants.FieldSize)
                        {
                            m_DrawnTextualEffectsCount++;
                            loc30 = renderAtom.x;
                        }
                    }
                }
                else if (effect is Appearances.MissileInstance)
                {
                    var missile        = effect as Appearances.MissileInstance;
                    var screenPosition = new Vector2(effectRectX + missile.AnimationDelta.x, effectRectY + missile.AnimationDelta.y);
                    effect.DrawTo(screenPosition, m_ScreenZoom, absoluteX, absoluteY, absoluteZ);

                    if (drawLyingObjects && m_OptionStorage.ShowLightEffects && effect.Type.IsLight)
                    {
                        var color = Colors.ColorFrom8Bit((byte)effect.Type.LightColor);
                        m_LightmapRenderer.SetLightSource(effectLightX, effectLightY, positionZ, effect.Type.Brightness, color);
                    }
                }
                else     // EffectInstance
                {
                    var screenPosition = new Vector2(effectRectX, effectRectY);
                    effect.DrawTo(screenPosition, m_ScreenZoom, absoluteX, absoluteY, absoluteZ);

                    if (drawLyingObjects && m_OptionStorage.ShowLightEffects && effect.Type.IsLight)
                    {
                        uint activeBrightness = (uint)((Math.Min(effect.Phase, effect.Type.FrameGroups[0].Phases + 1 - effect.Phase) * effect.Type.Brightness + 2) / 3);
                        var  color            = Colors.ColorFrom8Bit((byte)effect.Type.LightColor);
                        m_LightmapRenderer.SetLightSource(effectLightX, effectLightY, positionZ, Math.Min(activeBrightness, effect.Type.Brightness), color);
                    }
                }
            }

            // TODO: this should be drawn on a separate render texture
            // (atmosphoric)
            if (!!field.EnvironmentalEffect)
            {
                var screenPosition = new Vector2(rectX, rectY);
                field.EnvironmentalEffect.DrawTo(screenPosition, m_ScreenZoom, absoluteX, absoluteY, absoluteZ);
            }

            if (drawLyingObjects && objCount > 0)
            {
                var obj = field.ObjectsRenderer[objCount - 1];
                if (!!obj && !!obj.Type && obj.Type.IsTop)
                {
                    var screenPosition = new Vector2(rectX, rectY);
                    obj.DrawTo(screenPosition, m_ScreenZoom, absoluteX, absoluteY, absoluteZ);
                }
            }
        }
示例#10
0
 public void SetEnvironmentalEffect(UnityEngine.Vector3Int position, Appearances.ObjectInstance effectObject)
 {
     m_Fields[ToIndexInternal(position)].EnvironmentalEffect = effectObject;
 }
示例#11
0
        public Appearances.ObjectInstance AppendObject(UnityEngine.Vector3Int position, Appearances.ObjectInstance obj)
        {
            AssertNullObject(obj, "WorldMapStorage.AppendObject");
            Appearances.ObjectInstance otherObj = m_Fields[ToIndexInternal(position)].PutObject(obj, Constants.MapSizeW);
            if (!!otherObj && otherObj.ID == Appearances.AppearanceInstance.Creature)
            {
                OpenTibiaUnity.CreatureStorage.MarkOpponentVisible(otherObj.Data, false);
            }
            else if (otherObj == null)
            {
                m_CacheObjectsCount[(m_Origin.z + position.z) % Constants.MapSizeZ]++;
            }

            if (!!obj.Type && obj.Type.IsFullBank)
            {
                CacheFullbank = false;
            }

            return(otherObj);
        }
示例#12
0
 public int GetTopCreatureObject(UnityEngine.Vector3Int position, out Appearances.ObjectInstance obj)
 {
     return(GetField(position).GetTopCreatureObject(out obj));
 }
示例#13
0
        public Appearances.ObjectInstance ChangeObject(UnityEngine.Vector3Int position, int stackPos, Appearances.ObjectInstance obj)
        {
            AssertNullObject(obj, "WorldMapStorage.ChangeObject");
            Appearances.ObjectInstance otherObj = m_Fields[ToIndexInternal(position)].ChangeObject(obj, stackPos);
            if (!!otherObj && otherObj.ID == Appearances.AppearanceInstance.Creature &&
                !!obj && obj.ID == Appearances.AppearanceInstance.Creature && obj.Data != otherObj.Data)
            {
                OpenTibiaUnity.CreatureStorage.MarkOpponentVisible(otherObj.Data, false);
            }

            if (!!otherObj && otherObj.Type.IsFullBank || obj.Type.IsFullBank)
            {
                CacheFullbank = false;
            }

            return(otherObj);
        }
示例#14
0
 public Appearances.ObjectInstance PutObject(UnityEngine.Vector3Int position, Appearances.ObjectInstance obj)
 {
     AssertNullObject(obj, "WorldMapStorage.PutObject");
     return(InsertObject(position, -1, obj));
 }
示例#15
0
 public int GetTopCreatureObject()
 {
     Appearances.ObjectInstance _ = null;
     return(GetTopCreatureObject(out _));
 }
示例#16
0
 public UseActionImpl(Vector3Int absolutePosition, Appearances.ObjectInstance objectInstance, int positionOrData, UseActionTarget useTarget)
 {
     Init(absolutePosition, objectInstance?.Type, positionOrData, useTarget);
 }
示例#17
0
        public void UpdateObjectsCache()
        {
            if (!CacheObjectsDirty)
            {
                return;
            }

            CacheObjectsDirty = false;

            int index = 0;

            if (ObjectsCount > 0)
            {
                // ground, borders, bottom items
                for (int i = 0; i < ObjectsCount; i++)
                {
                    var @object = ObjectsNetwork[i];
                    var type    = @object.Type;
                    if (type.IsGround || type.IsGroundBorder || type.IsBottom)
                    {
                        ObjectsRenderer[index++] = @object;
                    }
                }

                // common items
                for (int i = ObjectsCount - 1; i >= 0; i--)
                {
                    var @object = ObjectsNetwork[i];
                    var type    = @object.Type;
                    if (!type.IsGround && !type.IsGroundBorder && !type.IsBottom && !type.IsTop && !type.IsCreature)
                    {
                        ObjectsRenderer[index++] = @object;
                    }
                }

                // creatures
                for (int i = ObjectsCount - 1; i >= 0; i--)
                {
                    var @object = ObjectsNetwork[i];
                    var type    = @object.Type;
                    if (@object.IsCreature)
                    {
                        ObjectsRenderer[index++] = @object;
                    }
                }

                // top items
                for (int i = 0; i < ObjectsCount; i++)
                {
                    var @object = ObjectsNetwork[i];
                    var type    = @object.Type;
                    if (type.IsTop)
                    {
                        ObjectsRenderer[index++] = @object;
                    }
                }
            }

            while (index < Constants.MapSizeW)
            {
                ObjectsRenderer[index++] = null;
            }


            CacheTranslucent = false;
            CacheUnsight     = false;

            Appearances.ObjectInstance hangableObject = null;
            Appearances.AppearanceType hookType       = null;

            for (int i = 0; i < ObjectsCount; i++)
            {
                Appearances.AppearanceType tmpType = ObjectsNetwork[i].Type;
                CacheTranslucent = CacheTranslucent || tmpType.IsTranslucent;
                CacheUnsight     = CacheUnsight || tmpType.IsUnsight;

                if (tmpType.IsHangable)
                {
                    hangableObject = ObjectsNetwork[i];
                }
                else if (tmpType.IsHookEast || tmpType.IsHookSouth)
                {
                    hookType = tmpType;
                }
            }

            if (hangableObject)
            {
                if (!!hookType && hookType.IsHookEast)
                {
                    hangableObject.Hang = Appearances.AppearanceInstance.HookEast;
                }
                else if (hookType)
                {
                    hangableObject.Hang = Appearances.AppearanceInstance.HookSouth;
                }
                else
                {
                    hangableObject.Hang = 0;
                }
            }
        }
示例#18
0
 public LookActionImpl(Vector3Int absolutePosition, Appearances.ObjectInstance objectInstance, int stackPosition)
 {
     Init(absolutePosition, objectInstance?.Type, stackPosition);
 }
示例#19
0
 public ToggleWrapStateActionImpl(UnityEngine.Vector3Int absolute, Appearances.ObjectInstance @object, int stackPos)
 {
     _absolute       = absolute;
     _appearanceType = @object?.Type ?? throw new System.ArgumentNullException("ToggleWrapStateActionImpl.ToggleWrapStateActionImpl: Invalid object.");
     _stackPos       = stackPos;
 }
示例#20
0
 public UseActionImpl(Vector3Int absolutePosition, Appearances.AppearanceType appearanceType, int stackPosOrData, Vector3Int targetAbsolute, Appearances.ObjectInstance targetObject, int targetPosition, UseActionTarget useTarget)
 {
     Init(absolutePosition, appearanceType, stackPosOrData, targetAbsolute, targetObject, targetPosition, useTarget);
 }
示例#21
0
        internal Appearances.ObjectInstance AppendObject(UnityEngine.Vector3Int mapPosition, Appearances.ObjectInstance @object)
        {
            AssertNullObject(@object, "WorldMapStorage.AppendObject");
            var otherObj = GetField(mapPosition).PutObject(@object, Constants.MapSizeW);

            if (!!otherObj && otherObj.IsCreature)
            {
                OpenTibiaUnity.CreatureStorage.MarkOpponentVisible(otherObj.Data, false);
            }
            else if (otherObj == null)
            {
                m_CacheObjectsCount[(m_Origin.z + mapPosition.z) % Constants.MapSizeZ]++;
            }

            if ([email protected] && @object.Type.IsFullGround)
            {
                CacheFullbank = false;
            }

            return(otherObj);
        }
示例#22
0
        public UseActionImpl(Vector3Int absolutePosition, uint objectId, int stackPosOrData, Vector3Int targetAbsolute, Appearances.ObjectInstance targetObject, int targetPosition, UseActionTarget useTarget)
        {
            var appearnceType = OpenTibiaUnity.AppearanceStorage.GetObjectType(objectId);

            Init(absolutePosition, appearnceType, stackPosOrData, targetAbsolute, targetObject, targetPosition, useTarget);
        }
示例#23
0
 internal void SetEnvironmentalEffect(UnityEngine.Vector3Int mapPosition, Appearances.ObjectInstance effectObject)
 {
     GetField(mapPosition).EnvironmentalEffect = effectObject;
 }
示例#24
0
        protected void Init(Vector3Int absolutePosition, Appearances.AppearanceType appearanceType, int stackPosOrData, Vector3Int targetAbsolute, Appearances.ObjectInstance targetObject, int targetStackPosOrData, UseActionTarget useTarget)
        {
            _appearanceType = appearanceType;
            if (!_appearanceType)
            {
                throw new System.ArgumentException("UseActionImpl.UseActionImpl: Invalid type: " + appearanceType);
            }

            _absolutePosition = absolutePosition;
            if (_absolutePosition.x == 65535 && _absolutePosition.y == 0)
            {
                _stackPosOrData = stackPosOrData;
            }
            else if (_absolutePosition.x == 65535 && _absolutePosition.y != 0)
            {
                _stackPosOrData = _absolutePosition.z;
            }
            else
            {
                _stackPosOrData = stackPosOrData;
            }

            _targetObject           = targetObject;
            _targetAbsolutePosition = absolutePosition;
            if (_targetAbsolutePosition.x == 65535 && _targetAbsolutePosition.y == 0)
            {
                _targetStackPosOrData = targetStackPosOrData;
            }
            else if (_targetAbsolutePosition.x == 65535 && _targetAbsolutePosition.y != 0)
            {
                _targetStackPosOrData = _targetAbsolutePosition.z;
            }
            else
            {
                _targetStackPosOrData = targetStackPosOrData;
            }

            _useActionTarget = useTarget;
        }
示例#25
0
        public Appearances.ObjectInstance InsertObject(UnityEngine.Vector3Int mapPosition, int stackPos, Appearances.ObjectInstance @object)
        {
            AssertNullObject(@object, "WorldMapStorage.InsertObject");
            var otherObj = GetField(mapPosition).PutObject(@object, stackPos);

            if (!!otherObj && otherObj.IsCreature)
            {
                OpenTibiaUnity.CreatureStorage.MarkOpponentVisible(otherObj.Data, false);
            }
            else if (!otherObj)
            {
                _cacheObjectsCount[(_origin.z + mapPosition.z) % Constants.MapSizeZ]++;
            }

            if (!!otherObj && otherObj.Type.IsFullGround || @object.Type.IsFullGround)
            {
                CacheFullbank = false;
            }

            return(otherObj);
        }
示例#26
0
        private void ParseCreatureMove(InputMessage message)
        {
            int x = message.GetU16();

            UnityEngine.Vector3Int oldAbsolutePosition;
            UnityEngine.Vector3Int oldMapPosition;
            int stackPos = -1;

            Appearances.ObjectInstance obj;
            Creatures.Creature         creature;

            if (x != 65535)
            {
                oldAbsolutePosition = message.GetPosition(x);
                if (!m_WorldMapStorage.IsVisible(oldAbsolutePosition, true))
                {
                    throw new System.Exception("ProtocolGame.ParseCreateOnMap: Start Co-ordinate " + oldAbsolutePosition + " is out of range.");
                }

                oldMapPosition = m_WorldMapStorage.ToMap(oldAbsolutePosition);
                stackPos       = message.GetU8();
                obj            = m_WorldMapStorage.GetObject(oldMapPosition, stackPos);
                if (!obj || !obj.IsCreature || !(creature = m_CreatureStorage.GetCreature(obj.Data)))
                {
                    throw new System.Exception("ProtocolGame.ParseCreatureMove: no creature at position " + oldAbsolutePosition);
                }
            }
            else
            {
                uint creatureID = message.GetU32();
                obj = m_AppearanceStorage.CreateObjectInstance(Appearances.AppearanceInstance.Creature, creatureID);
                if (!(creature = m_CreatureStorage.GetCreature(creatureID)))
                {
                    throw new System.Exception("ProtocolGame.ParseCreatureMove: Creature " + creatureID + " not found");
                }

                oldAbsolutePosition = creature.Position;
                if (!m_WorldMapStorage.IsVisible(oldAbsolutePosition, true))
                {
                    throw new System.Exception("ProtocolGame.ParseCreateOnMap: Start Co-ordinate " + oldAbsolutePosition + " is out of range.");
                }

                oldMapPosition = m_WorldMapStorage.ToMap(oldAbsolutePosition);
            }

            UnityEngine.Vector3Int newAbsolutePosition = message.GetPosition();
            if (!m_WorldMapStorage.IsVisible(newAbsolutePosition, true))
            {
                throw new System.Exception("ProtocolGame.ParseCreateOnMap: Target Co-ordinate " + oldAbsolutePosition + " is out of range.");
            }

            UnityEngine.Vector3Int newMapPosition = m_WorldMapStorage.ToMap(newAbsolutePosition);
            UnityEngine.Vector3Int 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 = m_WorldMapStorage.GetObject(newMapPosition, 0)) || !otherObj.Type || !otherObj.Type.IsBank))
            {
                throw new System.Exception("ProtocolGame.ParseCreateOnMap: Target field " + newAbsolutePosition + " has no BANK.");
            }

            if (x != 65535)
            {
                m_WorldMapStorage.DeleteObject(oldMapPosition, stackPos);
            }

            m_WorldMapStorage.PutObject(newMapPosition, obj);
            creature.Position = newAbsolutePosition;

            if (pushMovement)
            {
                if (creature.ID == m_Player.ID)
                {
                    m_Player.StopAutowalk(true);
                }

                if (delta.x > 0)
                {
                    creature.Direction = Directions.East;
                }
                else if (delta.x < 0)
                {
                    creature.Direction = Directions.West;
                }
                else if (delta.y < 0)
                {
                    creature.Direction = Directions.North;
                }
                else if (delta.y > 0)
                {
                    creature.Direction = Directions.South;
                }

                if (creature.ID != m_Player.ID)
                {
                    creature.StopMovementAnimation();
                }
            }
            else
            {
                creature.StartMovementAnimation(delta.x, delta.y, (int)otherObj.Type.Waypoints);
            }

            m_CreatureStorage.MarkOpponentVisible(creature, true);
            m_CreatureStorage.InvalidateOpponents();

            if (oldAbsolutePosition.z == m_MiniMapStorage.PositionZ)
            {
                m_WorldMapStorage.UpdateMiniMap(oldMapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(oldMapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(oldMapPosition);
                m_MiniMapStorage.UpdateField(oldAbsolutePosition, color, cost, false);
            }

            if (newAbsolutePosition.z == m_MiniMapStorage.PositionZ)
            {
                m_WorldMapStorage.UpdateMiniMap(newMapPosition);
                uint color = m_WorldMapStorage.GetMiniMapColour(newMapPosition);
                int  cost  = m_WorldMapStorage.GetMiniMapCost(newMapPosition);
                m_MiniMapStorage.UpdateField(newAbsolutePosition, color, cost, false);
            }
        }
示例#27
0
 public int GetTopLookObject(UnityEngine.Vector3Int mapPosition, out Appearances.ObjectInstance @object)
 {
     return(GetField(mapPosition).GetTopLookObject(out @object));
 }
示例#28
0
        public void UpdateObjectsCache()
        {
            int index        = 0;
            int objectsCount = ObjectsCount;

            Appearances.AppearanceType tmpType = null;

            while (index < ObjectsCount && ((tmpType = ObjectsNetwork[index].Type).IsBank || tmpType.IsClip || tmpType.IsBottom))
            {
                ObjectsRenderer[index] = ObjectsNetwork[index];
                index++;
            }

            while (index < ObjectsCount)
            {
                ObjectsRenderer[index] = ObjectsNetwork[--objectsCount];
                index++;
            }

            while (index < Constants.MapSizeW)
            {
                ObjectsRenderer[index] = null;
                index++;
            }

            Appearances.ObjectInstance hangableObject = null;
            Appearances.AppearanceType hookType       = null;

            CacheTranslucent = false;
            CacheUnsight     = false;

            for (int i = 0; i < ObjectsCount; i++)
            {
                tmpType          = ObjectsNetwork[i].Type;
                CacheTranslucent = CacheTranslucent || tmpType.IsTranslucent;
                CacheUnsight     = CacheUnsight || tmpType.IsUnsight;

                if (tmpType.IsHangable)
                {
                    hangableObject = ObjectsNetwork[i];
                }
                else if (tmpType.IsHookEast || tmpType.IsHookSouth)
                {
                    hookType = tmpType;
                }
            }

            if (hangableObject)
            {
                if (!!tmpType && tmpType.IsHookEast)
                {
                    hangableObject.Hang = Appearances.AppearanceInstance.HookEast;
                }
                else if (tmpType)
                {
                    hangableObject.Hang = Appearances.AppearanceInstance.HookSouth;
                }
                else
                {
                    hangableObject.Hang = 0;
                }
            }
        }