public void AdjustEndSubtick(LogicLevel level)
        {
            if (this.m_endTimestamp != -1)
            {
                int currentTime = LogicDataTables.GetGlobals().AdjustEndSubtickUseCurrentTime()
                    ? level.GetGameMode().GetServerTimeInSecondsSince1970()
                    : level.GetGameMode().GetStartTime();

                if (currentTime != -1)
                {
                    int remainingSecs = this.m_endTimestamp - currentTime;
                    int clamp         = LogicDataTables.GetGlobals().GetClampLongTimeStampsToDays();

                    if (clamp * 86400 > 0)
                    {
                        if (remainingSecs > 86400 * clamp)
                        {
                            remainingSecs = 86400 * clamp;
                        }
                        else if (remainingSecs < -86400 * clamp)
                        {
                            remainingSecs = -86400 * clamp;
                        }
                    }

                    this.m_remainingTime = level.GetLogicTime().GetTick() + LogicTime.GetSecondsInTicks(remainingSecs);
                }
            }
        }
        /// <summary>
        ///     Executes this instance.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (true)
            {
                int tileX = this._x >> 9;
                int tileY = this._y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    // if (level.GetTileMap().IsPassablePathFinder(this._x >> 8, this._y >> 8))
                    {
                        if (level.GetTileMap().IsValidAttackPos(tileX, tileY))
                        {
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            if (playerAvatar != null)
                            {
                                int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this._data) : playerAvatar.GetUnitCount(this._data);

                                if (unitCount > 0)
                                {
                                    if (level.GetBattleLog() != null)
                                    {
                                        // ?
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this._data, level, this._x, this._y);

                                    if (character != null)
                                    {
                                        // TODO: Finish this.
                                    }

                                    return(0);
                                }

                                return(-7);
                            }

                            return(-5);
                        }

                        return(-4);
                    }

                    // return -2;
                }

                return(-3);
            }

            return(-1);
        }
Exemplo n.º 3
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                int tileX = this.m_x >> 9;
                int tileY = this.m_y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    if (level.GetVillageType() == 0)
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        if (playerAvatar != null)
                        {
                            int unitCount = this.m_allianceSpell ? playerAvatar.GetAllianceUnitCount(this.m_data, this.m_upgLevel) : playerAvatar.GetUnitCount(this.m_data);

                            if (unitCount > 0)
                            {
                                if (level.GetBattleLog() != null)
                                {
                                    if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                    {
                                        level.UpdateLastUsedArmy();
                                    }
                                }

                                if (level.GetGameMode().IsInAttackPreparationMode())
                                {
                                    level.GetGameMode().EndAttackPreparation();
                                }

                                LogicCastSpellCommand.CastSpell(playerAvatar, this.m_data, this.m_allianceSpell, this.m_upgLevel, level, this.m_x, this.m_y);

                                return(0);
                            }
                        }

                        return(-3);
                    }

                    Debugger.Error("not available for village");

                    return(-23);
                }

                return(-3);
            }

            return(-1);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Executes this instance.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (true)
            {
                int tileX = this._x >> 9;
                int tileY = this._y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    if (level.GetVillageType() == 0)
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        if (playerAvatar != null)
                        {
                            int unitCount = this._allianceSpell ? playerAvatar.GetAllianceUnitCount(this._data, this._upgLevel) : playerAvatar.GetUnitCount(this._data);

                            if (unitCount > 0)
                            {
                                if (level.GetBattleLog() != null)
                                {
                                    // ?
                                }

                                if (level.GetGameMode().IsInAttackPreparationMode())
                                {
                                    level.GetGameMode().EndAttackPreparation();
                                }

                                LogicCastSpellCommand.CastSpell(playerAvatar, this._data, this._allianceSpell, this._upgLevel, level, this._x, this._y);

                                return(0);
                            }
                        }

                        return(-3);
                    }
                    else
                    {
                        Debugger.Error("not available for village");
                    }

                    return(-23);
                }

                return(-3);
            }

            return(-1);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (level.GetVillageType() == 1)
            {
                LogicGameMode gameMode = level.GetGameMode();

                if (!gameMode.IsInAttackPreparationMode())
                {
                    if (gameMode.GetState() != 5)
                    {
                        return(-9);
                    }
                }

                if (this.m_oldUnitData != null && this.m_newUnitData != null && gameMode.GetCalendar().IsProductionEnabled(this.m_newUnitData))
                {
                    if (!this.m_newUnitData.IsUnlockedForBarrackLevel(playerAvatar.GetVillage2BarrackLevel()))
                    {
                        if (gameMode.GetState() != 7)
                        {
                            return(-7);
                        }
                    }

                    int oldUnitCount   = playerAvatar.GetUnitCountVillage2(this.m_oldUnitData);
                    int oldUnitsInCamp = this.m_oldUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_oldUnitData));

                    if (oldUnitCount >= oldUnitsInCamp)
                    {
                        int newUnitCount   = playerAvatar.GetUnitCountVillage2(this.m_newUnitData);
                        int newUnitsInCamp = this.m_newUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_newUnitData));

                        playerAvatar.SetUnitCountVillage2(this.m_oldUnitData, oldUnitCount - oldUnitsInCamp);
                        playerAvatar.SetUnitCountVillage2(this.m_newUnitData, newUnitCount + newUnitsInCamp);

                        LogicArrayList <LogicDataSlot> unitsNew = playerAvatar.GetUnitsNewVillage2();

                        for (int i = 0; i < unitsNew.Size(); i++)
                        {
                            LogicDataSlot slot = unitsNew[i];

                            if (slot.GetCount() > 0)
                            {
                                playerAvatar.CommodityCountChangeHelper(8, slot.GetData(), -slot.GetCount());
                            }
                        }

                        return(0);
                    }

                    return(-23);
                }

                return(-7);
            }

            return(-10);
        }
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 0)
            {
                LogicGameMode gameMode = level.GetGameMode();

                if (gameMode.GetShieldRemainingSeconds() <= 0)
                {
                    gameMode.SetShieldRemainingSeconds(0);
                    gameMode.SetGuardRemainingSeconds(0);

                    gameMode.GetLevel().GetHome().GetChangeListener().ShieldActivated(0, 0);
                }
                else
                {
                    int guardTime = gameMode.GetGuardRemainingSeconds();

                    gameMode.SetShieldRemainingSeconds(0);
                    gameMode.SetGuardRemainingSeconds(guardTime);
                    gameMode.SetPersonalBreakCooldownSeconds(LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds());

                    level.GetHome().GetChangeListener().ShieldActivated(0, guardTime);
                }

                return(0);
            }

            return(-32);
        }
