コード例 #1
0
        public bool SpeedUp()
        {
            if (this.m_timer != null)
            {
                int remainingSecs = this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime());
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 0, this.m_parent.GetVillageType());

                LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsClientAvatar())
                {
                    LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;

                    if (clientAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_parent.GetLevel()))
                    {
                        clientAvatar.UseDiamonds(speedUpCost);
                        clientAvatar.GetChangeListener().DiamondPurchaseMade(10, this.m_hero.GetGlobalID(), clientAvatar.GetUnitUpgradeLevel(this.m_hero) + 1, speedUpCost,
                                                                             this.m_parent.GetLevel().GetVillageType());
                        this.FinishUpgrading(true);

                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #2
0
        public void IncrementDestroyedBuildingCount(LogicBuildingData data)
        {
            LogicBuildingClassData buildingClass = data.GetBuildingClass();

            if (buildingClass.IsTownHall() || buildingClass.IsTownHall2())
            {
                this.m_townhallDestroyed = true;
            }

            if (this.m_level != null)
            {
                LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
                {
                    if (this.m_level.GetState() == 2)
                    {
                        int matchType = this.m_level.GetMatchType();

                        if (matchType != 2 && matchType != 5)
                        {
                            this.m_level.GetAchievementManager().BuildingDestroyedInPvP(data);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public int GetSpeedUpHealthCost()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar.IsClientAvatar())
            {
                return(homeOwnerAvatar.GetHeroHealCost(this.m_hero));
            }

            return(0);
        }
コード例 #4
0
        /// <summary>
        ///     Recalculates the available loot.
        /// </summary>
        public void RecalculateAvailableLoot()
        {
            LogicAvatar homeOwnerAvatar = this._parent.GetLevel().GetHomeOwnerAvatar();

            if (!homeOwnerAvatar.IsNpcAvatar())
            {
                int matchType = this._parent.GetLevel().GetMatchType();

                if (matchType < 10)
                {
                    if (matchType == 0 ||
                        matchType == 2 ||
                        matchType >= 4 && matchType <= 6)
                    {
                        int resourceProductionLootPercentage = LogicDataTables.GetGlobals().GetResourceProductionLootPercentage(this._resourceData);

                        if (homeOwnerAvatar.IsClientAvatar())
                        {
                            if (this._parent.GetLevel().GetVisitorAvatar() != null)
                            {
                                LogicAvatar visitorAvatar = this._parent.GetLevel().GetVisitorAvatar();

                                if (visitorAvatar.IsClientAvatar())
                                {
                                    resourceProductionLootPercentage = resourceProductionLootPercentage *
                                                                       LogicDataTables.GetGlobals().GetLootMultiplierByTownHallDiff(visitorAvatar.GetTownHallLevel(),
                                                                                                                                    homeOwnerAvatar.GetTownHallLevel()) / 100;
                                }
                            }
                        }

                        if (resourceProductionLootPercentage > 100)
                        {
                            resourceProductionLootPercentage = 100;
                        }

                        this._availableLoot = this.GetResourceCount() * resourceProductionLootPercentage / 100;
                    }
                    else
                    {
                        this._availableLoot = 0;
                    }
                }
                else
                {
                    this._availableLoot = 0;
                }
            }
            else
            {
                this._availableLoot = 0;
            }
        }
コード例 #5
0
ファイル: LogicGameMode.cs プロジェクト: NotHuza/Cerberus-v4
        /// <summary>
        ///     Gets if the attacker is in attack preparation mode.
        /// </summary>
        public bool IsInAttackPreparationMode()
        {
            if (this._state == 2 || this._state == 5)
            {
                LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsClientAvatar())
                {
                    return(this.GetRemainingAttackSeconds() > LogicDataTables.GetGlobals().GetAttackLengthSecs());
                }
            }

            return(false);
        }
コード例 #6
0
        public void LoadDirectAttackState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int secondsSinceLastSave, bool war, bool village2,
                                          int currentTimestamp)
        {
            if (this.m_state != 0)
            {
                Debugger.Error("loadAttackState called from invalid state");
            }

            this.m_state          = 2;
            this.m_startTimestamp = currentTimestamp;
            this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON()));
            this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp);

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

            this.m_battleTimer = new LogicTimer();
            this.m_battleTimer.StartTimer(
                LogicDataTables.GetGlobals().GetAttackLengthSecs() + (village2
                    ? LogicDataTables.GetGlobals().GetAttackVillage2PreparationLengthSecs()
                    : LogicDataTables.GetGlobals().GetAttackPreparationLengthSecs()),
                this.m_level.GetLogicTime(), false, -1);

            if (!homeOwnerAvatar.IsClientAvatar())
            {
                Debugger.Error("loadDirectAttackState called and home owner is not client avatar");
            }

            this.m_level.SetMatchType(village2 ? 8 : war ? 7 : 3, null);

            if (village2)
            {
                this.m_level.SetVillageType(1);
            }

            this.m_level.SetHome(home, false);
            this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar);

            homeOwnerAvatar.SetLevel(this.m_level);

            this.m_level.SetVisitorAvatar(visitorAvatar);
            this.m_level.FastForwardTime(secondsSinceLastSave);
            this.m_level.LoadingFinished();
            this.m_replay = new LogicReplay(this.m_level);
        }
