Esempio n. 1
0
        public void GiveTurfRewardToGang(Gang targetGang)
        {
            List <TurfZone> curGangZones = ZoneManager.instance.GetZonesControlledByGang(targetGang.name);
            int             zonesCount   = curGangZones.Count;

            if (targetGang.isPlayerOwned)
            {
                if (curGangZones.Count > 0)
                {
                    int rewardedCash = 0;

                    for (int i = 0; i < zonesCount; i++)
                    {
                        int zoneReward = GangCalculations.CalculateRewardForZone(curGangZones[i], zonesCount);

                        rewardedCash += zoneReward;
                    }

                    MindControl.instance.AddOrSubtractMoneyToProtagonist(rewardedCash);
                    Function.Call(Hash.PLAY_SOUND, -1, "Virus_Eradicated", "LESTER1A_SOUNDS", 0, 0, 1);
                    UI.Notify("Money won from controlled zones: " + rewardedCash.ToString());
                }
            }
            else
            {
                for (int i = 0; i < curGangZones.Count; i++)
                {
                    targetGang.moneyAvailable += (int)
                                                 (GangCalculations.CalculateRewardForZone(curGangZones[i], zonesCount) *
                                                  ModOptions.instance.extraProfitForAIGangsFactor);
                }
            }
        }
Esempio n. 2
0
        void TryUpgradeMembers()
        {
            //since we've got some extra cash, lets upgrade our members!
            switch (RandoMath.CachedRandom.Next(3))
            {
            case 0:                     //accuracy!
                if (watchedGang.memberAccuracyLevel < ModOptions.instance.maxGangMemberAccuracy &&
                    watchedGang.moneyAvailable >= GangCalculations.CalculateAccuracyUpgradeCost(watchedGang.memberAccuracyLevel))
                {
                    watchedGang.moneyAvailable      -= GangCalculations.CalculateAccuracyUpgradeCost(watchedGang.memberAccuracyLevel);
                    watchedGang.memberAccuracyLevel += ModOptions.instance.GetAccuracyUpgradeIncrement();
                    if (watchedGang.memberAccuracyLevel > ModOptions.instance.maxGangMemberAccuracy)
                    {
                        watchedGang.memberAccuracyLevel = ModOptions.instance.maxGangMemberAccuracy;
                    }

                    GangManager.instance.SaveGangData(false);
                }
                break;

            case 1:                     //armor!
                if (watchedGang.memberArmor < ModOptions.instance.maxGangMemberArmor &&
                    watchedGang.moneyAvailable >= GangCalculations.CalculateArmorUpgradeCost(watchedGang.memberArmor))
                {
                    watchedGang.moneyAvailable -= GangCalculations.CalculateArmorUpgradeCost(watchedGang.memberArmor);
                    watchedGang.memberArmor    += ModOptions.instance.GetArmorUpgradeIncrement();

                    if (watchedGang.memberArmor > ModOptions.instance.maxGangMemberArmor)
                    {
                        watchedGang.memberArmor = ModOptions.instance.maxGangMemberArmor;
                    }

                    GangManager.instance.SaveGangData(false);
                }
                break;

            default:                     //health!
                if (watchedGang.memberHealth < ModOptions.instance.maxGangMemberHealth &&
                    watchedGang.moneyAvailable >= GangCalculations.CalculateHealthUpgradeCost(watchedGang.memberHealth))
                {
                    watchedGang.moneyAvailable -= GangCalculations.CalculateHealthUpgradeCost(watchedGang.memberHealth);
                    watchedGang.memberHealth   += ModOptions.instance.GetHealthUpgradeIncrement();

                    if (watchedGang.memberHealth > ModOptions.instance.maxGangMemberHealth)
                    {
                        watchedGang.memberHealth = ModOptions.instance.maxGangMemberHealth;
                    }

                    GangManager.instance.SaveGangData(false);
                }
                break;
            }
        }
