public void AddUnitsToQueue(LogicCombatItemData data, int count)
        {
            LogicCalendar          calendar          = this.m_level.GetCalendar();
            LogicAvatar            homeOwnerAvatar   = this.m_level.GetHomeOwnerAvatar();
            LogicClientAvatar      playerAvatar      = this.m_level.GetPlayerAvatar();
            LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
            LogicUnitProduction    production        = gameObjectManager.GetUnitProduction();

            if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
            {
                if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL)
                {
                    return;
                }

                production = gameObjectManager.GetSpellProduction();
            }

            if (production != null)
            {
                int trainCost = calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));

                for (int i = 0; i < count; i++)
                {
                    if (production.CanAddUnitToQueue(data, true) &&
                        playerAvatar.HasEnoughResources(data.GetTrainingResource(), trainCost, false, null, false))
                    {
                        playerAvatar.CommodityCountChangeHelper(0, data.GetTrainingResource(), -trainCost);
                        production.AddUnitToQueue(data, production.GetSlotCount(), true);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Destructs this instance.
        /// </summary>
        public void Destruct()
        {
            if (this._level != null)
            {
                this._level.Destruct();
                this._level = null;
            }

            if (this._commandManager != null)
            {
                this._commandManager.Destruct();
                this._commandManager = null;
            }

            if (this._calendar != null)
            {
                this._calendar.Destruct();
                this._calendar = null;
            }

            if (this._battleTimer != null)
            {
                this._battleTimer.Destruct();
                this._battleTimer = null;
            }

            if (this._replay != null)
            {
                this._replay.Destruct();
                this._replay = null;
            }

            this._configuration = null;
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogicGameMode" /> class.
 /// </summary>
 public LogicGameMode()
 {
     this._level            = new LogicLevel(this);
     this._commandManager   = new LogicCommandManager(this._level);
     this._calendar         = new LogicCalendar();
     this._configuration    = new LogicConfiguration();
     this._currentTimestamp = -1;
 }
        public bool HasEnoughFreeHousingSpace()
        {
            LogicCalendar       calendar        = this.m_level.GetCalendar();
            LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
            LogicUnitProduction unitProduction  = this.m_level.GetGameObjectManagerAt(0).GetUnitProduction();
            LogicDataTable      characterTable  = LogicDataTables.GetTable(LogicDataType.CHARACTER);

            int freeHousingSpace     = unitProduction.GetMaxTrainCount() - (homeOwnerAvatar.GetUnitsTotalCapacity() - unitProduction.GetTotalCount());
            int requiredHousingSpace = 0;

            for (int i = 0; i < characterTable.GetItemCount(); i++)
            {
                LogicCharacterData data = (LogicCharacterData)characterTable.GetItemAt(i);

                if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop())
                {
                    int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                    if (count > 0)
                    {
                        requiredHousingSpace += data.GetHousingSpace() * count;
                    }
                }
            }

            if (requiredHousingSpace <= freeHousingSpace)
            {
                LogicUnitProduction spellProduction = this.m_level.GetGameObjectManagerAt(0).GetSpellProduction();
                LogicDataTable      spellTable      = LogicDataTables.GetTable(LogicDataType.SPELL);

                int freeSpellHousingSpace     = spellProduction.GetMaxTrainCount() - (homeOwnerAvatar.GetSpellsTotalCapacity() - spellProduction.GetTotalCount());
                int requiredSpellHousingSpace = 0;

                for (int i = 0; i < spellTable.GetItemCount(); i++)
                {
                    LogicSpellData data = (LogicSpellData)spellTable.GetItemAt(i);

                    if (calendar.IsProductionEnabled(data))
                    {
                        int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                        if (count > 0)
                        {
                            requiredSpellHousingSpace += data.GetHousingSpace() * count;
                        }
                    }
                }

                return(requiredSpellHousingSpace <= freeSpellHousingSpace);
            }

            return(false);
        }
        public int GetResourceCost(LogicResourceData resourceData)
        {
            int cost = 0;

            LogicAvatar    homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
            LogicCalendar  calendar        = this.m_level.GetCalendar();
            LogicDataTable table           = LogicDataTables.GetTable(LogicDataType.CHARACTER);

            for (int i = 0; i < table.GetItemCount(); i++)
            {
                LogicCharacterData data = (LogicCharacterData)table.GetItemAt(i);

                if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop())
                {
                    int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                    if (count > 0)
                    {
                        if (data.GetTrainingResource() == resourceData)
                        {
                            cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));
                        }
                    }
                }
            }

            table = LogicDataTables.GetTable(LogicDataType.SPELL);

            for (int i = 0; i < table.GetItemCount(); i++)
            {
                LogicSpellData data = (LogicSpellData)table.GetItemAt(i);

                if (calendar.IsProductionEnabled(data))
                {
                    int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                    if (count > 0)
                    {
                        if (data.GetTrainingResource() == resourceData)
                        {
                            cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));
                        }
                    }
                }
            }

            return(cost);
        }
Ejemplo n.º 6
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                int lootLimitCooldown = playerAvatar.GetVariableByName("LootLimitCooldown");

                if (lootLimitCooldown == 1)
                {
                    LogicConfiguration configuration = level.GetGameMode().GetConfiguration();

                    if (configuration != null)
                    {
                        LogicCalendar calendar = level.GetGameMode().GetCalendar();

                        if (calendar != null)
                        {
                            int remainingSecs          = playerAvatar.GetRemainingLootLimitTime();
                            int totalSecs              = LogicCalendar.GetDuelLootLimitCooldownInMinutes(calendar, configuration) * 60;
                            int maxDiamondsCostPercent = LogicCalendar.GetDuelBonusMaxDiamondCostPercent(calendar, configuration);

                            int speedUpCost = LogicMath.Max(
                                LogicGamePlayUtil.GetLeagueVillage2(playerAvatar.GetDuelScore()).GetMaxDiamondCost() * maxDiamondsCostPercent * remainingSecs / totalSecs / 100, 1);

                            if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                            {
                                playerAvatar.UseDiamonds(speedUpCost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(18, 0, remainingSecs, speedUpCost, level.GetVillageType());
                                playerAvatar.FastForwardLootLimit(remainingSecs);

                                return(0);
                            }

                            return(-3);
                        }

                        return(-5);
                    }

                    return(-4);
                }

                return(-3);
            }

            return(-2);
        }