コード例 #7
0
        /// <summary>
        ///     Cancels the construction of trap.
        /// </summary>
        public void CancelConstruction()
        {
            LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
            {
                if (this._constructionTimer != null)
                {
                    this._constructionTimer.Destruct();
                    this._constructionTimer = null;

                    int upgLevel = this._upgLevel;

                    if (this._upgrading)
                    {
                        this.SetUpgradeLevel(this._upgLevel);
                        upgLevel += 1;
                    }

                    LogicTrapData     data = this.GetTrapData();
                    LogicResourceData buildResourceData = data.GetBuildResource();
                    Int32             buildCost         = data.GetBuildCost(upgLevel);
                    Int32             refundedCount     = LogicMath.Max(LogicDataTables.GetGlobals().GetBuildCancelMultiplier() * buildCost / 100, 0);
                    Debugger.Print("LogicTrap::cancelConstruction refunds: " + refundedCount);

                    homeOwnerAvatar.CommodityCountChangeHelper(0, buildResourceData, refundedCount);

                    this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this);

                    if (upgLevel != 0)
                    {
                        if (this._listener != null)
                        {
                            this._listener.RefreshState();
                        }
                    }
                    else
                    {
                        this.GetGameObjectManager().RemoveGameObject(this);
                    }
                }
            }
        }
コード例 #8
0
        public void ObstacleCleared()
        {
            LogicAvatar    homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
            LogicDataTable dataTable       = LogicDataTables.GetTable(LogicDataType.ACHIEVEMENT);

            if (homeOwnerAvatar != null)
            {
                if (homeOwnerAvatar.IsClientAvatar())
                {
                    LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;

                    for (int i = 0; i < dataTable.GetItemCount(); i++)
                    {
                        LogicAchievementData achievementData = (LogicAchievementData)dataTable.GetItemAt(i);

                        if (achievementData.GetActionType() == LogicAchievementData.ACTION_TYPE_CLEAR_OBSTACLES)
                        {
                            this.RefreshAchievementProgress(clientAvatar, achievementData, clientAvatar.GetAchievementProgress(achievementData) + 1);
                        }
                    }
                }
            }
        }
コード例 #9
0
        public bool SpeedUpHealth()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar.IsClientAvatar())
            {
                LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;
                int speedUpCost = this.GetSpeedUpHealthCost();

                if (clientAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_parent.GetLevel()))
                {
                    clientAvatar.UseDiamonds(speedUpCost);
                    clientAvatar.GetChangeListener().DiamondPurchaseMade(9, this.m_hero.GetGlobalID(), clientAvatar.GetUnitUpgradeLevel(this.m_hero) + 1, speedUpCost,
                                                                         this.m_parent.GetLevel().GetVillageType());

                    this.SetFullHealth();

                    return(true);
                }
            }

            return(false);
        }