Exemplo n.º 8
0
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                if (this.m_gameObjectId != 0)
                {
                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1);
                    LogicGameObject        gameObject        = gameObjectManager.GetGameObjectByID(this.m_gameObjectId);

                    if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)gameObject;

                        if (this.m_unitData != null && level.GetGameMode().GetCalendar().IsProductionEnabled(this.m_unitData))
                        {
                            if (this.m_unitData.GetVillageType() == 1)
                            {
                                LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent();

                                if (village2UnitComponent != null)
                                {
                                    if (this.m_unitData.IsUnlockedForProductionHouseLevel(gameObjectManager.GetHighestBuildingLevel(this.m_unitData.GetProductionHouseData(), true))
                                        )
                                    {
                                        LogicClientAvatar playerAvatar  = level.GetPlayerAvatar();
                                        LogicResourceData trainResource = this.m_unitData.GetTrainingResource();
                                        int trainCost = this.m_unitData.GetTrainingCost(playerAvatar.GetUnitUpgradeLevel(this.m_unitData));

                                        if (playerAvatar.HasEnoughResources(trainResource, trainCost, true, this, false))
                                        {
                                            village2UnitComponent.TrainUnit(this.m_unitData);
                                            playerAvatar.CommodityCountChangeHelper(0, trainResource, -trainCost);
                                        }

                                        return(0);
                                    }

                                    return(-7);
                                }

                                return(-4);
                            }

                            return(-8);
                        }
                    }

                    return(-5);
                }

                return(-1);
            }

            return(-10);
        }
        /// <summary>
        ///     Trains the unit with new training.
        /// </summary>
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (this._unitData != null)
                {
                    LogicUnitProduction unitProduction = this._unitData.GetCombatItemType() == 1
                        ? level.GetGameObjectManager().GetSpellProduction()
                        : level.GetGameObjectManager().GetUnitProduction();

                    if (!unitProduction.IsLocked())
                    {
                        if (this._unitCount > 0)
                        {
                            if (this._unitData.GetDataType() == unitProduction.GetUnitProductionType())
                            {
                                LogicClientAvatar playerAvatar         = level.GetPlayerAvatar();
                                LogicResourceData trainingResourceData = this._unitData.GetTrainingResource();
                                Int32             trainingCost         = level.GetGameMode().GetCalendar().GetUnitTrainingCost(this._unitData, playerAvatar.GetUnitUpgradeLevel(this._unitData));
                                Int32             refundCount          = LogicMath.Max(trainingCost * (this._unitData.GetDataType() != 3
                                                                      ? LogicDataTables.GetGlobals().GetSpellCancelMultiplier()
                                                                      : LogicDataTables.GetGlobals().GetTrainCancelMultiplier()) / 100, 0);

                                while (unitProduction.RemoveUnit(this._unitData, this._slotId))
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, trainingResourceData, refundCount);

                                    if (--this._unitCount <= 0)
                                    {
                                        break;
                                    }
                                }

                                return(0);
                            }
                        }

                        return(-1);
                    }

                    return(-23);
                }

                return(-1);
            }

            return(-99);
        }
        public override int Execute(LogicLevel level)
        {
            if (level.GetGameMode().GetState() == 1)
            {
                LogicAvatar avatar = level.GetHomeOwnerAvatar();

                if (avatar != null)
                {
                    if (this.m_deliverableBundle != null)
                    {
                        if (this.m_billingPackageData != null)
                        {
                            LogicDeliveryHelper.Deliver(level, this.m_deliverableBundle);
                            LogicOffer offer = level.GetOfferManager().GetOfferById(this.m_offerId);

                            if (offer != null)
                            {
                                offer.SetState(4);
                                offer.AddPayCount(1);
                            }

                            /*else
                             * {
                             *  Debugger.Warning(string.Format("Delivering offerUid:{0}. Offer was no longer found.", this.m_offerId));
                             * }*/

                            return(0);
                        }

                        return(-4);
                    }

                    return(-3);
                }

                return(-2);
            }

            return(-1);
        }
