internal void CancelConstruction()
        {
            if (this.IsConstructing)
            {
                bool wasUpgrading = IsUpgrading();
                this.IsConstructing = false;
                if (wasUpgrading)
                {
                    SetUpgradeLevel(UpgradeLevel);
                }
                Construction_Item        bd = GetConstructionItemData();
                Files.CSV_Logic.Resource rd = bd.GetBuildResource(UpgradeLevel + 1);
                int cost          = bd.GetBuildCost(UpgradeLevel + 1);
                int multiplier    = (CSV.Tables.Get(Gamefile.Globals).GetData("BUILD_CANCEL_MULTIPLIER") as Globals).NumberValue;
                int resourceCount = (int)((cost * multiplier * (long)1374389535) >> 32);
                resourceCount = Math.Max((resourceCount >> 5) + (resourceCount >> 31), 0);
                this.Level.Avatar.Resources.Plus(rd.GetGlobalID(), resourceCount);

                if (Builder_Village)
                {
                    this.Level.BuilderVillageWorkerManager.DeallocateWorker(this);
                }
                else
                {
                    this.Level.VillageWorkerManager.DeallocateWorker(this);
                }

                if (UpgradeLevel == -1)
                {
                    this.Level.GameObjectManager.RemoveGameObject(this);
                }
            }
        }
        public static bool Mission_Finish(this Player Player, int Global_ID)
        {
            if (Player.Tutorials.FindIndex(M => M == Global_ID) < 0)
            {
                Missions Mission = CSV.Tables.Get(Gamefile.Missions).GetDataWithID(Global_ID) as Missions;

#if DEBUG
                Console.WriteLine($"Mission received {Mission.Name} marked as finished");
#endif
                if (!string.IsNullOrEmpty(Mission.RewardResource))
                {
                    Files.CSV_Logic.Resource CSV_Resources = CSV.Tables.Get(Gamefile.Resources).GetData(Mission.RewardResource) as Files.CSV_Logic.Resource;

                    Player.Resources.Plus(CSV_Resources.GetGlobalID(), Mission.RewardResourceCount);
                }
                if (!string.IsNullOrEmpty(Mission.RewardTroop))
                {
                    Characters CSV_Characters = CSV.Tables.Get(Gamefile.Characters).GetData(Mission.RewardTroop) as Characters;

#if DEBUG
                    Console.WriteLine($"Player received {CSV_Characters.Name} as mission rewards");
#endif
                    Player.Add_Unit(CSV_Characters.GetGlobalID(), Mission.RewardTroopCount);
                }

                if (!string.IsNullOrEmpty(Mission.Dependencies))
                {
                    int DependenciesID = CSV.Tables.Get(Gamefile.Missions).GetData(Mission.Dependencies).GetGlobalID();
                    if (Player.Tutorials.FindIndex(M => M == DependenciesID) < 0)
                    {
#if DEBUG
                        Console.WriteLine($"Mission Dependencies {(CSV.Tables.Get(Gamefile.Missions).GetDataWithID(DependenciesID) as Missions).Name} marked as finished");
#endif
                        Mission_Finish(Player, DependenciesID);
                    }
                }
                Player.Experience += Mission.RewardXP;
                Player.Tutorials.Add(Mission.GetGlobalID());
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        internal override void Process()
        {
            var ca = this.Device.Player.Avatar;
            var go = this.Device.Player.Avatar.Variables.IsBuilderVillage
                ? this.Device.Player.GameObjectManager.GetBuilderVillageGameObjectByID(BuildingId)
                : this.Device.Player.GameObjectManager.GetGameObjectByID(BuildingId);

            if (go != null)
            {
                var b = (ConstructionItem)go;
                if (b.CanUpgrade())
                {
                    if (b.ClassId == 0 || b.ClassId == 7)
                    {
                        var bd = (Buildings)b.GetConstructionItemData();
                        Files.CSV_Logic.Resource rd = IsAltResource
                            ? bd.GetAltBuildResource(b.GetUpgradeLevel() + 1)
                            : bd.GetBuildResource(b.GetUpgradeLevel() + 1);
                        if (ca.HasEnoughResources(rd.GetGlobalID(),
                                                  bd.GetBuildCost(b.GetUpgradeLevel())))
                        {
                            if (this.Device.Player.Avatar.Variables.IsBuilderVillage
                                ? this.Device.Player.HasFreeBuilderVillageWorkers
                                : this.Device.Player.HasFreeVillageWorkers)
                            {
                                var name = go.GetData().Row.Name;
#if DEBUG
                                Loggers.Log(b.ClassId == 0 ? "Building" + $" : Upgrading {name} with ID {BuildingId}" : "Builder Building" + $" : Upgrading {name} with ID {BuildingId}", true);
#endif

                                if (bd.IsTownHall2())
                                {
                                    if (ca.Builder_TownHall_Level == 0)
                                    {
                                        Parallel.ForEach(this.Device.Player.GameObjectManager.GetGameObjects(7),
                                                         Object =>
                                        {
                                            Builder_Building b2 = (Builder_Building)Object;
                                            var bd2             = b2.GetBuildingData;
                                            if (b2.Locked)
                                            {
                                                if (bd2.Locked)
                                                {
                                                    return;
                                                }
#if DEBUG
                                                Loggers.Log(
                                                    $"Builder Building: Unlocking {bd2.Name} with ID {Object.GlobalId}",
                                                    true);
#endif
                                                b2.Unlock();
                                            }
                                        });
                                    }

                                    ca.Builder_TownHall_Level++;
                                }


                                if (bd.IsAllianceCastle())
                                {
                                    var a  = (Building)go;
                                    var al = a.GetBuildingData;

                                    ca.Castle_Level++;
                                    ca.Castle_Total    = al.GetUnitStorageCapacity(ca.Castle_Level);
                                    ca.Castle_Total_SP = al.GetAltUnitStorageCapacity(ca.Castle_Level);
                                }
                                else if (bd.IsTownHall())
                                {
                                    ca.TownHall_Level++;
                                }

                                ca.Resources.Minus(rd.GetGlobalID(), bd.GetBuildCost(b.GetUpgradeLevel()));
                                b.StartUpgrading(this.Device.Player.Avatar.Variables.IsBuilderVillage);
                            }
                        }
                    }
                    else if (b.ClassId == 4 || b.ClassId == 11)
                    {
                        var bd = (Traps)b.GetConstructionItemData();
                        if (ca.HasEnoughResources(bd.GetBuildResource(b.GetUpgradeLevel()).GetGlobalID(),
                                                  bd.GetBuildCost(b.GetUpgradeLevel())))
                        {
                            if (this.Device.Player.Avatar.Variables.IsBuilderVillage
                                ? this.Device.Player.HasFreeBuilderVillageWorkers
                                : this.Device.Player.HasFreeVillageWorkers)
                            {
                                var name = go.GetData().Row.Name;
#if DEBUG
                                Loggers.Log($"Trap: Upgrading {name} with ID {BuildingId}", true);
#endif

                                var rd = bd.GetBuildResource(b.GetUpgradeLevel() + 1);
                                ca.Resources.Minus(rd.GetGlobalID(), bd.GetBuildCost(b.GetUpgradeLevel()));
                                b.StartUpgrading(this.Device.Player.Avatar.Variables.IsBuilderVillage);
                            }
                        }
                    }
                    else if (b.ClassId == 8 || b.ClassId == 15)
                    {
                        var bd = (Village_Objects)b.GetConstructionItemData();
                        if (ca.HasEnoughResources(bd.GetBuildResource(b.GetUpgradeLevel()).GetGlobalID(),
                                                  bd.GetBuildCost(b.GetUpgradeLevel())))
                        {
                            if (this.Device.Player.Avatar.Variables.IsBuilderVillage
                                ? this.Device.Player.HasFreeBuilderVillageWorkers
                                : this.Device.Player.HasFreeVillageWorkers)
                            {
                                var name = go.GetData().Row.Name;
#if DEBUG
                                Loggers.Log($"Village Object: Upgrading {name} with ID {BuildingId}", true);
#endif

                                var rd = bd.GetBuildResource(b.GetUpgradeLevel() + 1);
                                ca.Resources.Minus(rd.GetGlobalID(), bd.GetBuildCost(b.GetUpgradeLevel()));
                                b.StartUpgrading(this.Device.Player.Avatar.Variables.IsBuilderVillage);
                            }
                        }
                    }
                }
            }
        }
        public static bool Mission_Finish(this Player Player, int Global_ID)
        {
            if (Player.Tutorials.FindIndex(M => M == Global_ID) < 0)
            {
                Missions Mission = CSV.Tables.Get(Gamefile.Missions).GetDataWithID(Global_ID) as Missions;

#if DEBUG
                Console.WriteLine($"Mission received {Mission.Name} marked as finished");
#endif
                if (!string.IsNullOrEmpty(Mission.RewardResource))
                {
                    Files.CSV_Logic.Resource CSV_Resources =
                        CSV.Tables.Get(Gamefile.Resources).GetData(Mission.RewardResource) as Files.CSV_Logic.Resource;

                    Player.Resources.Plus(CSV_Resources.GetGlobalID(), Mission.RewardResourceCount);
                }
                if (!string.IsNullOrEmpty(Mission.RewardTroop))
                {
                    Characters CSV_Characters =
                        CSV.Tables.Get(Gamefile.Characters).GetData(Mission.RewardTroop) as Characters;

#if DEBUG
                    Console.WriteLine($"Player received {CSV_Characters.Name} as mission rewards");
#endif
                    Player.Add_Unit(CSV_Characters.GetGlobalID(), Mission.RewardTroopCount);
                }

                if (!string.IsNullOrEmpty(Mission.Dependencies))
                {
                    int DependenciesID = CSV.Tables.Get(Gamefile.Missions).GetData(Mission.Dependencies).GetGlobalID();
                    if (Player.Tutorials.FindIndex(M => M == DependenciesID) < 0)
                    {
#if DEBUG
                        Console.WriteLine(
                            $"Mission Dependencies {(CSV.Tables.Get(Gamefile.Missions).GetDataWithID(DependenciesID) as Missions).Name} marked as finished");
#endif
                        Mission_Finish(Player, DependenciesID);
                    }
                }
                if (!string.IsNullOrEmpty(Mission.AttackNPC))
                {
                    Npcs CSV_Npcs = CSV.Tables.Get(Gamefile.Npcs).GetData(Mission.AttackNPC) as Npcs;

                    if (Player.Npcs.FindIndex(N => N.NPC_Id == CSV_Npcs.GetGlobalID()) > -1)
                    {
                        Player.Resources.Plus(Logic.Enums.Resource.Gold, CSV_Npcs.Gold);
                        Player.Resources.Plus(Logic.Enums.Resource.Elixir, CSV_Npcs.Elixir);
                    }
                }
                if (Mission.ChangeName)
                {
                    Player.Resources.Plus(Logic.Enums.Resource.Gold, 900);
                    Player.Resources.Plus(Logic.Enums.Resource.Elixir, 400);
                }

                Player.AddExperience(Mission.RewardXP);
                Player.Tutorials.Add(Mission.GetGlobalID());
                return(true);
            }
            return(false);
        }