static object PerformMemberwiseClone(ref object o)
        {
            var ins = new UnityEngine.Vector3Int();

            ins = (UnityEngine.Vector3Int)o;
            return(ins);
        }
Beispiel #2
0
        static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @z = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Int32 @y = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Int32 @x = ptr_of_this_method->Value;


            var result_of_this_method = new UnityEngine.Vector3Int(@x, @y, @z);

            if (!isNewObj)
            {
                __ret--;
                WriteBackInstance(__domain, __ret, __mStack, ref result_of_this_method);
                return(__ret);
            }

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #3
0
        public void AddTextualEffect(UnityEngine.Vector3Int absolutePosition, int color, string text, bool mergable = true)
        {
            var textMesh      = UnityEngine.Object.Instantiate(_textBoxPrefab, OpenTibiaUnity.GameManager.OnscreenMessagesContainer);
            var textualEffect = OpenTibiaUnity.AppearanceStorage.CreateTextualEffect(color, text, textMesh);

            AppendEffect(absolutePosition, textualEffect);
        }
        private static void LoadHomes()
        {
            Log.Write("Loading homes...");
            string jsonFilePath = "./gamedata/savegames/" + ServerManager.WorldName + "/homes.json";

            if (!File.Exists(jsonFilePath))
            {
                Log.Write("Could not locate homes.json! Ignoring");
                return;
            }

            JSONNode homesJSON = JSON.Deserialize(jsonFilePath);

            foreach (JSONNode playerJSON in homesJSON.LoopArray())
            {
                NetworkID player = NetworkID.Parse(playerJSON.GetAs <string>("i"));
                Dictionary <string, UnityEngine.Vector3Int> playerHomesJSON = new Dictionary <string, UnityEngine.Vector3Int>();

                // Load homes
                foreach (var v in playerJSON.GetAs <JSONNode>("h").LoopArray())
                {
                    UnityEngine.Vector3Int position = new UnityEngine.Vector3Int(v["x"].GetAs <int>(), v["y"].GetAs <int>(), v["z"].GetAs <int>());
                    playerHomesJSON.Add(v.GetAs <string>("n"), position);
                }


                homes.Add(player, playerHomesJSON);
            }

            Log.Write("Loaded homes.");
        }
Beispiel #5
0
        public virtual void AnimateMovement(int ticks)
        {
            m_AnimationDelta = UnityEngine.Vector3Int.zero;
            if (m_MovementRunning)
            {
                int diff = ticks - (m_AnimationEnd - m_AnimationSpeed.z);
                if (diff < 0)
                {
                    m_AnimationDelta.x = m_AnimationSpeed.x;
                    m_AnimationDelta.y = m_AnimationSpeed.y;
                }
                else if (diff >= m_AnimationSpeed.z)
                {
                    m_AnimationDelta.x = 0;
                    m_AnimationDelta.y = 0;
                }
                else if (m_AnimationSpeed.z != 0)
                {
                    m_AnimationDelta.x = m_AnimationSpeed.x - (int)System.Math.Round((double)m_AnimationSpeed.x * diff / m_AnimationSpeed.z);
                    m_AnimationDelta.y = m_AnimationSpeed.y - (int)System.Math.Round((double)m_AnimationSpeed.y * diff / m_AnimationSpeed.z);
                }
            }

            m_MovementRunning = ticks < m_MovementEnd || m_AnimationDelta.x != 0 || m_AnimationDelta.y != 0;
        }
        static StackObject *Clamp_16(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Vector3Int @max = (UnityEngine.Vector3Int) typeof(UnityEngine.Vector3Int).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            UnityEngine.Vector3Int @min = (UnityEngine.Vector3Int) typeof(UnityEngine.Vector3Int).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.Vector3Int instance_of_this_method;
            instance_of_this_method = (UnityEngine.Vector3Int) typeof(UnityEngine.Vector3Int).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            instance_of_this_method.Clamp(@min, @max);

            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            return(__ret);
        }
