コード例 #1
0
        public override void ApplyAvatarChange(LogicClientAvatar avatar)
        {
            LogicLegendSeasonEntry legendSeasonEntry = this.VillageType == 1 ? avatar.GetLegendSeasonEntryVillage2() : avatar.GetLegendSeasonEntry();

            if (legendSeasonEntry.GetLastSeasonState() != this.Entry.GetLastSeasonState())
            {
                if (this.VillageType == 1)
                {
                    avatar.SetDuelScore(avatar.GetDuelScore() - this.ScoreChange);
                    avatar.SetLegendaryScore(avatar.GetLegendaryScoreVillage2() + this.ScoreChange);
                }
                else
                {
                    avatar.SetScore(avatar.GetScore() - this.ScoreChange);
                    avatar.SetLegendaryScore(avatar.GetLegendaryScore() + this.ScoreChange);
                }

                legendSeasonEntry.SetLastSeasonState(this.Entry.GetLastSeasonState());
                legendSeasonEntry.SetLastSeasonDate(this.Entry.GetLastSeasonYear(), this.Entry.GetLastSeasonMonth());
                legendSeasonEntry.SetLastSeasonRank(this.Entry.GetLastSeasonRank());
                legendSeasonEntry.SetLastSeasonScore(this.Entry.GetLastSeasonScore());

                if (this.BestSeason)
                {
                    legendSeasonEntry.SetBestSeasonState(this.Entry.GetBestSeasonState());
                    legendSeasonEntry.SetBestSeasonDate(this.Entry.GetBestSeasonYear(), this.Entry.GetBestSeasonMonth());
                    legendSeasonEntry.SetBestSeasonRank(this.Entry.GetBestSeasonRank());
                    legendSeasonEntry.SetBestSeasonScore(this.Entry.GetBestSeasonScore());
                }
            }
        }
コード例 #2
0
        public override void ApplyAvatarChange(LogicClientAvatar avatar)
        {
            avatar.SetScore(LogicMath.Max(avatar.GetScore() + this.ScoreGain, 0));
            avatar.SetLeagueType(this.LeagueData.GetInstanceID());

            if (this.PrevLeagueData != null)
            {
                if (this.Attacker)
                {
                    if (this.ScoreGain < 0)
                    {
                        avatar.SetAttackLoseCount(avatar.GetAttackLoseCount() + 1);
                    }
                    else
                    {
                        avatar.SetAttackWinCount(avatar.GetAttackWinCount() + 1);
                    }
                }
                else
                {
                    if (this.ScoreGain < 0)
                    {
                        avatar.SetDefenseLoseCount(avatar.GetDefenseLoseCount() + 1);
                    }
                    else
                    {
                        avatar.SetDefenseWinCount(avatar.GetDefenseWinCount() + 1);
                    }
                }
            }
        }
コード例 #3
0
        public static void SetLogicClientAvatarToAllianceMemberEntry(LogicClientAvatar avatar, AllianceMemberEntry allianceMemberEntry, Alliance alliance = null)
        {
            bool updateScoring = avatar.GetScore() != avatar.GetScore();

            allianceMemberEntry.SetAvatarId(avatar.GetId());
            allianceMemberEntry.SetHomeId(avatar.GetCurrentHomeId());
            allianceMemberEntry.SetName(avatar.GetName());
            allianceMemberEntry.SetExpLevel(avatar.GetExpLevel());
            allianceMemberEntry.SetLeagueType(avatar.GetLeagueType());
            allianceMemberEntry.SetScore(avatar.GetScore());
            allianceMemberEntry.SetDuelScore(avatar.GetDuelScore());
            allianceMemberEntry.SetWarPreference(avatar.GetWarPreference());

            if (alliance != null)
            {
                if (updateScoring)
                {
                    alliance.UpdateScoring();
                }
            }
        }
コード例 #4
0
 private static int CalculateStrength(LogicClientAvatar playerAvatar)
 {
     return(playerAvatar.GetScore() + playerAvatar.GetTownHallLevel() * 75);
 }
