예제 #1
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!");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Returns a generate global id.
        /// </summary>
        /// <param name="GameObject"></param>
        /// <returns></returns>
        internal int GenerateGameObjectGlobalId(GameObject GameObject)
        {
            if (GameObject.Type < 13)
            {
                return((500 + GameObject.Type) * 1000000 + this.GameObjects[GameObject.Type].Count);
            }

            Logging.Error(this.GetType(), "GenerateGameObjectGlobalID() : Index is out of bounds.");

            return(0);
        }
예제 #3
0
        /// <summary>
        /// To call after initialization or after deserialization.
        /// </summary>
        internal void LoadingFinished()
        {
            foreach (GameObject GameObject in this.GameObjects[0])
            {
                GameObject.LoadingFinished();
            }

            foreach (GameObject GameObject in this.GameObjects[4])
            {
                GameObject.LoadingFinished();
            }

            foreach (GameObject GameObject in this.GameObjects[10])
            {
                GameObject.LoadingFinished();
            }
        }
예제 #4
0
        /// <summary>
        /// Removes the specified gameObject to the array.
        /// </summary>
        /// <param name="GameObject">The gameObject.</param>
        internal void RemoveGameObject(GameObject gameObject)
        {
            if (this.GameObjects[gameObject.Type].Remove(gameObject))
            {
                if (this.TownHall == gameObject)
                {
                    this.TownHall = null;
                }

                if (this.MapRoom == gameObject)
                {
                    this.MapRoom = null;
                }

                if (this.Laboratory == gameObject)
                {
                    this.Laboratory = null;
                }

                if (this.ArtifactProduction == gameObject)
                {
                    this.ArtifactProduction = null;
                }

                if (this.ArtifactStorage == gameObject)
                {
                    this.ArtifactStorage = null;
                }

                if (this.Deepsea == gameObject)
                {
                    this.Deepsea = null;
                }

                if (this.GunBoat == gameObject)
                {
                    this.GunBoat = null;
                }

                if (this.HeroBoat == gameObject)
                {
                    this.HeroBoat = null;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Adds gameObject in list.
        /// </summary>
        /// <param name="GameObject">The gameObject.</param>
        internal void AddGameObject(GameObject GameObject)
        {
            if (GameObject.Type > 0)
            {
                if (GameObject.Type == 1)
                {
                    CharacterData Character = (CharacterData)GameObject.Data;

                    if (Character.IsHero())
                    {
                        if (this.DeployedHero != null)
                        {
                            Logging.Error(this.GetType(), "AddGameObject() - Added another hero! There can be only one!");
                        }

                        this.DeployedHero = GameObject;
                    }
                }
                else if (GameObject.Type == 9)
                {
                    this.ResourceShips.Add(GameObject);
                }
            }
            else
            {
                Building Building = (Building)GameObject;

                if (Building.BuildingData.IsTownHallOrCommandCenter())
                {
                    this.TownHall = Building;
                }

                if (Building.BuildingData.IsMapRoom())
                {
                    this.MapRoom = Building;
                }

                if (Building.BuildingData.UpgradesUnits)
                {
                    if (!Building.BuildingData.IsHeroBoat)
                    {
                        this.Laboratory = Building;
                    }
                }

                if (Building.BuildingData.CreatesArtifacts)
                {
                    this.ArtifactProduction = Building;
                }

                if (Building.BuildingData.StoresArtifactes())
                {
                    this.ArtifactStorage = Building;
                }

                if (Building.BuildingData.IsDeepsea())
                {
                    this.Deepsea = Building;
                }

                if (Building.BuildingData.IsGunBoat())
                {
                    this.GunBoat = Building;
                }

                if (Building.BuildingData.IsHeroBoat)
                {
                    this.HeroBoat = Building;
                }
            }

            this.GameObjects[GameObject.Type].Add(GameObject);
        }
예제 #6
0
        /// <summary>
        /// Saves this instance to JSON.
        /// </summary>
        /// <param name="Json">The Json object.</param>
        internal void Save(JObject Json)
        {
            JArray Buildings = new JArray();

            foreach (Building GameObject in this.GameObjects[0])
            {
                JObject Item = new JObject();

                Item.Add("data", GameObject.Data.GlobalID);
                GameObject.Save(Item);

                Buildings.Add(Item);
            }

            Json.Add("buildings", Buildings);

            JArray Obstacles = new JArray();

            foreach (GameObject GameObject in this.GameObjects[3])
            {
                if (!GameObject.ShouldDestruct)
                {
                    JObject Item = new JObject();

                    Item.Add("data", GameObject.Data.GlobalID);
                    GameObject.Save(Item);

                    Obstacles.Add(Item);
                }
            }

            Json.Add("obstacles", Obstacles);

            JArray Traps = new JArray();

            foreach (GameObject GameObject in this.GameObjects[4])
            {
                JObject Item = new JObject();

                Item.Add("data", GameObject.Data.GlobalID);
                GameObject.Save(Item);

                Traps.Add(Item);
            }

            Json.Add("traps", Traps);


            JArray Decos = new JArray();

            foreach (GameObject GameObject in this.GameObjects[6])
            {
                JObject Item = new JObject();

                Item.Add("data", GameObject.Data.GlobalID);
                GameObject.Save(Item);

                Decos.Add(Item);
            }

            Json.Add("decos", Decos);

            JArray ResourceShips = new JArray();

            foreach (GameObject GameObject in this.GameObjects[9])
            {
                JObject Item = new JObject();

                Item.Add("data", GameObject.Data.GlobalID);
                GameObject.Save(Item);

                ResourceShips.Add(Item);
            }

            Json.Add("resource_ships", ResourceShips);
        }