コード例 #10
0
        public virtual void RecalculateAvailableLoot()
        {
            int matchType = this.m_parent.GetLevel().GetMatchType();

            LogicAvatar    homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
            LogicAvatar    visitorAvatar   = this.m_parent.GetLevel().GetVisitorAvatar();
            LogicDataTable resourceTable   = LogicDataTables.GetTable(LogicDataType.RESOURCE);

            for (int i = 0; i < this.m_resourceCount.Size(); i++)
            {
                LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);
                int resourceCount      = this.m_resourceCount[i];

                if (!homeOwnerAvatar.IsNpcAvatar())
                {
                    if (matchType == 5 && this.m_parent.GetLevel().IsArrangedWar())
                    {
                        if (resourceCount >= 0)
                        {
                            resourceCount = 0;
                        }
                    }
                    else if (LogicDataTables.GetGlobals().UseTownHallLootPenaltyInWar() || matchType != 5)
                    {
                        if (matchType != 8 && matchType != 9)
                        {
                            int multiplier = 100;
                            int calculateAvailableLootCount = 0;

                            if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar() &&
                                visitorAvatar != null && visitorAvatar.IsClientAvatar())
                            {
                                multiplier = LogicDataTables.GetGlobals().GetLootMultiplierByTownHallDiff(visitorAvatar.GetTownHallLevel(), homeOwnerAvatar.GetTownHallLevel());
                            }

                            if (this.m_parent.GetData() == LogicDataTables.GetTownHallData() && LogicDataTables.GetGlobals().GetTownHallLootPercentage() != -1)
                            {
                                calculateAvailableLootCount = resourceCount * (multiplier * LogicDataTables.GetGlobals().GetTownHallLootPercentage() / 100) / 100;
                            }
                            else if (!data.IsPremiumCurrency())
                            {
                                int townHallLevel         = homeOwnerAvatar.GetTownHallLevel();
                                int lootableResourceCount = 0;

                                if (matchType != 3)
                                {
                                    if (matchType == 5)
                                    {
                                        lootableResourceCount = resourceCount;
                                    }
                                    else if (matchType != 7)
                                    {
                                        lootableResourceCount = (int)((long)resourceCount * LogicDataTables.GetTownHallLevel(townHallLevel).GetStorageLootPercentage(data) / 100);
                                    }
                                }

                                int storageLootCap   = LogicDataTables.GetTownHallLevel(townHallLevel).GetStorageLootCap(data);
                                int maxResourceCount = LogicMath.Min(homeOwnerAvatar.GetResourceCount(data), homeOwnerAvatar.GetResourceCap(data));

                                if (maxResourceCount > storageLootCap && maxResourceCount > 0)
                                {
                                    int clampedValue;

                                    if (storageLootCap < 1000000)
                                    {
                                        if (storageLootCap < 100000)
                                        {
                                            if (storageLootCap < 10000)
                                            {
                                                if (storageLootCap < 1000)
                                                {
                                                    clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount;
                                                }
                                                else
                                                {
                                                    if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap())
                                                    {
                                                        clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount);
                                                    }
                                                    else
                                                    {
                                                        if (resourceCount / 100 > maxResourceCount / storageLootCap)
                                                        {
                                                            clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount);
                                                        }
                                                        else
                                                        {
                                                            clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount;
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap())
                                                {
                                                    clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount);
                                                }
                                                else
                                                {
                                                    if (resourceCount / 1000 > maxResourceCount / storageLootCap)
                                                    {
                                                        clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount);
                                                    }
                                                    else
                                                    {
                                                        if (resourceCount / 100 > maxResourceCount / storageLootCap)
                                                        {
                                                            clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount);
                                                        }
                                                        else
                                                        {
                                                            clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap())
                                            {
                                                clampedValue = 10000 * ((resourceCount * (storageLootCap / 10000) + (maxResourceCount >> 1)) / maxResourceCount);
                                            }
                                            else
                                            {
                                                if (resourceCount / 10000 > maxResourceCount / storageLootCap)
                                                {
                                                    clampedValue = 10000 * ((resourceCount * (storageLootCap / 10000) + (maxResourceCount >> 1)) / maxResourceCount);
                                                }
                                                else
                                                {
                                                    if (resourceCount / 1000 > maxResourceCount / storageLootCap)
                                                    {
                                                        clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount);
                                                    }
                                                    else
                                                    {
                                                        if (resourceCount / 100 > maxResourceCount / storageLootCap)
                                                        {
                                                            clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount);
                                                        }
                                                        else
                                                        {
                                                            clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        clampedValue = 40000 * ((resourceCount * (storageLootCap / 40000) + (maxResourceCount >> 1)) / maxResourceCount);
                                    }

                                    if (lootableResourceCount > clampedValue)
                                    {
                                        lootableResourceCount = clampedValue;
                                    }
                                }

                                calculateAvailableLootCount = multiplier * lootableResourceCount / 100;
                            }

                            if (calculateAvailableLootCount <= resourceCount)
                            {
                                resourceCount = calculateAvailableLootCount;
                            }
                        }
                    }
                }

                this.m_stealableResourceCount[i] = resourceCount;
            }
        }
