Esempio n. 1
0
        public bool ApplyMove(GameObject gameObject, Vector2Int dest, bool checkObjects = true, bool collision = true)
        {
            if (gameObject.Room == null)
            {
                return(false);
            }

            if (gameObject.Room.Map != this)
            {
                return(false);
            }


            PositionInfo posInfo = gameObject.PosInfo;

            if (CanGo(dest, checkObjects) == false)
            {
                return(false);
            }

            if (collision)
            {
                {
                    int x = posInfo.PosX - MinX;
                    int y = MaxY - posInfo.PosY;

                    if (_objects[y, x] == gameObject)
                    {
                        _objects[y, x] = null;
                    }
                }
                {
                    int x = dest.x - MinX;
                    int y = MaxY - dest.y;
                    _objects[y, x] = gameObject;
                }
            }

            // Zone
            GameObjectType type = ObjectManager.GetObjectTypeById(gameObject.Id);

            if (type == GameObjectType.Player)
            {
                Player player = (Player)gameObject;

                Zone now   = gameObject.Room.GetZone(gameObject.CellPos);
                Zone after = gameObject.Room.GetZone(dest);

                if (now != after)
                {
                    now.Players.Remove(player);
                    after.Players.Add(player);
                }
            }
            else if (type == GameObjectType.Monster)
            {
                Monster monster = (Monster)gameObject;

                Zone now   = gameObject.Room.GetZone(gameObject.CellPos);
                Zone after = gameObject.Room.GetZone(dest);

                if (now != after)
                {
                    now.Monsters.Remove(monster);
                    after.Monsters.Add(monster);
                }
            }
            else if (type == GameObjectType.Projectile)
            {
                Projectile projectile = (Projectile)gameObject;

                Zone now   = gameObject.Room.GetZone(gameObject.CellPos);
                Zone after = gameObject.Room.GetZone(dest);

                if (now != after)
                {
                    now.Projectiles.Remove(projectile);
                    after.Projectiles.Add(projectile);
                }
            }



            // 실제 좌표 이동
            posInfo.PosX = dest.x;
            posInfo.PosY = dest.y;

            return(true);
        }