Esempio n. 3
0
        void TryUpgradeZones()
        {
            int upgradeCost = GangCalculations.CalculateGangValueUpgradeCost(watchedGang.baseTurfValue);

            //upgrade the whole gang strength if possible!
            //lets not get more upgrades here than the player. it may get too hard for the player to catch up otherwise
            if (watchedGang.moneyAvailable >= upgradeCost &&
                watchedGang.baseTurfValue <= GangManager.instance.PlayerGang.baseTurfValue - 1)
            {
                watchedGang.moneyAvailable -= upgradeCost;
                watchedGang.baseTurfValue++;
                GangManager.instance.SaveGangData(false);
                return;
            }
            //if we have enough money to upgrade a zone,
            //try upgrading our toughest zone... or one that we can afford upgrading
            int lastCheckedValue = ModOptions.instance.maxTurfValue;

            for (int i = 0; i < myZones.Count; i++)
            {
                if (myZones[i].value >= lastCheckedValue)
                {
                    continue;                                                       //we already know we can't afford upgrading from this turf level
                }
                upgradeCost = GangCalculations.CalculateTurfValueUpgradeCost(myZones[i].value);
                if (watchedGang.moneyAvailable >= upgradeCost)
                {
                    watchedGang.moneyAvailable -= upgradeCost;
                    myZones[i].value++;
                    ZoneManager.instance.SaveZoneData(false);
                    return;
                }
                else
                {
                    lastCheckedValue = myZones[i].value;
                }
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public bool StartWar(Gang enemyGang, TurfZone warZone, WarType theWarType, AttackStrength attackStrength)
        {
            if (!isOccurring || enemyGang == GangManager.instance.PlayerGang)
            {
                this.enemyGang    = enemyGang;
                this.warZone      = warZone;
                this.curWarType   = theWarType;
                curWarAtkStrength = attackStrength;
                playerNearWarzone = false;
                spawnPointsSet    = false;

                warBlip            = World.CreateBlip(warZone.zoneBlipPosition);
                warBlip.IsFlashing = true;
                warBlip.Sprite     = BlipSprite.Deathmatch;
                warBlip.Color      = BlipColor.Red;

                warAreaBlip = World.CreateBlip(warZone.zoneBlipPosition,
                                               ModOptions.instance.maxDistToWarBlipBeforePlayerLeavesWar);
                warAreaBlip.Sprite = BlipSprite.BigCircle;
                warAreaBlip.Color  = BlipColor.Red;
                warAreaBlip.Alpha  = 175;


                Function.Call(Hash.BEGIN_TEXT_COMMAND_SET_BLIP_NAME, "STRING");
                Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, "Gang War (versus " + enemyGang.name + ")");
                Function.Call(Hash.END_TEXT_COMMAND_SET_BLIP_NAME, warBlip);

                curTicksAwayFromBattle = 0;
                enemiesInsideCars      = SpawnManager.instance.GetSpawnedMembersOfGang(enemyGang, true);

                if (theWarType == WarType.attackingEnemy)
                {
                    alliedReinforcements = GangCalculations.CalculateAttackerReinforcements(GangManager.instance.PlayerGang, attackStrength);
                    enemyReinforcements  = GangCalculations.CalculateDefenderReinforcements(enemyGang, warZone);
                }
                else
                {
                    alliedReinforcements = GangCalculations.CalculateDefenderReinforcements(GangManager.instance.PlayerGang, warZone);
                    enemyReinforcements  = GangCalculations.CalculateAttackerReinforcements(enemyGang, attackStrength);
                }

                float screenRatio = (float)Game.ScreenResolution.Width / Game.ScreenResolution.Height;

                int proportionalScreenWidth = (int)(1080 * screenRatio); //nativeUI UIResText works with 1080p height

                alliedNumText.Position = new Point((proportionalScreenWidth / 2) - 120, 10);
                enemyNumText.Position  = new Point((proportionalScreenWidth / 2) + 120, 10);

                alliedNumText.Caption = alliedReinforcements.ToString();
                enemyNumText.Caption  = enemyReinforcements.ToString();

                initialEnemyReinforcements = enemyReinforcements;

                reinforcementsAdvantage = alliedReinforcements / (float)enemyReinforcements;

                spawnedAllies  = SpawnManager.instance.GetSpawnedMembersOfGang(GangManager.instance.PlayerGang).Count;
                spawnedEnemies = SpawnManager.instance.GetSpawnedMembersOfGang(enemyGang).Count;

                maxSpawnedAllies  = (int)(RandoMath.Max((ModOptions.instance.spawnedMemberLimit / 2) * reinforcementsAdvantage, 5));
                maxSpawnedEnemies = RandoMath.Max(ModOptions.instance.spawnedMemberLimit - maxSpawnedAllies, 5);

                isOccurring = true;

                //BANG-like sound
                Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "PROPERTY_PURCHASE", "HUD_AWARDS");

                if (theWarType == WarType.attackingEnemy)
                {
                    UI.ShowSubtitle("The " + enemyGang.name + " are coming!");

                    //if we are attacking, set spawns around the player!
                    SetSpawnPoints(MindControl.CurrentPlayerCharacter.Position);
                }
                else
                {
                    UI.Notify(string.Concat("The ", enemyGang.name, " are attacking ", warZone.zoneName, "! They are ",
                                            GangCalculations.CalculateAttackerReinforcements(enemyGang, attackStrength).ToString(),
                                            " against our ",
                                            GangCalculations.CalculateDefenderReinforcements(GangManager.instance.PlayerGang, warZone).ToString()));
                    //spawns are set around the zone blip if we are defending
                    if (World.GetDistance(MindControl.CurrentPlayerCharacter.Position, warZone.zoneBlipPosition) < 100)
                    {
                        SetSpawnPoints(warZone.zoneBlipPosition);
                    }
                }

                SetHateRelationsBetweenGangs();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        /// <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);
                    }
                }
            }
        }