コード例 #11
0
        public void ValidateTroopUpgradeLevels()
        {
            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                if (homeOwnerAvatar.IsClientAvatar())
                {
                    int[] laboratoryLevels = new int[2];

                    for (int i = 0; i < 2; i++)
                    {
                        LogicBuilding laboratory = this.m_level.GetGameObjectManagerAt(i).GetLaboratory();

                        if (laboratory != null)
                        {
                            laboratoryLevels[i] = laboratory.GetUpgradeLevel();
                        }
                    }

                    LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER);

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

                        int upgradeLevel    = homeOwnerAvatar.GetUnitUpgradeLevel(characterData);
                        int villageType     = characterData.GetVillageType();
                        int newUpgradeLevel = upgradeLevel;

                        if (upgradeLevel >= characterData.GetUpgradeLevelCount())
                        {
                            newUpgradeLevel = characterData.GetUpgradeLevelCount() - 1;
                        }

                        int laboratoryLevel = laboratoryLevels[villageType];
                        int requireLaboratoryLevel;

                        do
                        {
                            requireLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(newUpgradeLevel--);
                        } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel);

                        newUpgradeLevel += 1;

                        if (upgradeLevel > newUpgradeLevel)
                        {
                            homeOwnerAvatar.SetUnitUpgradeLevel(characterData, newUpgradeLevel);
                            homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, characterData, newUpgradeLevel);
                        }
                    }

                    LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL);

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

                        int upgradeLevel    = homeOwnerAvatar.GetUnitUpgradeLevel(spellData);
                        int villageType     = spellData.GetVillageType();
                        int newUpgradeLevel = upgradeLevel;

                        if (upgradeLevel >= spellData.GetUpgradeLevelCount())
                        {
                            newUpgradeLevel = spellData.GetUpgradeLevelCount() - 1;
                        }

                        int laboratoryLevel = laboratoryLevels[villageType];
                        int requireLaboratoryLevel;

                        do
                        {
                            requireLaboratoryLevel = spellData.GetRequiredLaboratoryLevel(newUpgradeLevel--);
                        } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel);

                        newUpgradeLevel += 1;

                        if (upgradeLevel > newUpgradeLevel)
                        {
                            homeOwnerAvatar.SetUnitUpgradeLevel(spellData, newUpgradeLevel);
                            homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, spellData, newUpgradeLevel);
                        }
                    }
                }
            }
        }
