using System; using System.Collections.Generic; using System.Linq; using Unity.VisualScripting; using UnityEditor; using UnityEngine; /// <summary> /// Global methods and objects that are needed and retained throughout the game experience /// </summary> public static class Globals { public const int BaseStat = 10; // Base stat value for reference when calculating point values, damage, or more public const int BaseMinStat = 3; // Base Min Stat value that can't go lower for the player when creating character or most situations in game public const int BaseMaxStat = 20; // Base Max Stat value that can't go higher for the player when creating character or most situations in game public const float MainCameraOrtho = 5f; // The primary size the main camera should be in the orthographic terms public static readonly Vector3 MainCameraPosition = new Vector3(0f, 0f, -10f); public static readonly Color DisabledColor = new Color(.65f, .65f, .65f, 1f); public static Dictionary<int, bool> Flags = new Dictionary<int, bool>(); public static Dictionary<int, bool> RelicFlags = new Dictionary<int, bool>(); public static Dictionary<string, List<EntitySkills>> EntitySkillData = new Dictionary<string, List<EntitySkills>>(); public static bool AlexsShopCheat { get; set; } public static bool InfiniteMoneyCheat { get; set; } public static bool LargeHealthCheat { get; set; } public static bool LargeManaCheat { get; set; } public static bool Add100SkillPointsCheat { get; set; } public static bool IsBossEncounter { get; set; } // The current seed that is within the system's memory for function determinations, must be 9 digits public static int Seed { get; private set; } public static PlayerHandler Player { get; private set; } public static bool InventoryOpened { get; private set; } public static bool CurMaxPositionSwitch { get; private set; } /// <summary> /// Signals that the inventory is opened to other systems /// </summary> public static void OpenInventory() => InventoryOpened = true; /// <summary> /// Signals that the inventory is closed to other systems /// </summary> public static void CloseInventory() => InventoryOpened = false; /// <summary> /// Initializes the Random Number Generator with the seed passed through the global function and /// sets the Seed value to be called for reference visually in game /// </summary> /// <param name="seed">9 digit or less function</param> public static void SetSeed(int seed) { if (seed <= 0) throw new InvalidOperationException("Seed passed is 0 or less, please check that the value passed in character creation is valid: " + seed); // Sets the seed within the Random Number Generator then to the reference UnityEngine.Random.InitState(seed); Seed = seed; } /// <summary> /// Initialization for the game to set the player after the creation screen /// </summary> /// <param name="player">The player information based off of the starting screen information</param> public static void SetPlayer(PlayerHandler player) { Player = player; RelicSO[] allRelics = Resources.LoadAll<RelicSO>("Relics"); foreach (RelicSO relic in allRelics) RelicFlags.Add(relic.ID, false); } /// <summary> /// Transfers the data from the Item SO to an Item class object /// </summary> /// <param name="reference">The ItemSO version data</param> /// <returns>Item containing data from the Item SO object</returns> public static Item TurnItemFromObject(ItemSO reference) => new Item(reference); /// <summary> /// Transfers the data from the Consumable SO to a Consumable class object /// </summary> /// <param name="reference">Consumable SO version data</param> /// <returns>Consumable containing the data from the Consumable SO</returns> public static Consumable TurnConsumableFromObject(ConsumableSO reference) => new Consumable(reference); /// <summary> /// Transforms the Scriptable Object found into a Weapon class object to be used /// </summary> /// <param name="reference">Weapon SO version data</param> /// <returns>Weapon containing the Weapon SO data</returns> public static Weapon TurnWeaponFromObject(WeaponSO reference) => new Weapon(reference); /// <summary> /// Transfers the data within the Apparel SO into an Apparel class for usage within other classes /// </summary> /// <param name="reference">Apparel SO version data</param> /// <returns>Apparel with the Apparel SO data</returns> public static Apparel TurnApparelFromObject(ApparelSO reference) => new Apparel(reference); /// <summary> /// Transfers the data within the Relic SO into a base Relic class /// </summary> /// <param name="reference">The RelicSO which contains the necessary information</param> /// <returns>Relic object with the data from the reference RelicSO</returns> public static Relic TurnRelicFromObject(RelicSO reference) => new Relic(reference); /// <summary> /// Transfers the data from the Spell SO to the Spell class object /// </summary> /// <param name="reference">Spell SO version data</param> /// <returns>Spell containing the data from the Spell SO</returns> public static Spell TurnSpellFromObject(SpellSO reference) => new Spell(reference); /// <summary> /// Transfers the data from the Ability SO to an Ability class object /// </summary> /// <param name="reference">Ability SO version data</param> /// <returns>Ability containing the data from the Ability SO</returns> public static Ability TurnAbilityFromObject(AbilitySO reference) => new Ability(reference); /// <summary> /// Transfers the data from the Modifier SO to a Modifier class object /// </summary> /// <param name="reference">The ModifierSO class object</param> /// <returns>The Modifier containing the data from the Modifier SO</returns> public static Modifier TurnModifierFromObject(ModifierSO reference) => new Modifier(reference); /// <summary> /// Gathers the modifier from the stat indicated in the parameter, which can be used /// for various calculations or interfaces in the game, such as battle order /// </summary> /// <param name="statValue">The stat parameter</param> /// <returns>Modifier value</returns> public static int GatherModifier(int statValue) { int modOutput = 0; if (statValue > 10) { int extraVal = statValue - 10; for (int i = 0; i < extraVal; ++i) { if (i % 2 is 0) ++modOutput; } } else if (statValue < 10) { if (statValue <= 3) modOutput = -4; else if (statValue <= 5) modOutput = -3; else if (statValue <= 7) modOutput = -2; else if (statValue <= 9) modOutput = -1; } return modOutput; } public static void SetFlag(int flagValue, bool state) { if (!Flags.ContainsKey(flagValue)) Flags.Add(flagValue, state); else Flags[flagValue] = state; } public static void SwitchCurMaxPositions(bool state) { // Signal to the GUis in the system to switch their respective places // If catch occurs, must not be in the game itself yet and only on the title settings screen // or in game over settings screen try { GeneralUI.Instance.SwitchCurMaxPositions(); } catch { } CurMaxPositionSwitch = state; } public static EntitySkills SearchForEntitySkillData(string entityName, Guid id) { EntitySkills output = null; foreach (KeyValuePair<string, List<EntitySkills>> skillDataSet in EntitySkillData) { if (skillDataSet.Key.Equals(entityName)) { output = skillDataSet.Value .Where(skillSet => skillSet.UniqueId == id) .FirstOrDefault(); break; } } return output; } /// <summary> /// Saves the entity skill data from their skill trees to be recalled later for reference /// </summary> /// <param name="entityName">The name of the entity being saved</param> /// <param name="entitySkills">The list of skills in the skill tree affiliated</param> public static void SaveEntitySkillData(string entityName, EntitySkills entitySkills) { if (!EntitySkillData.ContainsKey(entityName)) EntitySkillData.Add(entityName, new List<EntitySkills> { entitySkills }); else { bool saveOver = false; EntitySkills removeSkillCheck = null; foreach (EntitySkills skillData in EntitySkillData[entityName]) { if (skillData.UniqueId == entitySkills.UniqueId) { removeSkillCheck = skillData; saveOver = true; break; } } // If the entity skill data set is already present, then simply remove it before saving it over if (saveOver) EntitySkillData[entityName].Remove(removeSkillCheck); EntitySkillData[entityName].Add(entitySkills); } } public static void ToggleRelicFlag(int relicID, bool state) { RelicFlags[relicID] = state; } }