コード例 #5
0
        public void RefreshStatus()
        {
            if (this.m_level.GetState() == 1)
            {
                LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();
                LogicDataTable    dataTable    = LogicDataTables.GetTable(LogicDataType.ACHIEVEMENT);

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

                    switch (achievementData.GetActionType())
                    {
                    case LogicAchievementData.ACTION_TYPE_NPC_STARS:
                        progress = playerAvatar.GetTotalNpcStars();
                        break;

                    case LogicAchievementData.ACTION_TYPE_UPGRADE:
                        progress = this.m_level.GetGameObjectManager().GetHighestBuildingLevel(achievementData.GetBuildingData()) + 1;
                        break;

                    case LogicAchievementData.ACTION_TYPE_VICTORY_POINTS:
                        progress = playerAvatar.GetScore();
                        break;

                    case LogicAchievementData.ACTION_TYPE_UNIT_UNLOCK:
                        progress = achievementData.GetCharacterData()
                                   .IsUnlockedForBarrackLevel(
                            LogicMath.Max(this.m_level.GetComponentManagerAt(achievementData.GetVillageType()).GetMaxBarrackLevel(), 0))
                                ? 1
                                : 0;
                        break;

                    case LogicAchievementData.ACTION_TYPE_LEAGUE:
                        progress = playerAvatar.GetLeagueType();
                        break;

                    case LogicAchievementData.ACTION_TYPE_ACCOUNT_BOUND:
                        progress = playerAvatar.IsAccountBound() ? 1 : 0;
                        break;

                    case LogicAchievementData.ACTION_TYPE_VERSUS_BATTLE_TROPHIES:
                        progress = playerAvatar.GetDuelScore();
                        break;

                    case LogicAchievementData.ACTION_TYPE_GEAR_UP:
                        progress = this.m_level.GetGameObjectManager().GetGearUpBuildingCount();
                        break;

                    case LogicAchievementData.ACTION_TYPE_REPAIR_BUILDING:
                        LogicArrayList <LogicAchievementData> achievementLevels = achievementData.GetAchievementLevels();

                        if (achievementLevels.Size() > 0)
                        {
                            for (int j = 0; j < achievementLevels.Size(); j++)
                            {
                                if (!this.IsBuildingUnlocked(achievementLevels[j].GetBuildingData()))
                                {
                                    break;
                                }

                                if (achievementLevels[j] == achievementData)
                                {
                                    progress = 1;
                                    break;
                                }
                            }
                        }

                        break;
                    }

                    this.RefreshAchievementProgress(playerAvatar, achievementData, progress);
                }
            }
        }
コード例 #6
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                LogicLegendSeasonEntry legendSeasonEntry;

                if (this.m_villageType == 1)
                {
                    legendSeasonEntry = playerAvatar.GetLegendSeasonEntryVillage2();
                }
                else
                {
                    if (this.m_villageType != 0)
                    {
                        return(-2);
                    }

                    legendSeasonEntry = playerAvatar.GetLegendSeasonEntry();
                }

                if (legendSeasonEntry.GetLastSeasonState() != this.m_lastSeasonState)
                {
                    if (this.m_villageType == 1)
                    {
                        playerAvatar.SetDuelScore(playerAvatar.GetDuelScore() - this.m_scoreChange);
                        playerAvatar.SetLegendaryScore(playerAvatar.GetLegendaryScoreVillage2() + this.m_scoreChange);
                    }
                    else
                    {
                        playerAvatar.SetScore(playerAvatar.GetScore() - this.m_scoreChange);
                        playerAvatar.SetLegendaryScore(playerAvatar.GetLegendaryScore() + this.m_scoreChange);
                    }

                    legendSeasonEntry.SetLastSeasonState(this.m_lastSeasonState);
                    legendSeasonEntry.SetLastSeasonDate(this.m_lastSeasonYear, this.m_lastSeasonMonth);
                    legendSeasonEntry.SetLastSeasonRank(this.m_lastSeasonRank);
                    legendSeasonEntry.SetLastSeasonScore(this.m_lastSeasonScore);

                    bool bestSeason = false;

                    if (legendSeasonEntry.GetBestSeasonState() == 0 ||
                        this.m_lastSeasonRank < legendSeasonEntry.GetBestSeasonRank() ||
                        this.m_lastSeasonRank == legendSeasonEntry.GetBestSeasonRank() &&
                        this.m_lastSeasonScore > legendSeasonEntry.GetBestSeasonScore())
                    {
                        legendSeasonEntry.SetBestSeasonState(this.m_lastSeasonState);
                        legendSeasonEntry.SetBestSeasonDate(this.m_lastSeasonYear, this.m_lastSeasonMonth);
                        legendSeasonEntry.SetBestSeasonRank(this.m_lastSeasonRank);
                        legendSeasonEntry.SetBestSeasonScore(this.m_lastSeasonScore);

                        bestSeason = true;
                    }

                    playerAvatar.GetChangeListener().LegendSeasonScoreChanged(this.m_lastSeasonState, this.m_lastSeasonScore, this.m_scoreChange, bestSeason, this.m_villageType);
                    level.GetGameListener().LegendSeasonScoreChanged(this.m_lastSeasonState, this.m_lastSeasonScore, this.m_scoreChange, bestSeason, this.m_villageType);

                    return(0);
                }
            }

            return(-1);
        }