コード例 #12
0
        /// <summary>
        ///     Finishes the construction of the <see cref="LogicBuilding"/>.
        /// </summary>
        public void FinishConstruction(bool ignoreState)
        {
            int state = this._level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
                {
                    LogicTrapData data = this.GetTrapData();

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

                    this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this);

                    if (this._upgLevel != 0 || this._upgrading)
                    {
                        if (this._upgLevel >= data.GetUpgradeLevelCount() - 1)
                        {
                            Debugger.Warning("LogicTrap - Trying to upgrade to level that doesn't exist! - " + data.GetName());
                            this._upgLevel = data.GetUpgradeLevelCount() - 1;
                        }
                        else
                        {
                            this._upgLevel += 1;
                        }
                    }

                    if (!ignoreState && !this._disarmed)
                    {
                        if (this.GetListener() != null)
                        {
                            // Listener.
                        }
                    }

                    this.XpGainHelper(LogicGamePlayUtil.TimeToExp(data.GetBuildTime(this._upgLevel)), homeOwnerAvatar, ignoreState);

                    if (this._disarmed)
                    {
                        // Listener.
                    }

                    this._fadeTime  = 0;
                    this._disarmed  = false;
                    this._upgrading = false;

                    if (this._listener != null)
                    {
                        this._listener.RefreshState();
                    }

                    if (state == 1)
                    {
                        this._level.GetAchievementManager().RefreshStatus();
                    }
                }
                else
                {
                    Debugger.Warning("LogicTrap::finishCostruction failed - Avatar is null or not client avatar");
                }
            }
        }
