public static void AddGlobalValue(GameValue gameValue) { InitializeDictionaryIfNull(); GameValue gv = new GameValue(gameValue); globalValuesDict[gv.name] = gv; }
public static bool CheckGameValues(string debugName, GameValuesContainer container, GameValueCheck[] checks) { if (container == null) { Debug.LogError(debugName + " doesnt have an attached GameValuesContainer!"); return(false); } bool checksOK = true; for (int i = 0; i < checks.Length; i++) { GameValue gv = container.GetGameValueObject(checks[i].name); if (gv == null) { checksOK = false; } else { if (gv.useBaseModifiers != checks[i].useBaseModifiers) { Debug.LogError(debugName + " Needs Game Value Named '" + checks[i].name + "' To " + (checks[i].useBaseModifiers ? "" : "Not") + " Use Base Modifiers"); checksOK = false; } if (gv.isRangedValue != checks[i].isRangedValue) { Debug.LogError(debugName + " Needs Game Value Named '" + checks[i].name + "' To " + (checks[i].isRangedValue ? "" : "Not") + " Be A Ranged Value"); checksOK = false; } } } return(checksOK); }
void OnPlayerDestroy() { levelV = null; pointsV = null; highestLevelV = null; rewardsV = null; }
void OnHighestLevelChange(GameValue valueChanged, GameValueChangedComponent changedComponent, float baseDelta, float rangedValueDelta) { int deltaPoints = (int)baseDelta; if (deltaPoints > 0) { rewardsV.AddToBaseValue(deltaPoints); } }
public float GetGameValueComponent(string name, GameValue.GameValueComponent component) { GameValue gv = GetGameValueObject(name); if (gv == null) { return(0); } return(gv.GetValueComponent(component)); }
public float GetBaseGameValue(string name) { GameValue gv = GetGameValueObject(name); if (gv == null) { return(0); } return(gv.GetBaseValue()); }
public bool MultiplyRangedValue(string name, float value) { GameValue gv = GetGameValueObject(name); if (gv == null) { return(false); } return(gv.MultiplyRangedValue(value)); }
// careful with stacking.... // to remove multiply by reciprocal of orinal mutliplier value public bool MultiplyBaseModifier(string name, float value) { GameValue gv = GetGameValueObject(name); if (gv == null) { return(false); } return(gv.MultiplyBaseModifier(value)); }
public bool AddToBaseValue(string name, float value) { GameValue gv = GetGameValueObject(name); if (gv == null) { return(false); } return(gv.AddToBaseValue(value)); }
public bool ModifyValue(string name, GameValueModifierComponent component, GameValueModifierBehavior behavior, float value) { GameValue gv = GetGameValueObject(name); if (gv == null) { return(false); } return(gv.ModifyValue(component, behavior, value)); }
public static float GetGlobalValue(string name) { GameValue gv = GetGameValue(name); if (gv == null) { return(0); } return(gv.GetValue()); }
public static void RemoveModifiers(Dictionary <string, GameValue> gameValues, GameValueModifier[] mods, int count, string description) { for (int i = 0; i < mods.Length; i++) { GameValue gameValue = GetGameValue(gameValues, mods[i].gameValueName); if (gameValue != null) { gameValue.RemoveModifier(mods[i], count, (description + i.ToString()).GetPersistentHashCode()); } } }
void AddGameValue(GameValue template, bool logRepeat = true) { string k = template.name; if (gameValues.ContainsKey(k)) { Debug.LogWarning(this.name + ": adding duplicate game value named: '" + k + "'... only original will be used"); } else { gameValues[k] = new GameValue(template); } }
public GameValue(GameValue template) { this.name = template.name; this.description = template.description; this.useBaseModifiers = template.useBaseModifiers; this.isRangedValue = template.isRangedValue; this.randomInitialization = template.randomInitialization; this.initMin = template.initMin; this.initMax = template.initMax; this.rangedMax = template.rangedMax; ReInitialize(); }
void PrintModifiersSummary(Rect pos, SerializedProperty prop) { SerializedProperty modifiers = prop.FindPropertyRelative("modifiers"); for (int i = 0; i < modifiers.arraySize; i++) { SerializedProperty m = modifiers.GetArrayElementAtIndex(i); EditorGUI.LabelField(pos, m.FindPropertyRelative("description").stringValue + ": " + ((GameValue.GameValueComponent)m.FindPropertyRelative("modifyValueComponent").enumValueIndex) + " " + GameValue.ModifyBehaviorString((GameValueModifier.ModifyBehavior)m.FindPropertyRelative("modifyBehavior").enumValueIndex) + m.FindPropertyRelative("modifyValue").floatValue + (m.FindPropertyRelative("isStackable").boolValue ? "(" + m.FindPropertyRelative("count").intValue + ")" : "") ); pos.y += EditorGUIUtility.singleLineHeight; } }
void OnPointsChange(GameValue valueChanged, GameValueChangedComponent changedComponent, float baseDelta, float rangedValueDelta) { int basePoints = (int)pointsV.baseValue; int newLevel = levelFormula.LevelReached(basePoints); if (levelV.baseValue != newLevel) { levelV.SetBaseValue(newLevel); } // update 0-1 til next level up (xp bar in ui) if (baseDelta > 0) { BroadcastPointsChange01(basePoints, (int)baseDelta, newLevel); } }
static void InitializeDictionaryIfNull() { if (globalValuesDict == null) { globalValuesDict = new Dictionary <string, GameValue>(); List <GlobalGameValues> allValuesObjs = GameSettings.GetSettingsOfType <GlobalGameValues>(); for (int i = 0; i < allValuesObjs.Count; i++) { for (int x = 0; x < allValuesObjs[i].gameValues.Length; x++) { GameValue gv = new GameValue(allValuesObjs[i].gameValues[x]); globalValuesDict[gv.name] = gv; } } } }
public static void AddModifiers(Dictionary <string, GameValue> gameValues, GameValueModifier[] mods, int count, string description, bool assertPermanent, GameObject subject, GameObject target) { for (int i = 0; i < mods.Length; i++) { if (assertPermanent && !mods[i].isPermanent) { continue; } if (Conditions.ConditionsMet(mods[i].conditions, subject, target)) { GameValue gameValue = GetGameValue(gameValues, mods[i].gameValueName); if (gameValue != null) { gameValue.AddModifier(mods[i], count, (description + i.ToString()).GetPersistentHashCode(), description); } } } }
void OnLevelChange(GameValue valueChanged, GameValueChangedComponent changedComponent, float baseDelta, float rangedValueDelta) { int newLevel = (int)levelV.baseValue; // update xp in case we changed level value outside: if (levelFormula.LevelReached(pointsV.baseValue) != newLevel) { pointsV.SetBaseValue(levelFormula.PointsThreshold(newLevel)); } if (useRewards) { // prevent farming points if (newLevel > highestLevelV.baseValue) { highestLevelV.SetBaseValue(newLevel); } } }
void OnPlayerCreate() { OnPlayerDestroy(); container = DynamicObject.playerObject.GetObjectScript <GameValuesContainer>(); if (useRewards) { if (GameValueChecker.CheckGameValues(name, container, new GameValueCheck[] { new GameValueCheck(pointsName, false, false), new GameValueCheck(levelName, false, false), new GameValueCheck(highestLevelName, false, false), new GameValueCheck(rewardName, false, false), })) { levelV = container.GetGameValueObject(levelName); pointsV = container.GetGameValueObject(pointsName); highestLevelV = container.GetGameValueObject(highestLevelName); rewardsV = container.GetGameValueObject(rewardName); pointsV.AddChangeListener(OnPointsChange, false); levelV.AddChangeListener(OnLevelChange, false); highestLevelV.AddChangeListener(OnHighestLevelChange, false); } } else { if (GameValueChecker.CheckGameValues(name, container, new GameValueCheck[] { new GameValueCheck(pointsName, false, false), new GameValueCheck(levelName, false, false), })) { levelV = container.GetGameValueObject(levelName); pointsV = container.GetGameValueObject(pointsName); pointsV.AddChangeListener(OnPointsChange, false); levelV.AddChangeListener(OnLevelChange, false); } } }
public GameValue(GameValue template) { this.name = template.name; this.randomInitialization = template.randomInitialization; if (randomInitialization) { this.baseValue = UnityEngine.Random.Range(template.initMin, template.initMax); } else { this.baseValue = template.initMin; } valueCapped = template.valueCapped; capMin = template.capMin; capMax = template.capMax; initMin = template.initMin; initMax = template.initMax; this.description = template.description; }
public void AddModifiers(GameValueModifier[] modifiers, string description, bool assertPermanent, GameObject subject, GameObject target) { MakeValuesDictionaryIfNull(); GameValue.AddModifiers(gameValuesDict, modifiers, 1, description, assertPermanent, subject, target); }
public static bool ValueExists(string name, out GameValue value) { InitializeDictionaryIfNull(); return(globalValuesDict.TryGetValue(name, out value)); }
public void RemoveModifiers(GameValueModifier[] modifiers, string description) { MakeValuesDictionaryIfNull(); GameValue.RemoveModifiers(gameValuesDict, modifiers, 1, description); }