Exemplo n.º 11
0
        public override void LoadFromSnapshot(LogicJSONObject jsonObject)
        {
            LogicLevel    level    = this.m_parent.GetLevel();
            LogicGameMode gameMode = level.GetGameMode();

            if (gameMode.GetVisitType() == 1 ||
                gameMode.GetVisitType() == 4 ||
                gameMode.GetVisitType() == 5)
            {
                int idx = 7;

                if (gameMode.GetVisitType() != 4 || !level.IsArrangedWar())
                {
                    int warLayout = level.GetWarLayout();

                    if (warLayout < 0 || !level.IsWarBase())
                    {
                        idx = level.GetActiveLayout();
                    }
                    else
                    {
                        idx = warLayout;
                    }
                }

                LogicJSONNumber xNumber = jsonObject.GetJSONNumber(this.GetLayoutVariableNameX(idx, false));
                LogicJSONNumber yNumber = jsonObject.GetJSONNumber(this.GetLayoutVariableNameY(idx, false));

                if (xNumber != null && yNumber != null)
                {
                    this.m_parent.SetInitialPosition(xNumber.GetIntValue() << 9, yNumber.GetIntValue() << 9);
                    Debugger.DoAssert(idx < 8, "Layout index out of bands");
                    this.m_layoutPosition[idx].Set(xNumber.GetIntValue(), yNumber.GetIntValue());
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (this.m_data != null && !level.IsAttackerHeroPlaced(this.m_data))
                {
                    if (level.GetVillageType() == this.m_data.GetVillageType())
                    {
                        int tileX = this.m_x >> 9;
                        int tileY = this.m_y >> 9;

                        if (level.GetTileMap().GetTile(tileX, tileY) != null)
                        {
                            if (level.GetTileMap().IsPassablePathFinder(this.m_x >> 8, this.m_y >> 8))
                            {
                                if (level.GetTileMap().IsValidAttackPos(tileX, tileY))
                                {
                                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                    if (playerAvatar != null)
                                    {
                                        if (playerAvatar.IsHeroAvailableForAttack(this.m_data))
                                        {
                                            if (level.GetBattleLog() != null)
                                            {
                                                if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                                {
                                                    level.UpdateLastUsedArmy();
                                                }
                                            }

                                            if (level.GetGameMode().IsInAttackPreparationMode())
                                            {
                                                level.GetGameMode().EndAttackPreparation();
                                            }

                                            int health   = playerAvatar.GetHeroHealth(this.m_data);
                                            int upgLevel = playerAvatar.GetUnitUpgradeLevel(this.m_data);

                                            level.SetAttackerHeroPlaced(this.m_data,
                                                                        LogicPlaceHeroCommand.PlaceHero(this.m_data, level, this.m_x, this.m_y,
                                                                                                        this.m_data.GetHeroHitpoints(health, upgLevel), upgLevel));

                                            return(0);
                                        }
                                    }

                                    return(-5);
                                }

                                return(-4);
                            }

                            return(-2);
                        }

                        return(-3);
                    }

                    return(-23);
                }

                return(-5);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            this.m_level = level;

            if (LogicDataTables.GetGlobals().EnablePresets())
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetEnablePresetsTownHallLevel())
                {
                    if (this.m_presetId <= 3)
                    {
                        LogicDataTable        table            = LogicDataTables.GetTable(LogicDataType.CHARACTER);
                        LogicComponentManager componentManager = level.GetComponentManager();

                        int totalMaxHousing = componentManager.GetTotalMaxHousing(0);

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

                            if (level.GetGameMode().GetCalendar().IsProductionEnabled(data) && !data.IsSecondaryTroop())
                            {
                                int count = 0;

                                if (this.m_slots.Size() > 0)
                                {
                                    for (int j = 0; j < this.m_slots.Size(); j++)
                                    {
                                        if (this.m_slots[j].GetData() == data)
                                        {
                                            count = this.m_slots[j].GetCount();
                                            break;
                                        }
                                    }
                                }

                                housingSpace += count * data.GetHousingSpace();

                                if (housingSpace > totalMaxHousing || !this.IsUnlocked(data))
                                {
                                    this.SetUnitPresetCount(data, 0);
                                }
                                else
                                {
                                    this.SetUnitPresetCount(data, count);
                                }
                            }
                        }

                        table           = LogicDataTables.GetTable(LogicDataType.SPELL);
                        totalMaxHousing = componentManager.GetTotalMaxHousing(0);

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

                            if (level.GetGameMode().GetCalendar().IsProductionEnabled(data))
                            {
                                int count = 0;

                                if (this.m_slots.Size() > 0)
                                {
                                    for (int j = 0; j < this.m_slots.Size(); j++)
                                    {
                                        if (this.m_slots[j].GetData() == data)
                                        {
                                            count = this.m_slots[j].GetCount();
                                            break;
                                        }
                                    }
                                }

                                housingSpace += count * data.GetHousingSpace();

                                if (housingSpace > totalMaxHousing || !this.IsUnlocked(data))
                                {
                                    this.SetUnitPresetCount(data, 0);
                                }
                                else
                                {
                                    this.SetUnitPresetCount(data, count);
                                }
                            }
                        }

                        return(0);
                    }

                    return(-2);
                }
            }

            return(-1);
        }