コード例 #7
0
        public static async Task <LogicArrayList <AllianceHeaderEntry> > SearchAlliances(SearchAlliancesMessage searchAlliancesMessage, LogicClientAvatar playerAvatar)
        {
            LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>();
            StringBuilder builder = new StringBuilder();

            builder.Append("SELECT ");
            builder.Append(SearchManager.QUERY_ALLIANCES_LIST_SELECT);
            builder.Append(" FROM `%BUCKET%` WHERE meta().id LIKE '%KEY_PREFIX%%' AND (");

            string searchString = searchAlliancesMessage.GetSearchString();

            if (!string.IsNullOrEmpty(searchString))
            {
                if (searchString.Length >= 16)
                {
                    searchString = searchString.Substring(0, 15);
                }

                if (searchString.StartsWith(HashTagCodeGenerator.CONVERSION_TAG))
                {
                    LogicLong allianceId = HashTagCodeGenerator.m_instance.ToId(searchString.Trim().ToUpperInvariant());

                    if (allianceId != null)
                    {
                        builder.Append(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH);
                        builder.Append(" == ");
                        builder.Append(allianceId.GetHigherInt().ToString());
                        builder.Append(" AND ");
                        builder.Append(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW);
                        builder.Append(" == ");
                        builder.Append(allianceId.GetLowerInt().ToString());
                        builder.Append(" OR ");
                    }
                }

                builder.Append("LOWER(alliance_name) LIKE '%");
                builder.Append(searchString.ToLowerInvariant());
                builder.Append("%' AND ");
            }

            builder.Append("member_count BETWEEN ");
            builder.Append(searchAlliancesMessage.GetMinimumMembers().ToString());
            builder.Append(" AND ");
            builder.Append(searchAlliancesMessage.GetMaximumMembers().ToString());

            if (searchAlliancesMessage.GetWarFrequency() != 0)
            {
                builder.Append(" AND war_freq == ");
                builder.Append(searchAlliancesMessage.GetWarFrequency().ToString());
            }

            if (searchAlliancesMessage.GetOrigin() != null)
            {
                builder.Append(" AND origin == ");
                builder.Append(searchAlliancesMessage.GetOrigin().GetGlobalID().ToString());
            }

            if (searchAlliancesMessage.GetRequiredScore() != 0)
            {
                builder.Append(" AND score >= ");
                builder.Append(searchAlliancesMessage.GetRequiredScore().ToString());
            }

            if (searchAlliancesMessage.GetRequiredDuelScore() != 0)
            {
                builder.Append(" AND duel_score >= ");
                builder.Append(searchAlliancesMessage.GetRequiredDuelScore().ToString());
            }

            if (searchAlliancesMessage.GetMinimumExpLevel() != 0)
            {
                builder.Append(" AND xp_level >= ");
                builder.Append(searchAlliancesMessage.GetMinimumExpLevel().ToString());
            }

            if (searchAlliancesMessage.IsJoinableOnly())
            {
                builder.Append(" AND required_score <= ");
                builder.Append(playerAvatar.GetScore().ToString());
                builder.Append(" AND required_duel_score <= ");
                builder.Append(playerAvatar.GetDuelScore().ToString());
            }

            builder.AppendLine(") ORDER BY score DESC LIMIT 200");

            IQueryResult <JObject> result = await ServerSearch.AllianceDatabase.ExecuteCommand <JObject>(builder.ToString());

            if (result.Success)
            {
                allianceList.EnsureCapacity(result.Rows.Count);
                result.Rows.ForEach(jsonObject => { allianceList.Add(SearchManager.LoadAllianceHeaderEntry(jsonObject)); });
            }

            return(allianceList);
        }