Beispiel #7
0
 public virtual void Reset()
 {
     ResetSkills();
     m_AnimationDelta     = UnityEngine.Vector3Int.zero;
     m_AnimationDirection = Directions.North;
     m_AnimationEnd       = 0;
     m_AnimationSpeed     = UnityEngine.Vector3Int.zero;
     m_Brightness         = 0;
     m_Direction          = Directions.North;
     m_ID              = 0;
     m_Trapper         = false;
     m_Unpassable      = false;
     m_KnownSince      = -1;
     m_LightColor      = UnityEngine.Color.black;
     m_MovementEnd     = 0;
     m_MovementRunning = false;
     Name              = null;
     m_PartyFlag       = PartyFlags.None;
     m_PKFlag          = PKFlags.Revenge;
     m_Type            = CreatureTypes.Monster;
     m_Visible         = false;
     m_GuildFlag       = GuildFlags.None;
     m_Marks.Clear();
     m_MountOutfit = null;
     m_Outfit      = null;
     m_Position    = UnityEngine.Vector3Int.zero;
 }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        public static UnityEngine.Vector3Int RotateBySector(this UnityEngine.Vector3Int vecUp, FLOAT3 dir)
        {
            var p = vecUp;
            var x = Mathf.Abs(dir.x);
            var z = Mathf.Abs(dir.z);

            if (dir.x >= 0f &&
                x >= z)
            {
                // right
                vecUp = vecUp.Rotate90();
            }
            else if (dir.z >= 0f &&
                     z >= x)
            {
                // up
            }
            else if (dir.z <= 0f &&
                     z >= x)
            {
                // down
                vecUp = vecUp.Rotate90();
                vecUp = vecUp.Rotate90();
            }
            else if (dir.x <= 0f &&
                     x >= z)
            {
                // left
                vecUp = vecUp.Rotate90();
                vecUp = vecUp.Rotate90();
                vecUp = vecUp.Rotate90();
            }

            return(vecUp);
        }
Beispiel #10
0
        public static UnityEngine.Vector3Int Rotate(this UnityEngine.Vector3Int vec, int sector)
        {
            var v = (UnityEngine.Vector2)vec.XZ();

            v = v.Rotate(sector * 90f);
            return(new UnityEngine.Vector3Int((int)v.x, vec.y, (int)v.y));
        }
        private static void SaveHomes()
        {
            Log.Write("Saving homes...");
            string jsonFilePath = "./gamedata/savegames/" + ServerManager.WorldName + "/homes.json";

            if (File.Exists(jsonFilePath))
            {
                File.Delete(jsonFilePath);
            }

            JSONNode homesJSON = new JSONNode(NodeType.Array);

            foreach (var key in homes.Keys)
            {
                JSONNode playerJSON      = new JSONNode();
                JSONNode playerHomesJSON = new JSONNode(NodeType.Array);

                foreach (var n in homes[key].Keys)
                {
                    UnityEngine.Vector3Int v = homes[key][n];
                    JSONNode homeEntryJSON   = new JSONNode().SetAs("x", v.x).SetAs("y", v.y).SetAs("z", v.z).SetAs("n", n);
                    playerHomesJSON.AddToArray(homeEntryJSON);
                }

                playerJSON.SetAs("i", key.ToString());
                playerJSON.SetAs("h", playerHomesJSON);

                homesJSON.AddToArray(playerJSON);
            }

            JSON.Serialize(jsonFilePath, homesJSON);
            Log.Write("Saved homes.");
        }
