private void TriggerEvent(StatRecord record) { if (record != null && _events.TryGetValue(record, out var @event)) { @event.Invoke(record); } }
public void GetValueUsesCustomOperatorOrderOnSettings() { var ooo = ScriptableObject.CreateInstance <OrderOfOperations>(); var o = ooo.Operators[0]; ooo.Operators.RemoveAt(0); ooo.Operators.Add(o); settings.OrderOfOperations = ooo; var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 4f); var r = new StatRecord(d); r.modifierAdd.Set("a", 4); r.modifierSubtract.Set("a", 2); r.modifierMultiply.Set("a", 4); r.modifierDivide.Set("a", 2); var result = 4 - 2; result += result * 4; result /= 2; result += 4; Assert.AreEqual(result, r.GetValue()); }
public void GetBaseValue() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); Assert.AreEqual(2, r.GetValue()); }
/// <summary> /// Retrieve an int value by record with an optional index /// </summary> /// <param name="record"></param> /// <param name="index"></param> /// <returns></returns> public int GetStatInt(StatRecord record, float index = 0) { if (record == null) { return(0); } return(Mathf.RoundToInt(record.GetValue(index))); }
private void loadItems() { foreach (int addr in RecordAddresses()) { var r = new StatRecord(M, addr); records.Add(r.Key, r); } }
private void loadItems() { foreach (var addr in RecordAdresses()) { StatRecord r = new StatRecord(m, addr); records.Add(r.Key, r); } }
public void GetValueWithoutModifier() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); var result = r.GetValue(); Assert.AreEqual(2, result); }
/// <summary> /// Retrieve a float value by record with an optional index /// </summary> /// <param name="record"></param> /// <param name="index"></param> /// <returns></returns> public float GetStat(StatRecord record, float index = 0) { if (record == null) { return(0); } return(record.GetValue(index)); }
public async Task CreateStatRecord(Player player) { List <Skill> skills = new List <Skill>(); List <Minigame> minigames = new List <Minigame>(); var apiData = await OfficialApiCall(_address + player.Username); if (apiData == null) { return; } string[] lines = apiData.Split('\n'); // adding a StatRecord object StatRecord newStatRecord = new StatRecord() { DateCreated = DateTime.Now, UserId = player.Id, Player = player }; // looping through the skills and adding them for (var i = 0; i < _totalSkills; i++) { String[] stat = lines[i].Split(','); Skill skill = new Skill() { SkillId = i, Xp = Int64.Parse(stat[2]), Level = Int32.Parse(stat[1]), Rank = Int32.Parse(stat[0]), StatRecordId = newStatRecord.Id }; skill.Xp = skill.Xp < 0 ? 0 : skill.Xp; skill.Rank = skill.Rank < 0 ? 0 : skill.Rank; skills.Add(skill); } // looping through the minigames and adding them for (var i = _totalSkills; i < lines.Length - 1; i++) { String[] stat = lines[i].Split(','); Minigame minigame = new Minigame() { MinigameId = i, Score = Int32.Parse(stat[1]), Rank = Int32.Parse(stat[0]), StatRecordId = newStatRecord.Id }; minigame.Score = minigame.Score < 0 ? 0 : minigame.Score; minigame.Rank = minigame.Rank < 0 ? 0 : minigame.Rank; minigames.Add(minigame); } newStatRecord.Skills = skills; newStatRecord.Minigames = minigames; player.StatRecords.Add(newStatRecord); }
public void GetValueRoundsForceRoundedDefinitions() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundResult", true); var r = new StatRecord(d); Assert.AreEqual(2, r.GetValue()); }
/// <summary> /// Wipe all modifiers (add, sub, mult, div) on a particular record /// </summary> /// <param name="record"></param> /// <param name="modifierId"></param> public void ClearAllModifiers(StatRecord record, string modifierId) { RemoveModifier(OperatorType.Add, record, modifierId); RemoveModifier(OperatorType.Subtract, record, modifierId); RemoveModifier(OperatorType.Multiply, record, modifierId); RemoveModifier(OperatorType.Divide, record, modifierId); TriggerEvent(record); }
/// <summary> /// Set a modifier by ID and value /// </summary> /// <param name="operation"></param> /// <param name="record"></param> /// <param name="modifierId"></param> /// <param name="value"></param> public void SetModifier(OperatorType operation, StatRecord record, string modifierId, float value) { if (record == null) { return; } record.GetModifier(operation).Set(modifierId, value); TriggerEvent(record); }
public void GetValueStoresLastRetrievedValue() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.modifierAdd.Set("a", 2f); r.GetValue(); Assert.AreEqual(4, r.LastRetrievedValue); }
public void OnStatChangeSubscribe(StatRecord record, UnityAction <StatRecord> callback) { if (!_events.TryGetValue(record, out var @event)) { @event = new StatRecordEvent(); _events[record] = @event; } @event.AddListener(callback); }
public void ModifierNotForceRoundedWithoutOperatorForceRound() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundResult", true); var r = new StatRecord(d); r.modifierMultiply.Set("a", 0.05f); Assert.AreEqual(3, r.GetValue(3f)); }
public void ChangingModifierChangesCachedValueLookups() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.modifierAdd.Set("a", 2f); r.GetValue(); r.modifierAdd.Set("a", 4f); Assert.AreEqual(6, r.GetValue()); }
private void loadItems() { foreach (int addr in RecordAddresses()) { var r = new StatRecord(M, addr); if (!records.ContainsKey(r.Key)) { records.Add(r.Key, r); } } }
public void ModifierIsNotForceRoundedWhenDefinitionForceRoundFalse() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundModifiers", false); var r = new StatRecord(d); r.modifierAdd.Set("a", 2.4f); Assert.AreEqual(4.8f, r.GetValue()); }
private void loadItems() { var iCounter = 1; foreach (var addr in RecordAddresses()) { var r = new StatRecord(M, addr, iCounter++); records[r.Key] = r; recordsById[r.ID] = r; } }
public void It_should_subscribe_with_a_definition() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); copy.OnStatChangeSubscribe(_health, (record) => result = record); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); Assert.AreEqual(5f, result.GetValue()); }
public void ModifierIsForceRoundedWithDefinitionForceRound() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2.4f); SetPrivateField(d, "_roundResult", true); SetPrivateField(d, "_roundModifiers", true); var r = new StatRecord(d); r.modifierAdd.Set("a", 2.4f); Assert.AreEqual(4, r.GetValue()); }
public void It_should_return_the_new_value_on_SetModifier() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); copy.OnStatChangeSubscribe("health", (record) => result = record); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); Assert.AreEqual(5f, result.GetValue()); }
private void loadItems() { int iCounter = 1; foreach (long addr in RecordAddresses()) { var r = new StatRecord(M, addr, iCounter++); if (!records.ContainsKey(r.Key)) { records.Add(r.Key, r); } } }
/// <summary> /// Remove a modifier by ID /// </summary> /// <param name="operation"></param> /// <param name="record"></param> /// <param name="modifierId"></param> /// <returns></returns> public bool RemoveModifier(OperatorType operation, StatRecord record, string modifierId) { if (record == null) { return(false); } var result = record.GetModifier(operation).Remove(modifierId); TriggerEvent(record); return(result); }
public void It_should_trigger_an_event_on_RemoveModifier() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); copy.OnStatChangeSubscribe("health", (record) => result = record); copy.RemoveModifier(OperatorType.Add, "health", "plus"); Assert.AreEqual(0f, result.GetValue()); }
public void GetValueWithEveryModifer() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var r = new StatRecord(d); r.modifierAdd.Set("a", 4); r.modifierSubtract.Set("a", 2); r.modifierMultiply.Set("a", 3); r.modifierDivide.Set("a", 2); var result = r.GetValue(); Assert.AreEqual(8, result); }
private async Task <StatRecord> CreateStatRecord(User user) { List <Skill> skills = new List <Skill>(); List <Minigame> minigames = new List <Minigame>(); var apiData = await OfficialApiCall(user.Username); string[] lines = apiData.Split('\n'); // adding a StatRecord object StatRecord newStatRecord = new StatRecord() { DateCreated = DateTime.Now, UserId = user.Id, }; // looping through the skills and adding them for (int i = 0; i < _totalSkills; i++) { String[] stat = lines[i].Split(','); Skill skill = new Skill() { SkillId = i, Xp = Int64.Parse(stat[2]), Level = Int32.Parse(stat[1]), Rank = Int32.Parse(stat[0]), StatRecordId = newStatRecord.Id }; skills.Add(skill); } // looping through the minigames and adding them for (int i = _totalSkills; i < lines.Length - 1; i++) { String[] stat = lines[i].Split(','); Minigame minigame = new Minigame() { MinigameId = i, Score = Int32.Parse(stat[1]), Rank = Int32.Parse(stat[0]), StatRecordId = newStatRecord.Id }; minigames.Add(minigame); } newStatRecord.Skills = skills; newStatRecord.Minigames = minigames; return(newStatRecord); }
public void GetBaseValueOverride() { var d = TestStatValueSelector.CreateDefinition(StatValueType.Float, 2); var statOverride = new StatValueSelector { type = StatValueType.Int }; var sInt = (StatValueInt)statOverride.GetValue(); sInt.value = 8; var r = new StatRecord(d, statOverride); Assert.AreEqual(8, r.GetBaseValue()); }
public void It_should_remove_the_passed_subscription_via_string() { _health.Value.GetValue().SetInt(0); StatRecord result = null; var copy = _container.CreateRuntimeCopy(); var record = copy.GetRecord("health"); var action = new UnityAction <StatRecord>(r => result = r); copy.OnStatChangeSubscribe(record, action); copy.OnStatChangeUnsubscribe("health", action); copy.SetModifier(OperatorType.Add, "health", "plus", 5f); Assert.IsNull(result); }
/// <summary> /// Retrieve the value of a modifier /// </summary> /// <param name="operation"></param> /// <param name="record"></param> /// <param name="modifierId"></param> /// <returns></returns> public float GetModifier(OperatorType operation, StatRecord record, string modifierId) { if (record == null) { return(0); } var modifier = record.GetModifier(operation).Get(modifierId); if (modifier == null) { return(0); } return(modifier.value); }