Exemplo n.º 14
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (level.GetVillageType() == 0)
                {
                    if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                    {
                        if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9))
                        {
                            return(-2);
                        }
                    }
                    else
                    {
                        LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9);

                        if (tile == null)
                        {
                            return(-4);
                        }

                        if (tile.GetPassableFlag() == 0)
                        {
                            return(-3);
                        }
                    }

                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar != null)
                    {
                        if (this.m_data != null)
                        {
                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                            if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0)
                            {
                                LogicAlliancePortal  alliancePortal  = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType());
                                LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent();

                                alliancePortal.SetInitialPosition(this.m_x, this.m_y);

                                if (bunkerComponent != null)
                                {
                                    bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity());

                                    if (level.GetBattleLog() != null)
                                    {
                                        if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                        {
                                            level.UpdateLastUsedArmy();
                                        }
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    bunkerComponent.RemoveAllUnits();

                                    LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits();

                                    for (int i = 0; i < allianceUnits.Size(); i++)
                                    {
                                        LogicUnitSlot       slot = allianceUnits[i];
                                        LogicCombatItemData data = (LogicCombatItemData)slot.GetData();

                                        if (data != null)
                                        {
                                            int count = slot.GetCount();

                                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                                    {
                                                        bunkerComponent.AddUnitImpl(data, slot.GetLevel());
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character");
                                        }
                                    }
                                }

                                gameObjectManager.AddGameObject(alliancePortal, -1);

                                return(0);
                            }
                        }
                    }

                    return(-5);
                }
            }

            return(-1);
        }