Beispiel #12
0
        private int ReadField(InputMessage message, int x, int y, int z)
        {
            UnityEngine.Vector3Int position = new UnityEngine.Vector3Int()
            {
                x = x,
                y = y,
                z = z
            };

            UnityEngine.Vector3Int absolutePosition = m_WorldMapStorage.ToAbsolute(position);

            int  typeOrId;
            int  stackPos = 0;
            bool effect   = false;

            while (true)
            {
                typeOrId = message.GetU16();
                if (typeOrId >= 65280)
                {
                    break;
                }

                if (!effect)
                {
                    ObjectInstance tmpInstance = m_AppearanceStorage.CreateEnvironmentalEffect((uint)typeOrId);
                    m_WorldMapStorage.SetEnvironmentalEffect(position, tmpInstance);
                    effect = true;
                    continue;
                }

                if (typeOrId == AppearanceInstance.UnknownCreature || typeOrId == AppearanceInstance.OutdatedCreature ||
                    typeOrId == AppearanceInstance.Creature)
                {
                    Creatures.Creature creature = ReadCreatureInstance(message, typeOrId, absolutePosition);

                    ObjectInstance tmpInstance = m_AppearanceStorage.CreateObjectInstance(AppearanceInstance.Creature, creature.ID);
                    if (stackPos < Constants.MapSizeW)
                    {
                        m_WorldMapStorage.AppendObject(position, tmpInstance);
                    }
                }
                else
                {
                    ObjectInstance tmpInstance = ReadObjectInstance(message, typeOrId);
                    if (stackPos < Constants.MapSizeW)
                    {
                        m_WorldMapStorage.AppendObject(position, tmpInstance);
                    }
                    else
                    {
                        throw new System.Exception("ProtocolGameUtility.ReadField: Expected creatures but received regular object.");
                    }
                }

                stackPos++;
            }

            return(typeOrId - 65280);
        }
Beispiel #13
0
        private void createBlocks(UnityEngine.Vector3Int numBlocks, UnityEngine.Vector3Int startPositions = default)
        {
            var    _         = _context.gameSetup.value;
            Random random    = new Random();
            var    materials = new[] { _.Brown, _.Green, _.Grey };
            int    length    = materials.Length;

            for (int x = startPositions.x; x < numBlocks.x + startPositions.x; x++)
            {
                for (int y = startPositions.y; y < numBlocks.y + startPositions.y; y++)
                {
                    for (int z = startPositions.z; z < numBlocks.z + startPositions.z; z++)
                    {
                        var block = _context.CreateEntity();
                        block.AddResource(_.BlankBlock, materials[random.Next(length)]);
                        block.AddName(block.resource.Material.name);
                        block.AddGameObjectType(GameObjectType.Static);
                        block.AddPosition(new UnityEngine.Vector3(x, y, z));
                        block.AddSize(new UnityEngine.Vector3(1, 1, 1));
                        block.AddStackSize(64);
                        //block.AddRotate(180f, new UnityEngine.Vector3(random.Next(2), random.Next(2), random.Next(2)));
                    }
                }
            }
        }
Beispiel #14
0
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 4 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
                {
                    int _x = LuaAPI.xlua_tointeger(L, 2);
                    int _y = LuaAPI.xlua_tointeger(L, 3);
                    int _z = LuaAPI.xlua_tointeger(L, 4);

                    var gen_ret = new UnityEngine.Vector3Int(_x, _y, _z);
                    translator.Push(L, gen_ret);

                    return(1);
                }

                if (LuaAPI.lua_gettop(L) == 1)
                {
                    translator.Push(L, default(UnityEngine.Vector3Int));
                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Vector3Int constructor!"));
        }
Beispiel #15
0
    public void ReplaceCell(UnityEngine.Vector3Int newPosition)
    {
        var index     = GameComponentsLookup.Cell;
        var component = CreateComponent <GameScene.ECS.Components.CellComponent>(index);

        component.Position = newPosition;
        ReplaceComponent(index, component);
    }
Beispiel #16
0
        private static UnityEngine.Vector3Int Rotate90(this UnityEngine.Vector3Int vec)
        {
            var p = vec;

            vec.x = p.z;
            vec.z = -p.x;
            return(vec);
        }
Beispiel #17
0
        public void SendBrowseField(UnityEngine.Vector3Int absolute)
        {
            var message = _packetWriter.CreateMessage();

            message.WriteEnum(GameclientMessageType.BrowseField);
            message.WritePosition(absolute);
            _packetWriter.FinishMessage();
        }
    public void ReplacePosition(UnityEngine.Vector3Int newPos)
    {
        var index     = GameComponentsLookup.Position;
        var component = (PositionComponent)CreateComponent(index, typeof(PositionComponent));

        component.Pos = newPos;
        ReplaceComponent(index, component);
    }
