示例#1
0
            /// <summary>
            /// Gives the specified upgrade to a FirstPersonMover
            /// </summary>
            /// <param name="Target"></param>
            /// <param name="Upgrade"></param>
            public static void Give(FirstPersonMover Target, UpgradeDescription Upgrade)
            {
                if (Target == null)
                {
                    return;
                }

                if (Target.IsMainPlayer())
                {
                    GameDataManager.Instance.SetUpgradeLevel(Upgrade.UpgradeType, Upgrade.Level);
                    UpgradeDescription upgrade = UpgradeManager.Instance.GetUpgrade(Upgrade.UpgradeType, Upgrade.Level);
                    GlobalEventManager.Instance.Dispatch("UpgradeCompleted", upgrade);
                }
                else
                {
                    UpgradeCollection upgradeCollection = Target.gameObject.GetComponent <UpgradeCollection>();

                    if (upgradeCollection == null)
                    {
                        debug.Log("Failed to give upgrade '" + Upgrade.UpgradeName + "' (Level: " + Upgrade.Level + ") to " + Target.CharacterName + " (UpgradeCollection is null)", Color.red);
                        return;
                    }

                    UpgradeTypeAndLevel upgradeToGive = new UpgradeTypeAndLevel {
                        UpgradeType = Upgrade.UpgradeType, Level = Upgrade.Level
                    };

                    List <UpgradeTypeAndLevel> upgrades = ((PreconfiguredUpgradeCollection)upgradeCollection).Upgrades.ToList();

                    upgrades.Add(upgradeToGive);

                    ((PreconfiguredUpgradeCollection)upgradeCollection).Upgrades = upgrades.ToArray();
                    ((PreconfiguredUpgradeCollection)upgradeCollection).InitializeUpgrades();

                    Target.RefreshUpgrades();
                }

                Target.SetUpgradesNeedsRefreshing();
            }
示例#2
0
        /// <summary>
        /// Gives the specified upgrade to a <see cref="FirstPersonMover"/>
        /// </summary>
        /// <param name="firstPersonMover"></param>
        /// <param name="upgradeType">The <see cref="UpgradeType"/> to give</param>
        /// <param name="level">The level of the upgrade</param>
        /// <exception cref="ArgumentNullException">If the given <see cref="FirstPersonMover"/> is <see langword="null"/></exception>
        /// <exception cref="ArgumentException">If the given <see cref="UpgradeType"/> and level has not been defined in <see cref="UpgradeManager.UpgradeDescriptions"/></exception>
        public static void GiveUpgrade(this FirstPersonMover firstPersonMover, UpgradeType upgradeType, int level)
        {
            if (firstPersonMover == null)
            {
                throw new ArgumentNullException(nameof(firstPersonMover));
            }

            if (UpgradeManager.Instance.GetUpgrade(upgradeType, level) == null)
            {
                throw new ArgumentException("The upgrade with type \"" + upgradeType + "\" and level " + level + " has not been defined!");
            }

            if (firstPersonMover.GetComponent <PreconfiguredUpgradeCollection>() != null) // If we are giving an upgrade to an enemy/ally
            {
                PreconfiguredUpgradeCollection upgradeCollection = firstPersonMover.GetComponent <PreconfiguredUpgradeCollection>();
                UpgradeTypeAndLevel            upgradeToGive     = new UpgradeTypeAndLevel {
                    UpgradeType = upgradeType, Level = level
                };

                List <UpgradeTypeAndLevel> upgrades = upgradeCollection.Upgrades.ToList();
                upgrades.Add(upgradeToGive);
                upgradeCollection.Upgrades = upgrades.ToArray();

                upgradeCollection.InitializeUpgrades();

                firstPersonMover.RefreshUpgrades();
            }
            else if (firstPersonMover.GetComponent <PlayerUpgradeCollection>() != null) // If we are giving it to the player
            {
                GameDataManager.Instance.SetUpgradeLevel(upgradeType, level);           // Set the level of the upgrade to the given one
                UpgradeDescription upgrade = UpgradeManager.Instance.GetUpgrade(upgradeType, level);
                GlobalEventManager.Instance.Dispatch(GlobalEvents.UpgradeCompleted, upgrade);
            }

            firstPersonMover.SetUpgradesNeedsRefreshing();
        }
示例#3
0
 /// <summary>
 /// Gets an UpgradeDescription from an UpgradeTypeAndLevel
 /// </summary>
 /// <param name="upgrade"></param>
 /// <returns></returns>
 public static UpgradeDescription GetUpgradeDescriptionFromTypeAndLevel(UpgradeTypeAndLevel upgrade)
 {
     return(GetUpgradeDescriptionFromTypeAndLevel(upgrade.UpgradeType, upgrade.Level));
 }
示例#4
0
 /// <summary>
 /// Gets the icon of the specified upgrade
 /// </summary>
 /// <param name="upgrade"></param>
 /// <returns></returns>
 public static Sprite GetUpgradeIcon(UpgradeTypeAndLevel upgrade)
 {
     return(GetUpgradeIcon(upgrade.UpgradeType, upgrade.Level));
 }