Exemplo n.º 15
0
 public override int Execute(LogicLevel level)
 {
     level.GetGameMode().GetCalendar().SetEventSeenTime(this.m_timestamp);
     return(0);
 }
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (this.m_trainCount <= 100)
                {
                    LogicUnitProduction unitProduction = this.m_unitType == 1
                        ? level.GetGameObjectManagerAt(0).GetSpellProduction()
                        : level.GetGameObjectManagerAt(0).GetUnitProduction();

                    if (this.m_trainCount > 0)
                    {
                        if (this.m_unitData != null)
                        {
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            bool firstLoopExecuted = false;
                            int  trainingCost      = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, playerAvatar.GetUnitUpgradeLevel(this.m_unitData));

                            for (int i = 0; i < this.m_trainCount; i++)
                            {
                                if (!unitProduction.CanAddUnitToQueue(this.m_unitData, false))
                                {
                                    if (firstLoopExecuted)
                                    {
                                        break;
                                    }

                                    return(-40);
                                }

                                if (!playerAvatar.HasEnoughResources(this.m_unitData.GetTrainingResource(), trainingCost, true, this, false))
                                {
                                    if (firstLoopExecuted)
                                    {
                                        break;
                                    }

                                    return(-30);
                                }

                                playerAvatar.CommodityCountChangeHelper(0, this.m_unitData.GetTrainingResource(), -trainingCost);

                                if (this.m_slotId == -1)
                                {
                                    this.m_slotId = unitProduction.GetSlotCount();
                                }

                                unitProduction.AddUnitToQueue(this.m_unitData, this.m_slotId, false);
                                firstLoopExecuted = true;
                            }

                            return(0);
                        }
                    }

                    return(-50);
                }

                Debugger.Error("LogicTraingUnitCommand - Count is too high");

                return(-20);
            }

            return(-99);
        }
Exemplo n.º 17
0
        /// <summary>
        ///     Adjusts the end subtick of timer.
        /// </summary>
        public void AdjustEndSubtick(LogicLevel level)
        {
            if (this._endTimestamp != -1)
            {
                int currentTime = LogicDataTables.GetGlobals().AdjustEndSubtickUseCurrentTime() ? level.GetGameMode().GetActiveTimestamp() : level.GetGameMode().GetCurrentTimestamp();

                if (currentTime != -1)
                {
                    int passedTime = this._endTimestamp - currentTime;
                    int clamp      = LogicDataTables.GetGlobals().GetClampLongTimeStampsToDays();

                    if (clamp * 86400 > 0)
                    {
                        if (passedTime > 86400 * clamp)
                        {
                            passedTime = 86400 * clamp;
                        }
                        else if (passedTime < -86400 * clamp)
                        {
                            passedTime = -86400 * clamp;
                        }
                    }

                    this._remainingTime = level.GetLogicTime() + (LogicDataTables.GetGlobals().MoreAccurateTime() ? (int)(1000L * passedTime / 16) : 60 * passedTime);
                }
            }
        }
