Esempio n. 1
0
        /// <summary>
        /// Finishes the building construction.
        /// </summary>
        internal void FinishConstruction(bool force = false)
        {
            if (this.Home.Player.Level.GameMode.State == State.Home || force)
            {
                this.Home.WorkerManager.DeallocateWorker(this);
                this.ConstructionTimer = null;

                int MaxLevel = this.BuildingData.GetUpgradeLevelCount();

                if (this.UpgradeLevel >= MaxLevel - 1)
                {
                    Logging.Error(this.GetType(), "FinishConstruction() - Trying to upgrade to level that doesn't exist!");
                    this.SetUpgradeLevel(MaxLevel - 1);
                }
                else
                {
                    this.SetUpgradeLevel(this.UpgradeLevel + 1);
                }

                this.Home.Player.XpGainHelper(GamePlayUtil.GetXpGain(this.BuildingData, this.UpgradeLevel));

                if (this.BuildingData.IsDeepsea())
                {
                    this.Home.Player.PlayerMap.DeepseaLevel = this.UpgradeLevel;
                }
            }
        }
Esempio n. 2
0
        //00 00 02 01 1D CD 65 10 00 00 38 A6

        public override void Execute(Level level)
        {
            ClientAvatar ca = level.GetPlayerAvatar();
            GameObject   go = level.GameObjectManager.GetGameObjectByID(m_vBuildingId);

            if (go != null)
            {
                if (go.ClassId == 0)
                {
                    Building b = (Building)go;
                    UnitProductionComponent upc = b.GetUnitProductionComponent();
                    if (upc != null)
                    {
                        int totalRemainingTime = upc.GetTotalRemainingSeconds();
                        int cost = GamePlayUtil.GetSpeedUpCost(totalRemainingTime);
                        if (upc.IsSpellForge())
                        {
                            int multiplier = ObjectManager.DataTables.GetGlobals().GetGlobalData("SPELL_SPEED_UP_COST_MULTIPLIER").NumberValue;
                            cost = (int)(((long)cost * (long)multiplier * (long)1374389535) >> 32);
                            cost = Math.Max((cost >> 5) + (cost >> 31), 1);
                        }
                        if (ca.HasEnoughDiamonds(cost))
                        {
                            if (upc.HasHousingSpaceForSpeedUp())
                            {
                                ca.UseDiamonds(cost);
                                upc.SpeedUp();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        internal void FinishConstruction(bool NoWorker = false)
        {
            TrapData Data = this.TrapData;

            if (this.UpgradeLevel + 1 > Data.MaxLevel)
            {
                Logging.Error(this.GetType(), "Unable to upgrade the building because the level is out of range! - " + Data.Name + ".");
                this.SetUpgradeLevel(Data.MaxLevel);
            }
            else
            {
                this.SetUpgradeLevel(this.UpgradeLevel + 1);
            }

            if (!NoWorker)
            {
                if (this.VillageType == 0)
                {
                    this.Level.WorkerManager.DeallocateWorker(this);
                }
                else
                {
                    this.Level.WorkerManagerV2.DeallocateWorker(this);
                }
            }


            this.Level.Player.AddExperience(GamePlayUtil.TimeToXp(Data.GetBuildTime(this.UpgradeLevel)));
            this.ConstructionTimer = null;
        }
Esempio n. 4
0
        public override void Execute(Level level)
        {
            var rd = (ResourceData)ObjectManager.DataTables.GetDataById(m_vResourceId);

            if (rd != null)
            {
                if (m_vResourceCount >= 1)
                {
                    if (!rd.PremiumCurrency)
                    {
                        var avatar            = level.GetPlayerAvatar();
                        var diamondCost       = GamePlayUtil.GetResourceDiamondCost(m_vResourceCount, rd);
                        var unusedResourceCap = avatar.GetUnusedResourceCap(rd);
                        if (m_vResourceCount <= unusedResourceCap)
                        {
                            if (avatar.HasEnoughDiamonds(diamondCost))
                            {
                                avatar.UseDiamonds(diamondCost);
                                avatar.CommodityCountChangeHelper(0, rd, m_vResourceCount);
                                if (m_vIsCommandEmbedded >= 1)
                                {
                                    ((Command)m_vCommand).Execute(level);
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Executes this instance.
        /// </summary>
        internal override void Execute(Level Level)
        {
            if (this.Data != null)
            {
                if (!this.Data.PremiumCurrency)
                {
                    // if (string.IsNullOrEmpty(this.Data.WarRefResource))
                    {
                        int Cost = GamePlayUtil.GetResourceCost(this.Data, this.Count, this.Data.VillageType);

                        if (Level.Player.HasEnoughDiamonds(this.Count))
                        {
                            if (Level.Player.GetAvailableResourceStorage(this.Data) >= this.Count)
                            {
                                Level.Player.UseDiamonds(this.Count);
                                Level.Player.Resources.Add(this.Data, this.Count);

                                if (this.Command != null)
                                {
                                    if (this.Command.ExecuteSubTick == -1)
                                    {
                                        this.Command.ExecuteSubTick = this.ExecuteSubTick;

                                        try
                                        {
                                            if (!this.Command.IsServerCommand)
                                            {
                                                this.Command.Execute(Level);
                                            }
                                        }
                                        catch (Exception Exception)
                                        {
                                            Logging.Error(this.GetType(), "An error has been throwed when the process of command type " + this.Command.Type + ". " + Exception);
                                        }
                                    }
                                }
                            }
                        }
#if DEBUG
                        else
                        {
                            Logging.Error(this.GetType(), "Unable to buy resources. You don't have enough diamond.");
                        }
#endif
                    }
                }
#if DEBUG
                else
                {
                    Logging.Error(this.GetType(), "Unable to buy resources. Premium resources is not buyable.");
                }
#endif
            }
#if DEBUG
            else
            {
                Logging.Error(this.GetType(), "Unable to buy resources. Data is null or invalid.");
            }
#endif
        }
        internal void SpeedUp()
        {
            if (this.UpgradeOnGoing)
            {
                int RemainingSeconds = this.Timer.GetRemainingSeconds(this.Parent.Level.Player.LastTick);

                if (RemainingSeconds > 0)
                {
                    Player Player = this.Parent.Level.Player;

                    if (Player != null)
                    {
                        int Cost = GamePlayUtil.GetSpeedUpCost(RemainingSeconds, 0, 100);

                        if (Cost > 0)
                        {
                            if (Player.HasEnoughDiamonds(Cost))
                            {
                                Player.UseDiamonds(Cost);
                                this.FinishUpgrading();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public int GetResourceDiamondCost(int resourceCount, ResourceData resourceData)
        {
            var result = 0;

            if (resourceData == ObjectManager.DataTables.GetResourceByName("DarkElixir"))
            {
                result = GetDarkElixirDiamondCost(resourceCount);
            }
            else if (resourceCount >= 1)
            {
                if (resourceCount >= 100)
                {
                    if (resourceCount >= 1000)
                    {
                        if (resourceCount >= 10000)
                        {
                            if (resourceCount >= 100000)
                            {
                                if (resourceCount >= 1000000)
                                {
                                    var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_10000000").NumberValue;
                                    var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_1000000").NumberValue;
                                    result = GamePlayUtil.CalculateResourceCost(10000000, 1000000, supCost, infCost, resourceCount);
                                }
                                else
                                {
                                    var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_1000000").NumberValue;
                                    var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_100000").NumberValue;
                                    result = GamePlayUtil.CalculateResourceCost(1000000, 100000, supCost, infCost, resourceCount);
                                }
                            }
                            else
                            {
                                var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_100000").NumberValue;
                                var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_10000").NumberValue;
                                result = GamePlayUtil.CalculateResourceCost(100000, 10000, supCost, infCost, resourceCount);
                            }
                        }
                        else
                        {
                            var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_10000").NumberValue;
                            var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_1000").NumberValue;
                            result = GamePlayUtil.CalculateResourceCost(10000, 1000, supCost, infCost, resourceCount);
                        }
                    }
                    else
                    {
                        var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_1000").NumberValue;
                        var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_100").NumberValue;
                        result = GamePlayUtil.CalculateResourceCost(1000, 100, supCost, infCost, resourceCount);
                    }
                }
                else
                {
                    result = ObjectManager.DataTables.GetGlobals().GetGlobalData("RESOURCE_DIAMOND_COST_100").NumberValue;
                }
            }
            return(result);
        }
Esempio n. 8
0
        internal override void Execute()
        {
            if (this.Data != null)
            {
                if (!this.Data.PremiumCurrency)
                {
                    // if (string.IsNullOrEmpty(this.Data.WarRefResource))
                    {
                        Level Level = this.Device.GameMode.Level;
                        int   Cost  = GamePlayUtil.GetResourceCost(this.Data, this.Count, this.Data.VillageType);

                        if (Level.Player.HasEnoughDiamonds(Cost))
                        {
                            if (Level.Player.GetAvailableResourceStorage(this.Data) >= this.Count)
                            {
                                Level.Player.UseDiamonds(Cost);
                                Level.Player.Resources.Add(this.Data, this.Count);

                                if (this.Command != null)
                                {
                                    try
                                    {
                                        if (!this.Command.IsServerCommand)
                                        {
                                            this.Command.Execute();

                                            /*
                                             * Logging.Info(this.GetType(), "Embedded Command is handled! (" + this.Command.Type + ")");
                                             */
                                        }
                                        else
                                        {
                                            Logging.Error(this.GetType(), "Unable to execute server command as embedded command! (" + this.Command.Type + ")");
                                        }
                                    }
                                    catch (Exception Exception)
                                    {
                                        Logging.Error(this.GetType(), "An error has been throwed when the process of command type " + this.Command.Type + ". " + Exception);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logging.Error(this.GetType(), "Unable to buy resources. The player don't have enough diamond.");
                        }
                    }
                }
                else
                {
                    Logging.Error(this.GetType(), "Unable to buy resources. Premium resources is not buyable.");
                }
            }
            else
            {
                Logging.Error(this.GetType(), "Unable to buy resources. Data is null or invalid.");
            }
        }
Esempio n. 9
0
        public int GetSpeedUpCost(int seconds)
        {
            var cost = 0;

            if (seconds >= 1)
            {
                if (seconds >= 60)
                {
                    if (seconds >= 3600)
                    {
                        if (seconds >= 86400)
                        {
                            var supCost =
                                ObjectManager.DataTables.GetGlobals()
                                .GetGlobalData("SPEED_UP_DIAMOND_COST_1_WEEK")
                                .NumberValue;
                            var infCost =
                                ObjectManager.DataTables.GetGlobals()
                                .GetGlobalData("SPEED_UP_DIAMOND_COST_24_HOURS")
                                .NumberValue;
                            cost = GamePlayUtil.CalculateSpeedUpCost(604800, 86400, supCost, infCost, seconds);
                        }
                        else
                        {
                            var supCost =
                                ObjectManager.DataTables.GetGlobals()
                                .GetGlobalData("SPEED_UP_DIAMOND_COST_24_HOURS")
                                .NumberValue;
                            var infCost =
                                ObjectManager.DataTables.GetGlobals()
                                .GetGlobalData("SPEED_UP_DIAMOND_COST_1_HOUR")
                                .NumberValue;
                            cost = GamePlayUtil.CalculateSpeedUpCost(86400, 3600, supCost, infCost, seconds);
                        }
                    }
                    else
                    {
                        var supCost =
                            ObjectManager.DataTables.GetGlobals()
                            .GetGlobalData("SPEED_UP_DIAMOND_COST_1_HOUR")
                            .NumberValue;
                        var infCost =
                            ObjectManager.DataTables.GetGlobals()
                            .GetGlobalData("SPEED_UP_DIAMOND_COST_1_MIN")
                            .NumberValue;
                        cost = GamePlayUtil.CalculateSpeedUpCost(3600, 60, supCost, infCost, seconds);
                    }
                }
                else
                {
                    cost =
                        ObjectManager.DataTables.GetGlobals().GetGlobalData("SPEED_UP_DIAMOND_COST_1_MIN").NumberValue;
                }
            }
            return(cost);
        }
Esempio n. 10
0
 public void SpeedUpConstruction()
 {
     if (IsConstructing())
     {
         var ca = GetLevel().GetPlayerAvatar();
         var remainingSeconds = m_vTimer.GetRemainingSeconds(m_vLevel.GetTime());
         var cost             = GamePlayUtil.GetSpeedUpCost(remainingSeconds);
         if (ca.HasEnoughDiamonds(cost))
         {
             ca.UseDiamonds(cost);
             FinishConstruction();
         }
     }
 }
Esempio n. 11
0
 public void SpeedUpConstruction()
 {
     if (IsConstructing())
     {
         ClientAvatar ca = Avatar.Avatar;
         int          remainingSeconds = m_vTimer.GetRemainingSeconds(m_vLevel.Avatar.LastTickSaved);
         int          cost             = GamePlayUtil.GetSpeedUpCost(remainingSeconds);
         if (ca.HasEnoughDiamonds(cost))
         {
             ca.UseDiamonds(cost);
             FinishConstruction();
         }
     }
 }
        internal override void Execute()
        {
            Player Player = this.Device.GameMode.Level.Player;

            if (Player.InAlliance)
            {
                Building Bunker = this.Device.GameMode.Level.GameObjectManager.Bunker;
                if (Bunker != null)
                {
                    BunkerComponent BunkerComponent = Bunker.BunkerComponent;
                    if (BunkerComponent != null)
                    {
                        if (!BunkerComponent.CanSendUnitRequest)
                        {
                            int RemainingSeconds = BunkerComponent.UnitRequestTimer.GetRemainingSeconds(Player.LastTick);

                            if (RemainingSeconds > 0)
                            {
                                int Cost = GamePlayUtil.GetSpeedUpCost(RemainingSeconds, 0, Globals.TroopRequestSpeedUpCostMultiplier);

                                if (Cost > 0)
                                {
                                    if (Player.HasEnoughDiamonds(Cost))
                                    {
                                        Player.UseDiamonds(Cost);
                                        BunkerComponent.UnitRequestTimer = null;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Logging.Error(this.GetType(), "Unable to speed up the troop request. The player BunkerComponent.CanSendUnitRequest returned true!");
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "Unable to speed up the troop request. The player BunkerComponent is null!");
                    }
                }
                else
                {
                    Logging.Error(this.GetType(), "Unable to speed up the troop request. The player doesn't have a bunker!");
                }
            }
            else
            {
                Logging.Error(this.GetType(), "Unable to speed up the troop request. The player is not in a clan!");
            }
        }
Esempio n. 13
0
        public int GetDarkElixirDiamondCost(int resourceCount)
        {
            var result = 0;

            if (resourceCount >= 1)
            {
                if (resourceCount >= 10)
                {
                    if (resourceCount >= 100)
                    {
                        if (resourceCount >= 1000)
                        {
                            if (resourceCount >= 10000)
                            {
                                var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_100000").NumberValue;
                                var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_10000").NumberValue;
                                result = GamePlayUtil.CalculateResourceCost(100000, 10000, supCost, infCost,
                                                                            resourceCount);
                            }
                            else
                            {
                                var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_10000").NumberValue;
                                var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_1000").NumberValue;
                                result = GamePlayUtil.CalculateResourceCost(10000, 1000, supCost, infCost, resourceCount);
                            }
                        }
                        else
                        {
                            var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_1000").NumberValue;
                            var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_100").NumberValue;
                            result = GamePlayUtil.CalculateResourceCost(1000, 100, supCost, infCost, resourceCount);
                        }
                    }
                    else
                    {
                        var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_100").NumberValue;
                        var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_10").NumberValue;
                        result = GamePlayUtil.CalculateResourceCost(100, 10, supCost, infCost, resourceCount);
                    }
                }
                else
                {
                    var supCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_10").NumberValue;
                    var infCost = ObjectManager.DataTables.GetGlobals().GetGlobalData("DARK_ELIXIR_DIAMOND_COST_1").NumberValue;
                    result = GamePlayUtil.CalculateResourceCost(10, 1, supCost, infCost, resourceCount);
                }
            }
            return(result);
        }
Esempio n. 14
0
 internal void SpeedUpConstruction()
 {
     if (this.Level.Player != null)
     {
         if (this.Constructing)
         {
             int Cost = GamePlayUtil.GetSpeedUpCost(this.RemainingConstructionTime, this.VillageType, 100);
             if (this.Level.Player.HasEnoughDiamonds(Cost))
             {
                 this.Level.Player.UseDiamonds(Cost);
                 this.FinishConstruction();
             }
         }
     }
 }
Esempio n. 15
0
        internal void SpeedUpUpgrade()
        {
            if (this.Parent.Level.Player != null)
            {
                if (this.Upgrading)
                {
                    int Cost = GamePlayUtil.GetSpeedUpCost(this.RemainingUpgradeTime, this.VillageType, 100);

                    if (this.Parent.Level.Player.HasEnoughDiamonds(Cost))
                    {
                        this.Parent.Level.Player.UseDiamonds(Cost);
                        this.FinishUpgrading();
                    }
                }
            }
        }
Esempio n. 16
0
        internal void SpeedUpClearing()
        {
            if (this.Level.Player != null)
            {
                if (this.ClearingOnGoing)
                {
                    int Cost = GamePlayUtil.GetSpeedUpCost(this.RemainingClearingTime, this.ObstacleData.VillageType, 100);

                    if (this.Level.Player.HasEnoughDiamonds(Cost))
                    {
                        this.Level.Player.UseDiamonds(Cost);
                        this.ClearingFinished();
                    }
                }
            }
        }
Esempio n. 17
0
        public void SpeedUpConstruction()
        {
            if (ConstructionTimer == null)
            {
                return;
            }
            var cost = GamePlayUtil.GetSpeedUpCost(ConstructionTimer.GetRemainingSeconds(Home.Time));

            if (Home.UseDiamonds(cost))
            {
                FinishConstruction();
            }
            else
            {
                Logger.Log("Payment failed.", GetType(), Logger.ErrorLevel.Warning);
            }
        }
Esempio n. 18
0
        public void SpeedUpClearing()
        {
            var remainingSeconds = 0;

            if (IsClearingOnGoing())
            {
                remainingSeconds = m_vTimer.GetRemainingSeconds(m_vLevel.GetTime());
            }
            var cost = GamePlayUtil.GetSpeedUpCost(remainingSeconds);
            var ca   = GetLevel().GetPlayerAvatar();

            if (ca.HasEnoughDiamonds(cost))
            {
                ca.UseDiamonds(cost);
                ClearingFinished();
            }
        }
Esempio n. 19
0
        public void SpeedUpUpgrade()
        {
            var remainingSeconds = 0;

            if (IsUpgrading())
            {
                remainingSeconds = m_vTimer.GetRemainingSeconds(GetParent().GetLevel().GetTime());
            }
            var cost = GamePlayUtil.GetSpeedUpCost(remainingSeconds);
            var ca   = GetParent().GetLevel().GetPlayerAvatar();

            if (ca.HasEnoughDiamonds(cost))
            {
                ca.UseDiamonds(cost);
                FinishUpgrading();
            }
        }
Esempio n. 20
0
        public override void Execute(Level level)
        {
            if (Depth >= MaxEmbeddedDepth)
            {
                IPEndPoint r = level.GetClient().Socket.RemoteEndPoint as IPEndPoint;
                ConnectionBlocker.AddNewIpToBlackList(r.Address.ToString());
                ResourcesManager.DropClient(level.GetClient().Socket.Handle.ToInt64());
            }
            else
            {
                var rd = (ResourceData)CSVManager.DataTables.GetDataById(m_vResourceId);
                if (rd != null)
                {
                    if (m_vResourceCount >= 1)
                    {
                        if (!rd.PremiumCurrency)
                        {
                            var avatar            = level.GetPlayerAvatar();
                            var diamondCost       = GamePlayUtil.GetResourceDiamondCost(m_vResourceCount, rd);
                            var unusedResourceCap = avatar.GetUnusedResourceCap(rd);
                            if (m_vResourceCount <= unusedResourceCap)
                            {
                                if (avatar.HasEnoughDiamonds(diamondCost))
                                {
                                    avatar.UseDiamonds(diamondCost);
                                    avatar.CommodityCountChangeHelper(0, rd, m_vResourceCount);
                                    if (m_vIsCommandEmbedded)
                                    {
                                        Depth++;

                                        if (Depth >= MaxEmbeddedDepth)
                                        {
                                            throw new ArgumentException(
                                                      "A command contained embedded command depth was greater than max embedded commands.");
                                        }

                                        ((Command)m_vCommand).Execute(level);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 internal override void Process()
 {
     if (Depth >= MaxEmbeddedDepth)
     {
         IPEndPoint r = this.Device.Socket.RemoteEndPoint as IPEndPoint;
         ConnectionBlocker.AddNewIpToBlackList(r.Address.ToString());
         ResourcesManager.DropClient(this.Device.Socket.Handle);
     }
     else
     {
         var rd = (ResourceData)CSVManager.DataTables.GetDataById(m_vResourceId);
         if (rd != null)
         {
             if (m_vResourceCount >= 1)
             {
                 if (!rd.PremiumCurrency)
                 {
                     var avatar            = this.Device.Player.Avatar;
                     var diamondCost       = GamePlayUtil.GetResourceDiamondCost(m_vResourceCount, rd);
                     var unusedResourceCap = avatar.GetUnusedResourceCap(rd);
                     if (m_vResourceCount <= unusedResourceCap)
                     {
                         if (avatar.HasEnoughDiamonds(diamondCost))
                         {
                             avatar.UseDiamonds(diamondCost);
                             avatar.CommodityCountChangeHelper(0, rd, m_vResourceCount);
                             if (m_vIsCommandEmbedded)
                             {
                                 int     CommandID = this.Reader.ReadInt32();
                                 Command _Command  =
                                     Activator.CreateInstance(CommandFactory.Commands[CommandID], this.Reader,
                                                              this.Device, CommandID) as Command;
                                 if (_Command != null)
                                 {
                                     _Command.Decode();
                                     _Command.Process();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 22
0
 public void SpeedUp()
 {
     if (m_vCurrentlyUpgradedUnit != null)
     {
         int remainingSeconds = 0;
         if (m_vTimer != null)
         {
             remainingSeconds = m_vTimer.GetRemainingSeconds(GetParent().GetLevel().GetTime());
         }
         int cost = GamePlayUtil.GetSpeedUpCost(remainingSeconds);
         var ca   = GetParent().GetLevel().GetPlayerAvatar();
         if (ca.HasEnoughDiamonds(cost))
         {
             ca.UseDiamonds(cost);
             FinishUpgrading();
         }
     }
 }
Esempio n. 23
0
 public void SpeedUp()
 {
     if (m_vCurrentlyUpgradedUnit != null)
     {
         var remainingSeconds = 0;
         if (m_vTimer != null)
         {
             remainingSeconds = m_vTimer.GetRemainingSeconds(GetParent().Avatar.Avatar.LastTickSaved);
         }
         var cost = GamePlayUtil.GetSpeedUpCost(remainingSeconds);
         var ca   = GetParent().Avatar.Avatar;
         if (ca.HasEnoughDiamonds(cost))
         {
             ca.UseDiamonds(cost);
             FinishUpgrading();
         }
     }
 }
Esempio n. 24
0
        /// <summary>
        /// Finishes the construction of building.
        /// </summary>
        internal void FinishConstruction()
        {
            if (this.Level.GameMode.State == State.Home)
            {
                BuildingData Data = this.BuildingData;

                if (this.UpgradeLevel + 1 > Data.MaxLevel)
                {
                    Logging.Error(this.GetType(), "Unable to upgrade the building because the level is out of range! - " + Data.Name + ".");
                    this.SetUpgradeLevel(Data.MaxLevel);
                }
                else
                {
                    this.SetUpgradeLevel(this.UpgradeLevel + 1);
                }

                this.Level.WorkerManager.DeallocateWorker(this);
                this.Level.Player.AddExperience(GamePlayUtil.TimeToXp(Data.GetBuildTime(this.UpgradeLevel)));

                this.ConstructionTimer = null;
            }
        }
Esempio n. 25
0
        internal void ClearingFinished()
        {
            Player Player = this.Level.Player;

            if (this.VillageType == 0)
            {
                Player.AddDiamonds(this.GemDrops[this.Level.GameObjectManager.ObstacleClearCounter++]);

                if (this.Level.GameObjectManager.ObstacleClearCounter >= this.GemDrops.Length)
                {
                    this.Level.GameObjectManager.ObstacleClearCounter = 0;
                }

                this.Level.WorkerManager.DeallocateWorker(this);
            }
            else
            {
                if (!this.ObstacleData.TallGrass)
                {
                    Player.AddDiamonds(this.GemDrops[this.Level.GameObjectManager.ObstacleClearCounterV2++]);

                    if (this.Level.GameObjectManager.ObstacleClearCounterV2 >= this.GemDrops.Length)
                    {
                        this.Level.GameObjectManager.ObstacleClearCounterV2 = 0;
                    }

                    this.Level.WorkerManagerV2.DeallocateWorker(this);
                }
            }

            // LogicAchievementManager::obstacleCleared();

            Player.AddExperience(GamePlayUtil.TimeToXp(this.ObstacleData.ClearTimeSeconds));
            Player.ObstacleCleaned++;

            this.ClearTimer = null;
            this.Destructed = true;
            this.Level.GameObjectManager.RemoveGameObject(this, this.VillageType);
        }
Esempio n. 26
0
        public override void Execute(Level level)
        {
            var rd = (ResourceData)ObjectManager.DataTables.GetDataById(m_vResourceId);

            if (rd != null)
            {
                if (m_vResourceCount >= 1)
                {
                    if (!rd.PremiumCurrency)
                    {
                        var avatar            = level.GetPlayerAvatar();
                        var diamondCost       = GamePlayUtil.GetResourceDiamondCost(m_vResourceCount, rd);
                        var unusedResourceCap = avatar.GetUnusedResourceCap(rd);
                        if (m_vResourceCount <= unusedResourceCap)
                        {
                            if (avatar.HasEnoughDiamonds(diamondCost))
                            {
                                avatar.UseDiamonds(diamondCost);
                                avatar.CommodityCountChangeHelper(0, rd, m_vResourceCount);
                                if (m_vIsCommandEmbedded)
                                {
                                    Depth++;

                                    if (Depth >= MaxEmbeddedDepth)
                                    {
                                        throw new ArgumentException(
                                                  "A command contained embedded command depth was greater than max embedded commands.");
                                    }

                                    ((Command)m_vCommand).Execute(level);
                                }
                            }
                        }
                    }
                }
            }
        }
        public override void Execute(Level level)
        {
            if (Depth >= 10)
            {
                //TODO: Block Exploitor's IP.
                ResourcesManager.DropClient(level.GetClient().GetSocketHandle());
            }
            else
            {
                ResourceData dataById = (ResourceData)CSVManager.DataTables.GetDataById(m_vResourceId);
                if (dataById == null || m_vResourceCount < 1 || dataById.PremiumCurrency)
                {
                    return;
                }

                ClientAvatar avatar = level.GetPlayerAvatar();
                int          resourceDiamondCost = GamePlayUtil.GetResourceDiamondCost(m_vResourceCount, dataById);
                if (m_vResourceCount > avatar.GetUnusedResourceCap(dataById) || !avatar.HasEnoughDiamonds(resourceDiamondCost))
                {
                    return;
                }

                avatar.UseDiamonds(resourceDiamondCost);
                avatar.CommodityCountChangeHelper(0, (Data)dataById, m_vResourceCount);
                if (!m_vIsCommandEmbedded)
                {
                    return;
                }

                if (m_vIsCommandEmbedded && m_vCommand != null)
                {
                    var cmd = (Command)m_vCommand;
                    cmd.Execute(level);
                }
            }
        }
Esempio n. 28
0
        internal void FinishConstruction()
        {
            BuildingData Data = this.BuildingData;

            if (this.Gearing)
            {
                this.Gearing = false;

                this.CombatComponent.GearUp = 1;

                if (this.CombatComponent.AltAttackMode)
                {
                    this.CombatComponent.AttackMode      = true;
                    this.CombatComponent.AttackModeDraft = true;
                }

                this.Level.WorkerManagerV2.DeallocateWorker(this);
            }
            else
            {
                if (this.UpgradeLevel + 1 > Data.MaxLevel)
                {
                    Logging.Error(this.GetType(), "Unable to upgrade the building because the level is out of range! - " + Data.Name + ".");
                    this.SetUpgradeLevel(Data.MaxLevel);
                }
                else
                {
                    this.SetUpgradeLevel(this.UpgradeLevel + 1);
                }

                if (this.Locked)
                {
                    this.Locked = false;
                    if (this.VillageType == 1)
                    {
                        this.Level.WorkerManagerV2.DeallocateWorker(this);
                    }
                }
                else
                {
                    if (this.VillageType == 0)
                    {
                        this.Level.WorkerManager.DeallocateWorker(this);
                    }
                    else
                    {
                        this.Level.WorkerManagerV2.DeallocateWorker(this);
                    }
                }
            }

            if (!Data.IsTroopHousingV2)
            {
                this.Level.Player.AddExperience(GamePlayUtil.TimeToXp(Data.GetBuildTime(this.UpgradeLevel)));
            }
            else
            {
                int troopHousing = this.Level.GameObjectManager.Filter.GetGameObjectCount(this.BuildingData);

                if (troopHousing >= 0)
                {
                    int Time;
                    switch (troopHousing)
                    {
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                        Time = Globals.TroopHousingV2BuildTimeSeconds[troopHousing - 1];
                        break;

                    default:
                        Time = Globals.TroopHousingV2BuildTimeSeconds[4];
                        break;
                    }

                    this.Level.Player.AddExperience(GamePlayUtil.TimeToXp(Time));
                }
                else
                {
                    Logging.Error(this.GetType(), "TroopHousingV2 count is below zero when trying to get build time");
                }
            }

            if (this.HeroBaseComponent != null)
            {
                var data = CSV.Tables.Get(Gamefile.Heroes).GetData(this.BuildingData.HeroType);
                if (data is HeroData)
                {
                    HeroData HeroData = (HeroData)data;

                    this.Level.Player.HeroUpgrades.Set(HeroData, 0);
                    this.Level.Player.HeroStates.Set(HeroData, 3);
                    if (HeroData.HasAltMode)
                    {
                        this.Level.Player.HeroModes.Set(HeroData, 0);
                    }
                }
            }

            this.ConstructionTimer = null;
        }