Beispiel #19
0
 public void StopMovementAnimation()
 {
     m_AnimationDirection = m_Direction;
     m_AnimationDelta     = UnityEngine.Vector3Int.zero;
     m_AnimationSpeed     = UnityEngine.Vector3Int.zero;
     m_AnimationEnd       = 0;
     m_MovementEnd        = 0;
     m_MovementRunning    = false;
 }
    public SerializedGrid(TileDataController gridSystem)
    {
        serializedTilemap = gridSystem.SerializedTilemap();

        UnityEngine.Vector3Int TilemapDimensions = gridSystem.GetReserveDimensions();

        width  = TilemapDimensions.x;
        height = TilemapDimensions.y;
    }
    public GameEntity AddCurrentPosition(UnityEngine.Vector3Int newValue)
    {
        var index     = GameComponentsLookup.CurrentPosition;
        var component = (Components.CurrentPosition)CreateComponent(index, typeof(Components.CurrentPosition));

        component.value = newValue;
        AddComponent(index, component);
        return(this);
    }
Beispiel #22
0
        public void StartAutowalk(int targetX, int targetY, int targetZ, bool diagonal, bool exact)
        {
            if (targetX == m_AutowalkTarget.x && targetY == m_AutowalkTarget.y && targetZ == m_AutowalkTarget.z)
            {
                return;
            }

            if (targetX == m_Position.x + 2 * m_AutowalkPathDelta.x &&
                targetY == m_Position.y + 2 * m_AutowalkPathDelta.y &&
                targetZ == m_Position.z + 2 * m_AutowalkPathDelta.z)
            {
                return;
            }

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

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

            m_AutowalkTarget.Set(-1, -1, -1);
            m_AutowalkTargetDiagonal = false;
            m_AutowalkTargetExact    = false;

            // check if the tile can actually be entered (before proceeding with anything)
            // the tile must be visible, otherwise it would then be checked in the pathfinder
            if (worldMapStorage.IsVisible(targetX, targetY, targetZ, true))
            {
                UnityEngine.Vector3Int s_v1 = new UnityEngine.Vector3Int(targetX, targetY, targetZ);
                worldMapStorage.ToMap(s_v1, out s_v1);
                if ((s_v1.x != Constants.PlayerOffsetX || s_v1.y != Constants.PlayerOffsetY) && worldMapStorage.GetEnterPossibleFlag(s_v1.x, s_v1.y, s_v1.z, true) == Constants.FieldEnterNotPossible)
                {
                    worldMapStorage.AddOnscreenMessage(MessageModes.Failure, TextResources.MSG_SORRY_NOT_POSSIBLE);
                    return;
                }
            }

            m_AutowalkTarget.Set(targetX, targetY, targetZ);
            m_AutowalkTargetDiagonal = diagonal;
            m_AutowalkTargetExact    = exact;
            if (m_AutowalkPathAborting || m_AutowalkPathSteps.Count == 1)
            {
                return;
            }

            if (m_AutowalkPathSteps.Count == 0)
            {
                StartAutowalkInternal();
            }
            else
            {
                protocolGame.SendStop();
                m_AutowalkPathAborting = true;
            }
        }
Beispiel #23
0
    public GameEntity ReplaceCell(UnityEngine.Vector3Int newValue)
    {
        var index     = GameComponentsLookup.Cell;
        var component = (Components.Cell)CreateComponent(index, typeof(Components.Cell));

        component.Value = newValue;
        ReplaceComponent(index, component);
        return(this);
    }
Beispiel #24
0
    public GameEntity ReplacePreviousPosition(UnityEngine.Vector3Int newValue)
    {
        var index     = GameComponentsLookup.PreviousPosition;
        var component = (Components.PreviousPosition)CreateComponent(index, typeof(Components.PreviousPosition));

        component.value = newValue;
        ReplaceComponent(index, component);
        return(this);
    }
