Exemple #1
0
        public void RemoveUpgrade(int uniquePilotId, int upgradeId)
        {
            int  upgradeToRemoveKey      = 0;
            bool hasFoundUpgradeToRemove = false;

            foreach (KeyValuePair <int, Upgrade> upgrade in pilots[uniquePilotId].upgrades)
            {
                if (upgrade.Value.id == upgradeId)
                {
                    hasFoundUpgradeToRemove = true;
                    upgradeToRemoveKey      = upgrade.Key;
                    break;
                }
            }
            if (hasFoundUpgradeToRemove)
            {
                pilots[uniquePilotId].upgrades.Remove(upgradeToRemoveKey);
                UpgradeModifiers.RemoveUpgrade(this, uniquePilotId, upgradeId);
                Upgrades.RemoveUnusableUpgrades(this, uniquePilotId);
                Builds.SaveBuilds();
            }
        }
        private static bool IsUpgradeUsable(UniquePilot uniquePilot, Upgrade upgrade, bool isRemovingUpgrades = false)
        {
            bool isUpgradeUsable = true;

            if (uniquePilot.pilotSkill < upgrade.requiresPilotSkill)
            {
                isUpgradeUsable = false;
            }
            if (upgrade.factions.Contains(Faction.All) == false && upgrade.factions.Contains(uniquePilot.pilot.faction) == false)
            {
                isUpgradeUsable = false;
            }
            if (upgrade.shipSize != ShipSize.All && upgrade.shipSize != uniquePilot.pilot.ship.shipSize)
            {
                isUpgradeUsable = false;
            }

            if (uniquePilot.upgrades.ContainsValue(upgrade) && upgrade.isLimited && isRemovingUpgrades == false)
            {
                isUpgradeUsable = false;
            }

            // Check if the pilot has a slot for the upgrade
            if (uniquePilot.possibleUpgrades.ContainsKey(upgrade.upgradeType))
            {
                if (isRemovingUpgrades)
                {
                    isUpgradeUsable = (uniquePilot.possibleUpgrades[upgrade.upgradeType] >= 0) ? isUpgradeUsable : false;
                }
                else
                {
                    isUpgradeUsable = (upgrade.numberOfUpgradeSlots <= uniquePilot.possibleUpgrades[upgrade.upgradeType]) ? isUpgradeUsable : false;
                }
            }
            else
            {
                isUpgradeUsable = false;
            }

            bool isCorrectShipType = false;

            if ((upgrade.shipThatCanUse.Contains(ShipType.All) || (upgrade.shipThatCanUse.Contains(uniquePilot.pilot.ship.shipType))) &&
                (upgrade.isTieOnly == false || (upgrade.isTieOnly == true && uniquePilot.pilot.ship.isTIE)) &&
                (upgrade.isXWingOnly == false || (upgrade.isXWingOnly == true && uniquePilot.pilot.ship.isXWing))
                )
            {
                isCorrectShipType = true;
            }
            if (isCorrectShipType == false)
            {
                isUpgradeUsable = false;
            }

            if (upgrade.requiresActions.Count > 0)
            {
                foreach (Action requiredAction in upgrade.requiresActions)
                {
                    if (uniquePilot.usableActions.Exists(action => action == requiredAction) == false)
                    {
                        isUpgradeUsable = false;
                        break;
                    }
                }
            }

            if (upgrade.requiresUpgrades.Count > 0)
            {
                foreach (int requiredupgrade in upgrade.requiresUpgrades)
                {
                    if (uniquePilot.upgrades.Values.ToList().Exists(upgradeElement => upgradeElement.id == requiredupgrade) == false)
                    {
                        isUpgradeUsable = false;
                        break;
                    }
                }
            }

            if (UpgradeModifiers.SkipGetUpgrade(uniquePilot, upgrade, isRemovingUpgrades))
            {
                isUpgradeUsable = false;
            }

            return(isUpgradeUsable);
        }