コード例 #8
0
        /// <summary>
        ///     Refreshes status of all achievements.
        /// </summary>
        public void RefreshStatus()
        {
            if (this._level.GetState() == 1)
            {
                LogicClientAvatar playerAvatar = this._level.GetPlayerAvatar();
                LogicDataTable    dataTable    = LogicDataTables.GetTable(22);

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

                    switch (achievementData.GetActionType())
                    {
                    case 0:
                        progress = playerAvatar.GetTotalNpcStars();
                        break;

                    case 1:
                        progress = this._level.GetGameObjectManager().GetHighestBuildingLevel(achievementData.GetBuildingData()) + 1;
                        break;

                    case 2:
                        progress = playerAvatar.GetScore();
                        break;

                    case 3:
                        progress = achievementData.GetCharacterData().IsUnlockedForBarrackLevel(LogicMath.Max(this._level.GetComponentManagerAt(achievementData.GetVillageType()).GetMaxBarrackLevel(), 0)) ? 1 : 0;
                        break;

                    case 12:
                        progress = playerAvatar.GetLeagueType();
                        break;

                    case 16:
                        progress = playerAvatar.IsAccountBound() ? 1 : 0;
                        break;

                    case 17:
                        progress = playerAvatar.GetDuelScore();
                        break;

                    case 18:
                        progress = this._level.GetGameObjectManager().GetGearUpBuildingCount();
                        break;

                    case 19:
                        LogicArrayList <LogicAchievementData> achievementLevels = achievementData.GetAchievementLevels();

                        if (achievementLevels.Count <= 0)
                        {
                            break;
                        }

                        for (int j = 0; j < achievementLevels.Count; j++)
                        {
                            if (!this._level.IsBuildingUnlocked(achievementLevels[j].GetBuildingData()))
                            {
                                goto refresh;
                            }
                        }

                        progress = 1;

                        break;
                    }

refresh:
                    this.RefreshAchievementProgress(playerAvatar, achievementData, progress);
                }
            }
        }
コード例 #9
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;
        }
コード例 #10
0
        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);
        }
コード例 #11
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);
        }
