/// <summary>
        /// Loads gameobject from json.
        /// </summary>
        internal void LoadGameObject(JToken Token, int Map)
        {
            if (JsonHelper.GetJsonNumber(Token, "data", out int DataID))
            {
                Data Data = CSV.Tables.GetWithGlobalID(DataID);

                if (Data == null)
                {
                    Logging.Error(this.GetType(), "An error has been throwed when the load of GameObject. data is not valid.");
                    return;
                }

                GameObject GameObject = GameObjectFactory.CreateGameObject(Data, this.Level);

                if (GameObject != null)
                {
                    GameObject.Load(Token);
                    this.AddGameObject(GameObject, Map);
                }
            }
            else
            {
                Logging.Error(this.GetType(), "An error has been throwed when the load of GameObject. data not exist.");
            }
        }
        /// <summary>
        /// Randomly place the obstacle.
        /// </summary>
        internal void RandomlyPlaceObstacle(ObstacleData Data)
        {
            if (Data.VillageType == this.Map)
            {
                int WidthInTiles  = this.Level.WidthInTiles;
                int HeightInTiles = this.Level.HeightInTiles;

                for (int i = 0; i <= 20; i++)
                {
                    int X = this.Random.Rand(WidthInTiles + 1 - Data.Width);
                    int Y = this.Random.Rand(HeightInTiles + 1 - Data.Height);

                    if (this.Level.IsValidPlaceForObstacle(Data, X, Y, Data.Width, Data.Height, true))
                    {
                        Obstacle Obstacle = (Obstacle)GameObjectFactory.CreateGameObject(Data, this.Level);
                        Obstacle.SetPositionXY(X, Y);
                        this.AddGameObject(Obstacle, this.Map);

                        Logging.Info(this.GetType(), "X:" + X + "   Y:" + Y);

                        break;
                    }
                }
            }
            else
            {
                Logging.Error(this.GetType(), "RandomlyPlaceObstacle() - Trying to place obstacle in wrong village");
            }
        }
示例#3
0
        /// <summary>
        /// Loads gameObjects from Json array (<see cref="JArray"/>).
        /// </summary>
        /// <param name="Array">The Json array.</param>
        internal void LoadGameObjectsFromJsonArray(JArray Array)
        {
            foreach (JToken Token in Array)
            {
                if (JsonHelper.GetInt(Token["data"], out int Id))
                {
                    Data Data = CSV.Tables.GetDataById(Id);

                    if (Data != null)
                    {
                        GameObject GameObject = GameObjectFactory.CreateGameObject(Data, this.Home);

                        if (GameObject != null)
                        {
                            GameObject.Load(Token);
                            this.AddGameObject(GameObject);
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "Load - Data is NULL for Global ID:" + Id);
                    }
                }
                else
                {
                    Logging.Error(this.GetType(), "Load - Data id was not found!");
                }
            }
        }
示例#4
0
    public GameObjectResource get()
    {
        if (idle.Count <= 0)
        {
            GameObject g = gameObjectFactory.CreateGameObject();
            add(g);
        }
        GameObjectResource r = idle.First().Value;

        r.getGameObject().SetActive(true);
        used.Add(r.getId(), r);
        idle.Remove(r.getId());
        return(r);
    }
示例#5
0
        public void PutGameObject(NwWalkerGameObject go, bool sync)
        {
            MMW.Invoke(() =>
            {
                try
                {
                    var wo = Resources.Objects[go.ObjectHash];
                    if (!wo.Loaded)
                    {
                        wo.Load();
                    }

                    var g  = GameObjectFactory.CreateGameObject(go, wo, wo.Name, wo.Bones != null ? "Deferred Physical Skin" : "Deferred Physical");
                    g.Hash = go.Hash;
                    g.Transform.Position = go.Position.FromVec3f();
                    g.Transform.Rotate   = go.Rotation.FromVec3f();
                    if (go.Scale != null)
                    {
                        g.Transform.Scale = go.Scale.FromVec3f();
                    }
                    g.Transform.UpdatePhysicalTransform();

                    MMW.RegistGameObject(g);
                    if (sync)
                    {
                        SyncWorldObjects.Add(g);
                    }
                    else
                    {
                        WorldObjects.Add(g);
                    }
                }
                catch
                {
                    MMW.BroadcastMessage("log", $"[ERROR] object \"{go.Name}\" entry failed");
                }
            });
        }