Beispiel #25
0
        public UnityEngine.Vector3Int ToMapClosest(UnityEngine.Vector3Int absolutePosition)
        {
            int dZ = _position.z - absolutePosition.z;
            int x  = UnityEngine.Mathf.Max(0, UnityEngine.Mathf.Min(absolutePosition.x - (_position.x - Constants.PlayerOffsetX) - dZ, Constants.MapSizeX - 1));
            int y  = UnityEngine.Mathf.Max(0, UnityEngine.Mathf.Min(absolutePosition.y - (_position.y - Constants.PlayerOffsetY) - dZ, Constants.MapSizeY - 1));
            int z  = UnityEngine.Mathf.Max(0, UnityEngine.Mathf.Min(PlayerZPlane + dZ, Constants.MapSizeZ - 1));

            return(new UnityEngine.Vector3Int(x, y, z));
        }
Beispiel #26
0
        public void SendLook(UnityEngine.Vector3Int position, uint typeID, int stackPosition)
        {
            OutputMessage message = new OutputMessage();

            message.AddU8(ClientServerOpCodes.Look);
            message.AddPosition(position);
            message.AddU16((ushort)typeID);
            message.AddU8((byte)stackPosition);
            WriteToOutput(message);
        }
Beispiel #27
0
        public void SendLook(UnityEngine.Vector3Int absolute, uint typeId, int stackPos)
        {
            var message = _packetWriter.CreateMessage();

            message.WriteEnum(GameclientMessageType.Look);
            message.WritePosition(absolute);
            message.WriteUnsignedShort((ushort)typeId);
            message.WriteUnsignedByte((byte)stackPos);
            _packetWriter.FinishMessage();
        }
Beispiel #28
0
        internal void SendTurnObject(UnityEngine.Vector3Int absolute, uint typeID, int stackPos)
        {
            var message = m_PacketWriter.CreateMessage();

            message.WriteEnum(GameclientMessageType.TurnObject);
            message.WritePosition(absolute);
            message.WriteUnsignedShort((ushort)typeID);
            message.WriteUnsignedByte((byte)stackPos);
            m_PacketWriter.FinishMessage();
        }
Beispiel #29
0
        public UnityEngine.Vector3Int ToMap(UnityEngine.Vector3Int absolutePosition)
        {
            UnityEngine.Vector3Int?mapPosition = ToMapInternal(absolutePosition);
            if (mapPosition == null)
            {
                throw new System.ArgumentException("WorldMapStorage.ToMap: Input co-ordinate " + absolutePosition + " is out of range (m=" + _position + ").");
            }

            return(mapPosition.Value);
        }
Beispiel #30
0
        private int ReadField(Internal.ByteArray message, int x, int y, int z)
        {
            var mapPosition      = new UnityEngine.Vector3Int(x, y, z);
            var absolutePosition = WorldMapStorage.ToAbsolute(mapPosition);

            int  typeOrId;
            int  stackPos  = 0;
            bool gotEffect = false;

            while (true)
            {
                typeOrId = message.ReadUnsignedShort();
                if (typeOrId >= 65280)
                {
                    break;
                }

                if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameEnvironmentEffect) && !gotEffect)
                {
                    var effectObject = AppearanceStorage.CreateEnvironmentalEffect((uint)typeOrId);
                    WorldMapStorage.SetEnvironmentalEffect(mapPosition, effectObject);
                    gotEffect = true;
                    continue;
                }

                if (typeOrId == AppearanceInstance.UnknownCreature || typeOrId == AppearanceInstance.OutdatedCreature ||
                    typeOrId == AppearanceInstance.Creature)
                {
                    var creature = ReadCreatureInstance(message, typeOrId, absolutePosition);

                    var @object = AppearanceStorage.CreateObjectInstance(AppearanceInstance.Creature, creature.ID);
                    if (stackPos < Constants.MapSizeW)
                    {
                        WorldMapStorage.AppendObject(mapPosition, @object);
                    }
                }
                else
                {
                    var @object = ReadObjectInstance(message, typeOrId);
                    if (stackPos < Constants.MapSizeW)
                    {
                        WorldMapStorage.AppendObject(mapPosition, @object);
                    }
                    else
                    {
                        throw new System.Exception("ProtocolGameUtility.ReadField: Expected creatures but received regular object.");
                    }
                }

                stackPos++;
            }

            return(typeOrId - 65280);
        }