コード例 #12
0
        public static void CalculateCombatScore(LogicClientAvatar attacker, LogicClientAvatar defender, int stars, bool ignoreLeague, bool revenge, int destructionPercentage,
                                                int starBonusMultiplier, bool duelMatch)
        {
            int multiplier = stars;

            if (stars <= 0)
            {
                multiplier = LogicDataTables.GetGlobals().GetScoreMultiplierOnAttackLose();
            }

            int attackerScore = attacker.GetScore();
            int defenderScore = defender.GetScore();

            LogicLeagueData attackerLeagueData = attacker.GetLeagueTypeData();
            LogicLeagueData defenderLeagueData = defender.GetLeagueTypeData();

            int newAttackerScore;
            int newDefenderScore;

            if (LogicDataTables.GetGlobals().EloOffsetDampeningEnabled())
            {
                newAttackerScore = LogicELOMath.CalculateNewRating(stars > 0, attackerScore, defenderScore, 20 * multiplier, LogicDataTables.GetGlobals().GetEloDampeningFactor(),
                                                                   LogicDataTables.GetGlobals().GetEloDampeningLimit(), LogicDataTables.GetGlobals().GetEloDampeningScoreLimit());
                newDefenderScore = LogicELOMath.CalculateNewRating(stars <= 0, defenderScore, attackerScore, 20 * multiplier, LogicDataTables.GetGlobals().GetEloDampeningFactor(),
                                                                   LogicDataTables.GetGlobals().GetEloDampeningLimit(), LogicDataTables.GetGlobals().GetEloDampeningScoreLimit());
            }
            else
            {
                newAttackerScore = LogicELOMath.CalculateNewRating(stars > 0, attackerScore, defenderScore, 20 * multiplier);
                newDefenderScore = LogicELOMath.CalculateNewRating(stars <= 0, defenderScore, attackerScore, 20 * multiplier);
            }

            int attackerGainCount = newAttackerScore - attackerScore;
            int defenderGainCount = newDefenderScore - defenderScore;

            if (attackerScore < 1000 && attackerGainCount < 0)
            {
                attackerGainCount = attackerScore * attackerGainCount / 1000;
            }

            if (defenderScore < 1000 && defenderGainCount < 0)
            {
                defenderGainCount = defenderScore * defenderGainCount / 1000;
            }

            if (LogicELOMath.CalculateNewRating(true, attackerScore, defenderScore, 60) > attackerScore)
            {
                if (stars <= 0)
                {
                    if (attackerGainCount >= 0)
                    {
                        attackerGainCount = -1;
                    }
                }
                else
                {
                    if (attackerGainCount <= 0)
                    {
                        attackerGainCount = 1;
                    }

                    if (defenderGainCount >= 0)
                    {
                        defenderGainCount = -1;
                    }
                }
            }

            newAttackerScore = LogicMath.Max(attackerScore + attackerGainCount, 0);
            newDefenderScore = LogicMath.Max(defenderScore + defenderGainCount, 0);

            if (!ignoreLeague)
            {
                attacker.SetScore(newAttackerScore);
                defender.SetScore(newDefenderScore);

                if (LogicDataTables.GetGlobals().EnableLeagues())
                {
                    if (!duelMatch)
                    {
                        if (attackerLeagueData != null)
                        {
                            if (stars <= 0)
                            {
                                attacker.SetAttackLoseCount(attacker.GetAttackLoseCount() + 1);
                            }
                            else
                            {
                                attacker.SetAttackWinCount(attacker.GetAttackWinCount() + 1);
                            }
                        }

                        if (defenderLeagueData != null)
                        {
                            if (stars > 0)
                            {
                                defender.SetDefenseLoseCount(defender.GetDefenseLoseCount() + 1);
                            }
                            else
                            {
                                defender.SetDefenseWinCount(defender.GetDefenseLoseCount() + 1);
                            }
                        }

                        if (stars > 0)
                        {
                            if (!revenge || LogicDataTables.GetGlobals().RevengeGiveLeagueBonus())
                            {
                                int leagueBonusPercentage = LogicDataTables.GetGlobals().GetLeagueBonusPercentage(destructionPercentage);

                                attacker.CommodityCountChangeHelper(0, LogicDataTables.GetGoldData(), attackerLeagueData.GetGoldReward() * leagueBonusPercentage / 100);
                                attacker.CommodityCountChangeHelper(0, LogicDataTables.GetElixirData(), attackerLeagueData.GetElixirReward() * leagueBonusPercentage / 100);

                                if (attacker.IsDarkElixirUnlocked())
                                {
                                    attacker.CommodityCountChangeHelper(0, LogicDataTables.GetDarkElixirData(),
                                                                        attackerLeagueData.GetDarkElixirReward() * leagueBonusPercentage / 100);
                                }
                            }
                        }

                        LogicGamePlayUtil.UpdateLeagueRank(attacker, newAttackerScore, false);
                        LogicGamePlayUtil.UpdateLeagueRank(defender, newDefenderScore, true);
                    }
                }
            }

            attacker.GetChangeListener().ScoreChanged(attacker.GetCurrentHomeId(), attackerGainCount, stars > 0 ? 1 : -1, true, attacker.GetLeagueTypeData(), attackerLeagueData,
                                                      destructionPercentage);
            defender.GetChangeListener().ScoreChanged(defender.GetCurrentHomeId(), defenderGainCount, stars > 0 ? -1 : 1, false, defender.GetLeagueTypeData(), defenderLeagueData,
                                                      destructionPercentage);

            if (stars > 0 && !ignoreLeague && !duelMatch && (!revenge || LogicDataTables.GetGlobals().RevengeGiveStarBonus()) && !attacker.GetStarBonusCooldown())
            {
                int totalStars = stars + attacker.GetStarBonusCounter();

                if (totalStars >= LogicDataTables.GetGlobals().GetStarBonusStarCount())
                {
                    LogicLeagueData leagueData = attacker.GetLeagueTypeData();

                    attacker.AddStarBonusReward(leagueData.GetGoldRewardStarBonus() * starBonusMultiplier, leagueData.GetElixirRewardStarBonus() * starBonusMultiplier,
                                                leagueData.GetDarkElixirRewardStarBonus() * starBonusMultiplier);
                    attacker.StarBonusCollected();

                    if (LogicDataTables.GetGlobals().AllowStarsOverflowInStarBonus() && !attacker.GetStarBonusCooldown())
                    {
                        totalStars %= LogicDataTables.GetGlobals().GetStarBonusStarCount();
                    }
                    else
                    {
                        totalStars = 0;
                    }
                }

                attacker.SetStarBonusCounter(totalStars);
            }
        }