public override int Execute(LogicLevel level) { this.m_level = level; if (level.GetVillageType() == 0) { if (LogicDataTables.GetGlobals().EnablePresets()) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetEnablePresetsTownHallLevel()) { if (this.m_presetId <= 3) { if (this.HasEnoughFreeHousingSpace()) { int elixirCost = this.GetResourceCost(LogicDataTables.GetElixirData()); int darkElixirCost = this.GetResourceCost(LogicDataTables.GetDarkElixirData()); if (level.GetPlayerAvatar().HasEnoughResources(LogicDataTables.GetElixirData(), elixirCost, LogicDataTables.GetDarkElixirData(), darkElixirCost, true, this, false)) { this.TrainUnits(); return(0); } } return(-1); } return(-2); } } return(-3); } return(-32); }
public override void Load(LogicJSONObject jsonObject) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defg"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } else if (LogicDataTables.GetElixirData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defe"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defde"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } } } }
public override void Save(LogicJSONObject jsonObject, int villageType) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defg", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defe", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defde", new LogicJSONNumber(count)); } } } } }
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); } }