Ejemplo n.º 1
0
        internal override void Execute()
        {
            GameObject GameObject = this.Device.GameMode.Level.GameObjectManager.Filter.GetGameObjectById(this.BuildingId);

            if (GameObject != null)
            {
                if (GameObject is Building)
                {
                    Building Building = (Building)GameObject;
                    Building.SpeedUpConstruction();
                }
                else if (GameObject is Trap)
                {
                    Trap Trap = (Trap)GameObject;
                    Trap.SpeedUpConstruction();
                }
                else if (GameObject is VillageObject)
                {
                    VillageObject VillageObject = (VillageObject)GameObject;
                    VillageObject.SpeedUpConstruction();
                }
                else
                {
                    Logging.Error(this.GetType(), "Unable to speed up the construction. GameObject Type : " + GameObject.Type + ".");
                }
            }
            else
            {
                Logging.Error(this.GetType(), "Unable to speed up the construction. The game object doesn't exist.");
            }
        }
        /// <summary>
        /// Start construction of the <see cref="VillageObject"/>.
        /// </summary>
        /// <returns>True if success.</returns>
        internal static bool Construct(this VillageObject Building)
        {
            if (!Building.ConstructionTime.HasValue)
            {
                if (Building.Csv.BuildCost.Count > Building.Level + 1)
                {
                    if (Building.Objects.Buildings.Townhall.Level + 1 >= Building.Csv.TownHallLevel[Building.Level + 1])
                    {
                        int Resource = CSV.Tables.Get(Gamefile.Resources).GetData(Building.Csv.BuildResource).GlobalID;

                        if (Building.Objects.Player.Resources.Minus(Resource, Building.Csv.BuildCost[Building.Level + 1]))
                        {
                            Building.ConstructionTime = (int)new TimeSpan(Building.Csv.BuildTimeD[Building.Level + 1], Building.Csv.BuildTimeH[Building.Level + 1], Building.Csv.BuildTimeD[Building.Level + 1], Building.Csv.BuildTimeS[Building.Level + 1]).TotalSeconds;

                            if (Building.ConstructionTime <= 0f)
                            {
                                Building.ConstructionEnded();
                                Building.ConstructionTime = null;
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Invoked when the construction is ended.
        /// </summary>
        internal static void ConstructionEnded(this VillageObject Building)
        {
            if (Building.ConstructionTime.HasValue && Building.ConstructionTime <= 0f)
            {
                Building.Level++;

                int TotalTime = (int)new TimeSpan(Building.Csv.BuildTimeD[Building.Level], Building.Csv.BuildTimeH[Building.Level], Building.Csv.BuildTimeM[Building.Level], Building.Csv.BuildTimeS[Building.Level]).TotalSeconds;

                Building.Objects.Player.AddExperience((int)Math.Sqrt(TotalTime));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Clears all gameobjects and loads the objects from the JSON given
        /// </summary>
        /// <param name="json"></param>
        public void LoadJson(string json)
        {
            Home.ComponentManager.Clear();

            var j = JObject.Parse(json);

            if (j.ContainsKey("exp_ver"))
            {
                _expVersion = j["exp_ver"].ToObject <int>();
            }

            if (j.ContainsKey("last_news_seen"))
            {
                LastNewsSeen = j["last_news_seen"].ToObject <int>();
            }

            if (j.ContainsKey("buildings"))
            {
                Buildings.Clear();
                foreach (var jToken in j["buildings"])
                {
                    var obj = (JObject)jToken;

                    var building = new Building(Home)
                    {
                        Id = 500000000 + Buildings.Count
                    };

                    building.Load(obj);
                    Buildings.Add(building);
                }
            }

            if (j.ContainsKey("obstacles"))
            {
                Obstacles.Clear();
                foreach (var jToken in j["obstacles"])
                {
                    var obj      = (JObject)jToken;
                    var obstacle = new Obstacle(Home)
                    {
                        Id = 503000000 + Obstacles.Count
                    };

                    obstacle.Load(obj);
                    Obstacles.Add(obstacle);
                }
            }

            if (j.ContainsKey("decos"))
            {
                Decos.Clear();
                foreach (var jToken in j["decos"])
                {
                    var obj  = (JObject)jToken;
                    var deco = new Deco(Home)
                    {
                        Id = 506000000 + Decos.Count
                    };

                    deco.Load(obj);
                    Decos.Add(deco);
                }
            }

            if (j.ContainsKey("traps"))
            {
                Traps.Clear();
                foreach (var jToken in j["traps"])
                {
                    var obj  = (JObject)jToken;
                    var trap = new Trap(Home)
                    {
                        Id = 504000000 + Traps.Count
                    };

                    trap.Load(obj);
                    Traps.Add(trap);
                }
            }

            if (j.ContainsKey("vobjs"))
            {
                VillageObjects.Clear();
                foreach (var jToken in j["vobjs"])
                {
                    var obj           = (JObject)jToken;
                    var villageObject = new VillageObject(Home)
                    {
                        Id = 508000000 + VillageObjects.Count
                    };

                    villageObject.Load(obj);
                    VillageObjects.Add(villageObject);
                }
            }

            if (j.ContainsKey("buildings2"))
            {
                Buildings2.Clear();
                foreach (var jToken in j["buildings2"])
                {
                    var obj       = (JObject)jToken;
                    var building2 = new Building(Home)
                    {
                        Id = 500000000 + Buildings2.Count
                    };

                    building2.Load(obj);
                    Buildings2.Add(building2);
                }
            }

            if (j.ContainsKey("obstacles2"))
            {
                Obstacles2.Clear();
                foreach (var jToken in j["obstacles2"])
                {
                    var obj      = (JObject)jToken;
                    var obstacle = new Obstacle(Home)
                    {
                        Id = 503000000 + Obstacles2.Count
                    };

                    obstacle.Load(obj);
                    Obstacles2.Add(obstacle);
                }
            }

            if (j.ContainsKey("decos2"))
            {
                Decos2.Clear();
                foreach (var jToken in j["decos2"])
                {
                    var obj  = (JObject)jToken;
                    var deco = new Deco(Home)
                    {
                        Id = 506000000 + Decos2.Count
                    };

                    deco.Load(obj);
                    Decos2.Add(deco);
                }
            }

            if (j.ContainsKey("traps2"))
            {
                Traps2.Clear();
                foreach (var jToken in j["traps2"])
                {
                    var obj  = (JObject)jToken;
                    var trap = new Trap(Home)
                    {
                        Id = 504000000 + Traps2.Count
                    };

                    trap.Load(obj);
                    Traps2.Add(trap);
                }
            }

            if (j.ContainsKey("vobjs2"))
            {
                VillageObjects2.Clear();
                foreach (var jToken in j["vobjs2"])
                {
                    var obj           = (JObject)jToken;
                    var villageObject = new VillageObject(Home)
                    {
                        Id = 508000000 + VillageObjects2.Count
                    };

                    villageObject.Load(obj);
                    VillageObjects2.Add(villageObject);
                }
            }
        }
Ejemplo n.º 5
0
        internal override void Execute()
        {
            Level      Level      = this.Device.GameMode.Level;
            GameObject GameObject = Level.GameObjectManager.Filter.GetGameObjectById(this.Id);

            if (GameObject != null)
            {
                if (GameObject is Building)
                {
                    Building Building = (Building)GameObject;
                    if (Building.UpgradeAvailable)
                    {
                        BuildingData Data         = (BuildingData)Building.Data;
                        ResourceData ResourceData = this.UseAltResource ? Data.AltBuildResourceData(Building.GetUpgradeLevel() + 1) : Data.BuildResourceData;

                        if (ResourceData != null)
                        {
                            if (Level.Player.Resources.GetCountByData(ResourceData) >= Data.BuildCost[Building.GetUpgradeLevel() + 1])
                            {
                                if (Data.VillageType == 0 ? Level.WorkerManager.FreeWorkers > 0 : Level.WorkerManagerV2.FreeWorkers > 0)
                                {
                                    Level.Player.Resources.Remove(ResourceData, Data.BuildCost[Building.GetUpgradeLevel() + 1]);
                                    Building.StartUpgrade();

                                    if (Data.IsTownHall2)
                                    {
                                        if (Level.Player.TownHallLevel2 == 0)
                                        {
                                            foreach (var gameObject in Level.GameObjectManager.GameObjects[0][1])
                                            {
                                                Building     building2 = (Building)gameObject;
                                                BuildingData data2     = building2.BuildingData;
                                                if (building2.Locked)
                                                {
                                                    if (!data2.Locked)
                                                    {
#if DEBUG
                                                        Logging.Info(this.GetType(), $"Builder Building: Unlocking {data2.Name} with ID {gameObject.Id}");
#endif
                                                        building2.Locked = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Logging.Error(this.GetType(), "Unable to upgrade the building. The player doesn't have enough resources.");
                            }
                        }
                        else
                        {
                            Logging.Error(this.GetType(), "Unable to upgrade the building. The resource data is null");
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "Unable to upgrade the building. Upgrade is not available.");
                    }
                }
                else if (GameObject is Trap)
                {
                    Trap Trap = (Trap)GameObject;
                    if (Trap.UpgradeAvailable)
                    {
                        TrapData     Data         = Trap.TrapData;
                        ResourceData ResourceData = Data.BuildResourceData;

                        if (ResourceData != null)
                        {
                            if (Level.Player.Resources.GetCountByData(ResourceData) >= Data.BuildCost[Trap.GetUpgradeLevel() + 1])
                            {
                                if (Data.VillageType == 0 ? Level.WorkerManager.FreeWorkers > 0 : Level.WorkerManagerV2.FreeWorkers > 0)
                                {
                                    Level.Player.Resources.Remove(ResourceData, Data.BuildCost[Trap.GetUpgradeLevel() + 1]);
                                    Trap.StartUpgrade();
                                }
                            }
                            else
                            {
                                Logging.Error(this.GetType(), "Unable to upgrade the Trap. The player doesn't have enough resources.");
                            }
                        }
                        else
                        {
                            Logging.Error(this.GetType(), "Unable to start upgrade the Trap. The resources data is null.");
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "Unable to upgrade the building. Upgrade is not available.");
                    }
                }
                else if (GameObject is VillageObject)
                {
                    VillageObject     VillageObject = (VillageObject)GameObject;
                    VillageObjectData Data          = VillageObject.VillageObjectData;
                    ResourceData      ResourceData  = Data.BuildResourceData;

                    if (ResourceData != null)
                    {
                        if (Level.Player.Resources.GetCountByData(ResourceData) >= Data.BuildCost[VillageObject.GetUpgradeLevel() + 1])
                        {
                            if (Data.VillageType == 0 ? Level.WorkerManager.FreeWorkers > 0 : Level.WorkerManagerV2.FreeWorkers > 0)
                            {
                                Level.Player.Resources.Remove(ResourceData, Data.BuildCost[VillageObject.GetUpgradeLevel() + 1]);
                                VillageObject.StartUpgrade();
                            }
                        }
                        else
                        {
                            Logging.Error(this.GetType(), "Unable to upgrade the VillageObject. The player doesn't have enough resources.");
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "Unable to start upgrade the VillageObject. The resources data is null.");
                    }
                }
                else
                {
                    Logging.Error(this.GetType(), $"Unable to determined Game Object type. Game Object type {GameObject.Type}.");
                }
            }
            else
            {
                Logging.Error(this.GetType(), "Unable to upgrade the gameObject. GameObject is null");
#if COMMAND_DEBUG
                Device.Account.Player.Debug.Dump();
#endif
            }
        }