Exemplo n.º 18
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                int tileX = this.m_x >> 9;
                int tileY = this.m_y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    if (level.GetTileMap().IsPassablePathFinder(this.m_x >> 8, this.m_y >> 8))
                    {
                        if (level.GetTileMap().IsValidAttackPos(tileX, tileY))
                        {
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            if (playerAvatar != null)
                            {
                                int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this.m_data) : playerAvatar.GetUnitCount(this.m_data);

                                if (unitCount > 0)
                                {
                                    if (level.GetBattleLog() != null)
                                    {
                                        if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                        {
                                            level.UpdateLastUsedArmy();
                                        }
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this.m_data, level, this.m_x, this.m_y);

                                    if (character != null && character.HasSpecialAbility())
                                    {
                                        if (this.m_data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_START_RAGE)
                                        {
                                            LogicSpellData specialAbilitySpellData = this.m_data.GetSpecialAbilitySpell();

                                            level.BoostGameObject(character, specialAbilitySpellData.GetSpeedBoost(0), specialAbilitySpellData.GetSpeedBoost2(0),
                                                                  specialAbilitySpellData.GetDamageBoostPercent(0), specialAbilitySpellData.GetAttackSpeedBoost(0),
                                                                  60 * this.m_data.GetSpecialAbilityAttribute(character.GetUpgradeLevel()),
                                                                  specialAbilitySpellData.GetBoostLinkedToPoison());
                                        }
                                        else if (this.m_data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_START_CLOAK)
                                        {
                                            character.SetStealthTime(15 * this.m_data.GetSpecialAbilityAttribute(character.GetUpgradeLevel()));
                                        }
                                    }

                                    return(0);
                                }

                                return(-7);
                            }

                            return(-5);
                        }

                        return(-4);
                    }

                    return(-2);
                }

                return(-3);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_trapData != null)
            {
                if (this.m_trapData.GetVillageType() == level.GetVillageType())
                {
                    if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_trapData.GetWidth(), this.m_trapData.GetHeight(), null))
                    {
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                        LogicResourceData buildResourceData = this.m_trapData.GetBuildResource();

                        int buildCost = this.m_trapData.GetBuildCost(0);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsTrapCapReached(this.m_trapData, true))
                        {
                            if (level.GetGameMode().GetCalendar().IsEnabled(this.m_trapData))
                            {
                                if (buildResourceData.IsPremiumCurrency())
                                {
                                    playerAvatar.UseDiamonds(buildCost);
                                    playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_trapData.GetGlobalID(), 0, buildCost, level.GetVillageType());
                                }
                                else
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                }

                                LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this.m_trapData, level, level.GetVillageType());

                                if (this.m_trapData.GetBuildTime(0) == 0)
                                {
                                    trap.FinishConstruction(false);
                                }

                                trap.SetInitialPosition(this.m_x << 9, this.m_y << 9);
                                level.GetGameObjectManager().AddGameObject(trap, -1);

                                if (level.IsTrapCapReached(this.m_trapData, false))
                                {
                                    level.GetGameListener().TrapCapReached(this.m_trapData);
                                }

                                int width  = trap.GetWidthInTiles();
                                int height = trap.GetHeightInTiles();

                                for (int i = 0; i < width; i++)
                                {
                                    for (int j = 0; j < height; j++)
                                    {
                                        LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass();

                                        if (tallGrass != null)
                                        {
                                            level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                        }
                                    }
                                }

                                return(0);
                            }
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_shieldData != null)
            {
                int cooldownSecs = level.GetCooldownManager().GetCooldownSeconds(this.m_shieldData.GetGlobalID());

                if (cooldownSecs <= 0)
                {
                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (this.m_shieldData.GetScoreLimit() > playerAvatar.GetScore() || this.m_shieldData.GetScoreLimit() <= 0)
                    {
                        if (playerAvatar.HasEnoughDiamonds(this.m_shieldData.GetDiamondsCost(), true, level))
                        {
                            LogicGameMode gameMode = level.GetGameMode();

                            playerAvatar.UseDiamonds(this.m_shieldData.GetDiamondsCost());
                            playerAvatar.GetChangeListener().DiamondPurchaseMade(6, this.m_shieldData.GetGlobalID(), this.m_shieldData.GetTimeHours() * 3600,
                                                                                 this.m_shieldData.GetDiamondsCost(), level.GetVillageType());

                            int shieldTime    = gameMode.GetShieldRemainingSeconds() + this.m_shieldData.GetTimeHours() * 3600;
                            int guardTime     = gameMode.GetGuardRemainingSeconds();
                            int personalBreak = 0;

                            if (this.m_shieldData.GetTimeHours() <= 0)
                            {
                                if (shieldTime > 0)
                                {
                                    return(-2);
                                }

                                guardTime += this.m_shieldData.GetGuardTimeHours() * 3600;
                            }
                            else
                            {
                                LogicLeagueData leagueData = playerAvatar.GetLeagueTypeData();

                                if (playerAvatar.GetAttackShieldReduceCounter() != 0)
                                {
                                    playerAvatar.SetAttackShieldReduceCounter(0);
                                    playerAvatar.GetChangeListener().AttackShieldReduceCounterChanged(0);
                                }

                                if (playerAvatar.GetDefenseVillageGuardCounter() != 0)
                                {
                                    playerAvatar.SetDefenseVillageGuardCounter(0);
                                    playerAvatar.GetChangeListener().DefenseVillageGuardCounterChanged(0);
                                }

                                guardTime += leagueData.GetVillageGuardInMins() * 60;
                            }

                            if (shieldTime <= 0)
                            {
                                personalBreak = LogicMath.Min(LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds() + this.m_shieldData.GetGuardTimeHours() * 3600,
                                                              gameMode.GetPersonalBreakCooldownSeconds() + this.m_shieldData.GetGuardTimeHours() * 3600);
                            }
                            else
                            {
                                personalBreak = shieldTime + LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds();
                            }

                            gameMode.SetPersonalBreakCooldownSeconds(personalBreak);
                            gameMode.SetShieldRemainingSeconds(shieldTime);
                            gameMode.SetGuardRemainingSeconds(guardTime);

                            level.GetHome().GetChangeListener().ShieldActivated(shieldTime, guardTime);
                            level.GetCooldownManager().AddCooldown(this.m_shieldData.GetGlobalID(), this.m_shieldData.GetCooldownSecs());

                            return(0);
                        }
                    }
                }
            }

            return(-1);
        }