コード例 #13
0
        public void SetBattleOver()
        {
            if (this.m_battleOver)
            {
                return;
            }

            this.m_level.GetBattleLog().SetBattleEnded(LogicDataTables.GetGlobals().GetAttackLengthSecs() - this.GetRemainingAttackSeconds());
            this.m_level.GetMissionManager().Tick();

            LogicArrayList <LogicComponent> components = this.m_level.GetComponentManager().GetComponents(LogicComponentType.COMBAT);

            for (int i = 0; i < components.Size(); i++)
            {
                ((LogicCombatComponent)components[i]).Boost(0, 0, 0);
            }

            bool duelMatch = (this.m_level.GetMatchType() & 0xFFFFFFFE) == 8;

            if (duelMatch)
            {
                LogicAvatar avatar = this.m_level.GetVisitorAvatar();

                if (avatar != null && avatar.IsClientAvatar())
                {
                    ((LogicClientAvatar)avatar).RemoveUnitsVillage2();
                }
            }

            if (this.m_state == 3)
            {
                this.EndDefendState();
            }
            else
            {
                LogicBattleLog battleLog = this.m_level.GetBattleLog();

                if (battleLog.GetBattleStarted())
                {
                    LogicAvatar visitorAvatar   = this.m_level.GetVisitorAvatar();
                    LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                    int stars = battleLog.GetStars();

                    if (!this.m_level.GetVisitorAvatar().IsClientAvatar() || !this.m_level.GetHomeOwnerAvatar().IsClientAvatar())
                    {
                        if (visitorAvatar.IsClientAvatar() && homeOwnerAvatar.IsNpcAvatar())
                        {
                            LogicNpcAvatar npcAvatar = (LogicNpcAvatar)homeOwnerAvatar;
                            LogicNpcData   npcData   = npcAvatar.GetNpcData();

                            int npcStars = visitorAvatar.GetNpcStars(npcData);

                            if (stars > npcStars && npcData.IsSinglePlayer())
                            {
                                visitorAvatar.SetNpcStars(npcData, stars);
                                visitorAvatar.GetChangeListener().CommodityCountChanged(0, npcData, stars);
                            }

                            // TODO: LogicBattleLog::sendNpcAttackEndEvents.
                        }
                    }
                    else
                    {
                        LogicClientAvatar attacker = (LogicClientAvatar)visitorAvatar;
                        LogicClientAvatar defender = (LogicClientAvatar)homeOwnerAvatar;

                        int originalAttackerScore = attacker.GetScore();
                        int originalDefenderScore = defender.GetScore();
                        int matchType             = this.m_level.GetMatchType();

                        if (matchType == 1 || !LogicDataTables.GetGlobals().ScoringOnlyFromMatchedMode() && (matchType == 0 || matchType == 2 || matchType == 4 || matchType == 6))
                        {
                            LogicGamePlayUtil.CalculateCombatScore(attacker, defender, stars, false,
                                                                   matchType == 4, battleLog.GetDestructionPercentage(), this.m_calendar.GetStarBonusMultiplier(), duelMatch);

                            if (!duelMatch && homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetLootCartEnabledTownHall())
                            {
                                LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE);

                                if (resourceTable.GetItemCount() > 0)
                                {
                                    bool hasStolen = false;

                                    for (int i = 0; i < resourceTable.GetItemCount(); i++)
                                    {
                                        LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);

                                        if (!data.IsPremiumCurrency())
                                        {
                                            if (battleLog.GetStolenResources(data) > 0)
                                            {
                                                hasStolen = true;
                                            }
                                        }
                                    }

                                    if (hasStolen)
                                    {
                                        LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
                                        LogicObstacle          lootCart          = gameObjectManager.GetLootCart();

                                        if (lootCart == null)
                                        {
                                            gameObjectManager.AddLootCart();
                                            lootCart = gameObjectManager.GetLootCart();
                                        }

                                        if (lootCart != null)
                                        {
                                            LogicLootCartComponent lootCartComponent = lootCart.GetLootCartComponent();

                                            if (lootCartComponent != null)
                                            {
                                                for (int i = 0; i < resourceTable.GetItemCount(); i++)
                                                {
                                                    LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);

                                                    if (!data.IsPremiumCurrency() && data.GetWarResourceReferenceData() == null)
                                                    {
                                                        int lootPercentage = lootCart.GetObstacleData().GetLootDefensePercentage();
                                                        int lootCount      = battleLog.GetStolenResources(data) * lootPercentage / 100;

                                                        lootCartComponent.SetResourceCount(i,
                                                                                           LogicMath.Min(LogicMath.Max(lootCount, lootCartComponent.GetResourceCount(i)),
                                                                                                         lootCartComponent.GetCapacityCount(i)));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            this.m_level.UpdateBattleShieldStatus(false);

                            if (stars > 0)
                            {
                                LogicArrayList <LogicDataSlot> castedUnits         = battleLog.GetCastedUnits();
                                LogicArrayList <LogicDataSlot> castedSpells        = battleLog.GetCastedSpells();
                                LogicArrayList <LogicUnitSlot> castedAllianceUnits = battleLog.GetCastedAllianceUnits();

                                LogicArrayList <LogicDataSlot> placedUnits = new LogicArrayList <LogicDataSlot>(castedUnits.Size());

                                for (int i = 0; i < castedUnits.Size(); i++)
                                {
                                    placedUnits.Add(new LogicDataSlot(castedUnits[i].GetData(), castedUnits[i].GetCount()));
                                }

                                for (int i = 0; i < castedSpells.Size(); i++)
                                {
                                    int idx = -1;

                                    for (int j = 0; j < placedUnits.Size(); j++)
                                    {
                                        if (placedUnits[j].GetData() == castedSpells[i].GetData())
                                        {
                                            idx = j;
                                            break;
                                        }
                                    }

                                    if (idx != -1)
                                    {
                                        placedUnits[idx].SetCount(placedUnits[idx].GetCount() + castedSpells[i].GetCount());
                                    }
                                    else
                                    {
                                        placedUnits.Add(new LogicDataSlot(castedSpells[i].GetData(), castedSpells[i].GetCount()));
                                    }
                                }

                                for (int i = 0; i < castedAllianceUnits.Size(); i++)
                                {
                                    placedUnits.Add(new LogicDataSlot(castedAllianceUnits[i].GetData(), castedAllianceUnits[i].GetCount()));
                                }

                                for (int i = 0; i < placedUnits.Size(); i++)
                                {
                                    LogicCombatItemData   data = (LogicCombatItemData)placedUnits[i].GetData();
                                    LogicCalendarUseTroop calendarUseTroopEvent = this.m_calendar.GetUseTroopEvents(data);

                                    if (calendarUseTroopEvent != null)
                                    {
                                        int count = attacker.GetEventUnitCounterCount(data);

                                        if (placedUnits[i].GetCount() >= count >> 16)
                                        {
                                            int progressCount = (short)count + 1;
                                            int eventCounter  = progressCount | (int)(count & 0xFFFF0000);

                                            attacker.SetCommodityCount(6, data, eventCounter);
                                            attacker.GetChangeListener().CommodityCountChanged(6, data, eventCounter);

                                            if (calendarUseTroopEvent.GetParameter(0) == progressCount)
                                            {
                                                int diamonds = calendarUseTroopEvent.GetParameter(2);
                                                int xp       = calendarUseTroopEvent.GetParameter(3);

                                                attacker.XpGainHelper(xp);
                                                attacker.SetDiamonds(attacker.GetDiamonds() + diamonds);
                                                attacker.SetFreeDiamonds(attacker.GetFreeDiamonds() + diamonds);
                                                attacker.GetChangeListener().FreeDiamondsAdded(diamonds, 9);

                                                Debugger.HudPrint(string.Format("USE TROOP Event: Awarding XP: {0} GEMS {1}", xp, diamonds));
                                            }
                                        }
                                    }
                                }

                                for (int i = 0; i < placedUnits.Size(); i++)
                                {
                                    placedUnits[i].Destruct();
                                }

                                placedUnits.Destruct();
                            }
                        }

                        if (this.m_state != 5 &&
                            this.m_level.GetDefenseShieldActivatedHours() == 0 &&
                            battleLog.GetDestructionPercentage() > 0)
                        {
                            int defenseVillageGuardCounter = defender.GetDefenseVillageGuardCounter() + 1;

                            defender.SetDefenseVillageGuardCounter(defenseVillageGuardCounter);
                            defender.GetChangeListener().DefenseVillageGuardCounterChanged(defenseVillageGuardCounter);

                            int villageGuardMins = (defenseVillageGuardCounter & 0xFFFFFF) == 3 * ((defenseVillageGuardCounter & 0xFFFFFF) / 3)
                                ? defender.GetLeagueTypeData().GetVillageGuardInMins()
                                : LogicDataTables.GetGlobals().GetDefaultDefenseVillageGuard();

                            this.m_level.GetHome().GetChangeListener().GuardActivated(60 * villageGuardMins);

                            Debugger.HudPrint(string.Format("Battle end. No Shield, Village Guard for defender: {0}", villageGuardMins));
                        }

                        battleLog.SetAttackerScore(attacker.GetScore() - originalAttackerScore);
                        battleLog.SetDefenderScore(defender.GetScore() - originalDefenderScore);
                        battleLog.SetOriginalAttackerScore(originalAttackerScore);
                        battleLog.SetOriginalDefenderScore(originalDefenderScore);

                        if (this.m_state != 5)
                        {
                            if (stars != 0)
                            {
                                if (matchType != 3 && matchType != 7 && matchType != 8 && matchType != 9)
                                {
                                    if (matchType == 5)
                                    {
                                        if (stars > this.m_level.GetPreviousAttackStars() && !this.m_level.GetIgnoreAttack())
                                        {
                                            this.m_level.GetAchievementManager().IncreaseWarStars(stars);
                                        }
                                    }
                                    else
                                    {
                                        this.m_level.GetAchievementManager().PvpAttackWon();
                                    }
                                }
                            }
                            else if (matchType > 9 || matchType == 3 || matchType == 5 || matchType == 7 || matchType == 8 || matchType == 9)
                            {
                                this.m_level.GetAchievementManager().PvpDefenseWon();
                            }
                        }
                    }
                }
            }

            this.m_battleOver = true;
        }