public void EndWar(bool playerVictory) { bool weWereAttacking = curWarType == WarType.attackingEnemy; if (playerVictory) { int battleProfit = GangCalculations.CalculateBattleRewards(enemyGang, weWereAttacking ? warZone.value : (int)curWarAtkStrength, weWereAttacking); MindControl.instance.AddOrSubtractMoneyToProtagonist (battleProfit); UI.Notify("Victory rewards: $" + battleProfit.ToString()); if (weWereAttacking) { GangManager.instance.PlayerGang.TakeZone(warZone); UI.ShowSubtitle(warZone.zoneName + " is now ours!"); } else { UI.ShowSubtitle(warZone.zoneName + " remains ours!"); } AmbientGangMemberSpawner.instance.postWarBackupsRemaining = ModOptions.instance.postWarBackupsAmount; } else { enemyGang.moneyAvailable += (int) (GangCalculations.CalculateBattleRewards(GangManager.instance.PlayerGang, !weWereAttacking ? warZone.value : (int)curWarAtkStrength, !weWereAttacking) * ModOptions.instance.extraProfitForAIGangsFactor); if (curWarType == WarType.attackingEnemy) { UI.ShowSubtitle("We've lost this battle. They keep the turf."); } else { enemyGang.TakeZone(warZone); UI.ShowSubtitle(warZone.zoneName + " has been taken by the " + enemyGang.name + "!"); } } CheckIfBattleWasUnfair(); Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "ScreenFlash", "WastedSounds"); warBlip.Remove(); warAreaBlip.Remove(); shouldDisplayReinforcementsTexts = false; isOccurring = false; playerNearWarzone = false; AmbientGangMemberSpawner.instance.enabled = true; if (!weWereAttacking) { //prevent the player from being attacked again too early timeLastWarAgainstPlayer = ModCore.curGameTime; } if (enemySpawnBlip != null) { enemySpawnBlip.Remove(); } foreach (Blip alliedBlip in alliedSpawnBlips) { if (alliedBlip != null) { alliedBlip.Remove(); } } //reset relations to whatever is set in modoptions GangManager.instance.SetGangRelationsAccordingToAggrLevel(ModOptions.instance.gangMemberAggressiveness); }
/// <summary> /// if fighting is enabled and the targetzone is controlled by an enemy, attack it! ... But only if it's affordable. /// if we're desperate we do it anyway /// </summary> /// <param name="targetZone"></param> void TryStartFightForZone(TurfZone targetZone) { Gang ownerGang = GangManager.instance.GetGangByName(targetZone.ownerGangName); if (ownerGang == null) { Logger.Log("Gang with name " + targetZone.ownerGangName + " no longer exists; assigning all owned turf to 'none'", 1); ZoneManager.instance.GiveGangZonesToAnother(targetZone.ownerGangName, "none"); //this zone was controlled by a gang that no longer exists. it is neutral now if (watchedGang.moneyAvailable >= ModOptions.instance.baseCostToTakeTurf) { watchedGang.moneyAvailable -= ModOptions.instance.baseCostToTakeTurf; watchedGang.TakeZone(targetZone); } } else { if (GangWarManager.instance.isOccurring && GangWarManager.instance.warZone == targetZone) { //don't mess with this zone then, it's a warzone return; } //we check how well defended this zone is, //then figure out how large our attack should be. //if we can afford that attack, we do it int defenderStrength = GangCalculations.CalculateDefenderStrength(ownerGang, targetZone); GangWarManager.AttackStrength requiredStrength = GangCalculations.CalculateRequiredAttackStrength(watchedGang, defenderStrength); int atkCost = GangCalculations.CalculateAttackCost(watchedGang, requiredStrength); if (watchedGang.moneyAvailable < atkCost) { if (myZones.Count == 0) { //if we're out of turf and cant afford a decent attack, lets just attack anyway //we use a light attack and do it even if that means our money gets negative. //this should make gangs get back in the game or be wiped out instead of just staying away requiredStrength = GangWarManager.AttackStrength.light; atkCost = GangCalculations.CalculateAttackCost(watchedGang, requiredStrength); } else { return; //hopefully we can just find a cheaper fight } } if (targetZone.ownerGangName == GangManager.instance.PlayerGang.name) { if (ModOptions.instance.warAgainstPlayerEnabled && GangWarManager.instance.CanStartWarAgainstPlayer) { //the player may be in big trouble now watchedGang.moneyAvailable -= atkCost; GangWarManager.instance.StartWar(watchedGang, targetZone, GangWarManager.WarType.defendingFromEnemy, requiredStrength); } } else { watchedGang.moneyAvailable -= atkCost; int attackStrength = GangCalculations.CalculateAttackerStrength(watchedGang, requiredStrength); //roll dices... favor the defenders a little here if (attackStrength / RandoMath.CachedRandom.Next(1, 22) > defenderStrength / RandoMath.CachedRandom.Next(1, 15)) { watchedGang.TakeZone(targetZone); watchedGang.moneyAvailable += (int)(GangCalculations.CalculateBattleRewards(ownerGang, targetZone.value, true) * ModOptions.instance.extraProfitForAIGangsFactor); } else { ownerGang.moneyAvailable += (int)(GangCalculations.CalculateBattleRewards(watchedGang, (int)requiredStrength, false) * ModOptions.instance.extraProfitForAIGangsFactor); } } } }