Exemplo n.º 21
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                if (this.m_unitData != null)
                {
                    if (this.m_unitData.GetVillageType() == 0)
                    {
                        if (!this.m_unitData.IsDonationDisabled())
                        {
                            bool containsUnit = false;
                            int  upgLevel     = playerAvatar.GetUnitUpgradeLevel(this.m_unitData);

                            LogicUnitProductionComponent unitProductionComponent = null;

                            if (this.m_quickDonate)
                            {
                                int cost = this.m_unitData.GetDonateCost();

                                if (!playerAvatar.HasEnoughDiamonds(cost, true, level) || !LogicDataTables.GetGlobals().EnableQuickDonateWar())
                                {
                                    playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);
                                    return(0);
                                }
                            }
                            else
                            {
                                LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                                if (LogicDataTables.GetGlobals().UseNewTraining())
                                {
                                    LogicUnitProduction unitProduction  = gameObjectManager.GetUnitProduction();
                                    LogicUnitProduction spellProduction = gameObjectManager.GetSpellProduction();

                                    if (unitProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0)
                                    {
                                        if (unitProduction.GetUnitProductionType() == this.m_unitData.GetDataType())
                                        {
                                            containsUnit = true;
                                        }
                                    }

                                    if (spellProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0)
                                    {
                                        if (spellProduction.GetUnitProductionType() == this.m_unitData.GetDataType())
                                        {
                                            containsUnit = true;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0, c = gameObjectManager.GetNumGameObjects(); i < c; i++)
                                    {
                                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                                        if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding building = (LogicBuilding)gameObject;
                                            LogicUnitProductionComponent component = building.GetUnitProductionComponent();

                                            if (component != null)
                                            {
                                                unitProductionComponent = component;

                                                if (component.ContainsUnit(this.m_unitData))
                                                {
                                                    if (component.GetRemainingSeconds() == 0 && component.GetCurrentlyTrainedUnit() == this.m_unitData)
                                                    {
                                                        containsUnit = true;
                                                    }
                                                }
                                                else
                                                {
                                                    unitProductionComponent = null;
                                                }
                                            }
                                        }
                                    }
                                }

                                if (!containsUnit)
                                {
                                    if (playerAvatar.GetUnitCount(this.m_unitData) <= 0)
                                    {
                                        playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);
                                        return(0);
                                    }
                                }
                            }

                            if (this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                            {
                                playerAvatar.XpGainHelper(this.m_unitData.GetHousingSpace() * LogicDataTables.GetGlobals().GetDarkSpellDonationXP());
                                level.GetAchievementManager().AlianceSpellDonated((LogicSpellData)this.m_unitData);
                            }
                            else
                            {
                                playerAvatar.XpGainHelper(((LogicCharacterData)this.m_unitData).GetDonateXP());
                                level.GetAchievementManager().AlianceUnitDonated((LogicCharacterData)this.m_unitData);
                            }

                            playerAvatar.GetChangeListener().WarDonateOk(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);

                            if (this.m_quickDonate)
                            {
                                int cost = this.m_unitData.GetDonateCost();

                                playerAvatar.UseDiamonds(cost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(12, this.m_unitData.GetGlobalID(), 0, cost, level.GetVillageType());

                                if (level.GetState() == 1 || level.GetState() == 3 &&
                                    this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                {
                                    // TODO: Finish this.
                                }
                            }
                            else
                            {
                                if (!containsUnit)
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, this.m_unitData, -1);
                                }

                                LogicResourceData trainingResource = this.m_unitData.GetTrainingResource();
                                int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, upgLevel);
                                int refund       = playerAvatar.GetTroopDonationRefund() * trainingCost / 100;

                                playerAvatar.CommodityCountChangeHelper(0, trainingResource, LogicMath.Max(refund, 0));

                                if (level.GetState() == 1 || level.GetState() == 3)
                                {
                                    if (containsUnit)
                                    {
                                        if (LogicDataTables.GetGlobals().UseNewTraining())
                                        {
                                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                            LogicUnitProduction    unitProduction    = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER
                                                ? gameObjectManager.GetSpellProduction()
                                                : gameObjectManager.GetUnitProduction();

                                            unitProduction.RemoveTrainedUnit(this.m_unitData);
                                        }

                                        if (this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                        {
                                            LogicBuilding productionHouse = null;

                                            if (unitProductionComponent != null)
                                            {
                                                productionHouse = (LogicBuilding)unitProductionComponent.GetParent();
                                            }
                                            else
                                            {
                                                if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                                                {
                                                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                                    int gameObjectCount = gameObjectManager.GetNumGameObjects();

                                                    for (int i = 0; i < gameObjectCount; i++)
                                                    {
                                                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                                                        if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                                        {
                                                            LogicBuilding tmpBuilding = (LogicBuilding)gameObject;
                                                            LogicUnitProductionComponent tmpComponent = tmpBuilding.GetUnitProductionComponent();

                                                            if (tmpComponent != null)
                                                            {
                                                                if (tmpComponent.GetProductionType() == this.m_unitData.GetCombatItemType())
                                                                {
                                                                    if (tmpBuilding.GetBuildingData().GetProducesUnitsOfType() == this.m_unitData.GetUnitOfType() &&
                                                                        !tmpBuilding.IsUpgrading() &&
                                                                        !tmpBuilding.IsConstructing())
                                                                    {
                                                                        if (this.m_unitData.IsUnlockedForProductionHouseLevel(tmpBuilding.GetUpgradeLevel()))
                                                                        {
                                                                            if (productionHouse != null)
                                                                            {
                                                                                int seed = playerAvatar.GetExpPoints();

                                                                                if (tmpBuilding.Rand(seed) % 1000 > 750)
                                                                                {
                                                                                    productionHouse = tmpBuilding;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                productionHouse = tmpBuilding;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            if (productionHouse != null)
                                            {
                                                // TODO: Implement listener.
                                            }
                                        }
                                    }
                                    else
                                    {
                                        LogicArrayList <LogicComponent> components = level.GetComponentManagerAt(0).GetComponents(LogicComponentType.UNIT_STORAGE);

                                        for (int i = 0; i < components.Size(); i++)
                                        {
                                            LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[i];
                                            int idx = unitStorageComponent.GetUnitTypeIndex(this.m_unitData);

                                            if (idx != -1)
                                            {
                                                if (unitStorageComponent.GetUnitCount(idx) > 0)
                                                {
                                                    unitStorageComponent.RemoveUnits(this.m_unitData, 1);

                                                    if (LogicDataTables.GetGlobals().UseNewTraining())
                                                    {
                                                        LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                                        LogicUnitProduction    unitProduction    = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER
                                                            ? gameObjectManager.GetSpellProduction()
                                                            : gameObjectManager.GetUnitProduction();

                                                        unitProduction.MergeSlots();
                                                        unitProduction.UnitRemoved();
                                                    }

                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    // TODO: Finish this.
                                }
                            }

                            return(0);
                        }

                        return(-91);
                    }

                    return(-45);
                }
            }

            return(0);
        }
Exemplo n.º 22
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._shieldData != null)
            {
                int cooldownSecs = level.GetCooldownManager().GetCooldownSeconds(this._shieldData.GetGlobalID());

                if (cooldownSecs <= 0)
                {
                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (this._shieldData.GetScoreLimit() > playerAvatar.GetScore() || this._shieldData.GetScoreLimit() <= 0)
                    {
                        if (playerAvatar.HasEnoughDiamonds(this._shieldData.GetDiamondsCost(), true, level))
                        {
                            LogicGameMode gameMode = level.GetGameMode();

                            playerAvatar.UseDiamonds(this._shieldData.GetDiamondsCost());

                            int shieldTime      = gameMode.GetShieldRemainingSeconds() + this._shieldData.TimeH * 3600;
                            int guardTime       = gameMode.GetGuardRemainingSeconds();
                            int maintenanceTime = 0;

                            if (this._shieldData.TimeH <= 0)
                            {
                                if (shieldTime > 0)
                                {
                                    return(-2);
                                }

                                guardTime += this._shieldData.GuardTimeH * 3600;
                            }
                            else
                            {
                                LogicLeagueData leagueData = playerAvatar.GetLeagueTypeData();

                                if (playerAvatar.GetShieldCostAmount() != 0)
                                {
                                    playerAvatar.SetShieldCostAmount(0);
                                }

                                guardTime += leagueData.VillageGuardInMins * 60;
                            }

                            if (shieldTime <= 0)
                            {
                                maintenanceTime = LogicMath.Min(LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds() + this._shieldData.GuardTimeH * 3600,
                                                                gameMode.GetMaintenanceRemainingSeconds() + this._shieldData.GuardTimeH * 3600);
                            }
                            else
                            {
                                maintenanceTime = shieldTime + LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds();
                            }

                            gameMode.SetMaintenanceRemainingSeconds(maintenanceTime);
                            gameMode.SetShieldRemainingSeconds(shieldTime);
                            gameMode.SetGuardRemainingSeconds(guardTime);

                            level.GetCooldownManager().AddCooldown(this._shieldData.GetGlobalID(), this._shieldData.GetCooldownSecs());

                            return(0);
                        }
                    }
                }
            }

            return(-1);
        }