예제 #1
0
        public void UpdateFromModifierChanges()
        {
            var template = new StatTemplate()
            {
                Name     = "Current Health",
                MaxValue = 1000
            };
            var instance = template.CreateInstance(CharacterTrait.MaxMana);

            var static5         = new EventField <float> (5);
            var changeFrom5to10 = new EventField <float> (5);

            Assert.AreEqual(0.0f, instance.Value);

            var modifier = new StatModifier(StatModificationPhase.Typical, StatModificationType.Additive, static5);

            instance.AddModifier(modifier);

            Assert.AreEqual(5.0f, instance.Value);

            var anotherModifier = new StatModifier(StatModificationPhase.Typical, StatModificationType.Additive, changeFrom5to10);

            instance.AddModifier(anotherModifier);

            Assert.AreEqual(10.0f, instance.Value);

            changeFrom5to10.Value = 10.0f;

            Assert.AreEqual(15.0f, instance.Value);
        }
예제 #2
0
 public StatInstance(Entity parent, StatTemplate stat)
 {
     _parent   = parent;
     Stat      = stat;
     Modifiers = new List <StatModifier>();
     Refresh();
 }
예제 #3
0
        public void UnsubscribeModifierWhenRemoved()
        {
            var template = new StatTemplate()
            {
                Name     = "Current Health",
                MaxValue = 1000
            };
            var instance = template.CreateInstance(CharacterTrait.MaxMana);

            var changingModifierValue = new EventField <float> (5);

            Assert.AreEqual(0.0f, instance.Value);

            var modifier = new StatModifier(StatModificationPhase.Typical, StatModificationType.Additive, changingModifierValue);

            instance.AddModifier(modifier);

            Assert.AreEqual(5.0f, instance.Value);

            changingModifierValue.Value = 10.0f;

            Assert.AreEqual(10.0f, instance.Value);

            instance.RemoveModifier(modifier);

            Assert.AreEqual(0.0f, instance.Value);

            changingModifierValue.Value = 15.0f;

            Assert.AreEqual(0.0f, instance.Value);
        }
예제 #4
0
        public void UpdateFromModifierChanges()
        {
            StatIdentifier genericStat = "generic_stat";

            var template = new StatTemplate()
            {
                Name     = "Generic Stat",
                MaxValue = 1000
            };
            var instance = template.CreateInstance(genericStat);

            var static5         = new EventField <float>(5);
            var changeFrom5to10 = new EventField <float>(5);

            Assert.AreEqual(0.0f, instance.Value);

            var modifier = new StatModifier(StatModificationPhase.Typical, StatModificationType.Additive, static5);

            instance.AddModifier(modifier);

            Assert.AreEqual(5.0f, instance.Value);

            var anotherModifier = new StatModifier(StatModificationPhase.Typical, StatModificationType.Additive, changeFrom5to10);

            instance.AddModifier(anotherModifier);

            Assert.AreEqual(10.0f, instance.Value);

            changeFrom5to10.Value = 10.0f;

            Assert.AreEqual(15.0f, instance.Value);
        }
예제 #5
0
        public void UnsubscribeModifierWhenRemoved()
        {
            StatIdentifier genericStat = "generic_stat";

            var template = new StatTemplate()
            {
                Name     = "Generic Stat",
                MaxValue = 1000
            };
            var instance = template.CreateInstance(genericStat);

            var changingModifierValue = new EventField <float>(5);

            Assert.AreEqual(0.0f, instance.Value);

            var modifier = new StatModifier(StatModificationPhase.Typical, StatModificationType.Additive, changingModifierValue);

            instance.AddModifier(modifier);

            Assert.AreEqual(5.0f, instance.Value);

            changingModifierValue.Value = 10.0f;

            Assert.AreEqual(10.0f, instance.Value);

            instance.RemoveModifier(modifier);

            Assert.AreEqual(0.0f, instance.Value);

            changingModifierValue.Value = 15.0f;

            Assert.AreEqual(0.0f, instance.Value);
        }
예제 #6
0
 public void AddStat(StatTemplate stat)
 {
     if (_stats.ContainsKey(stat.Key))
     {
         throw new MeException($"Attempted to add stat with key {stat.Key}, but a stat with this key already exists.");
     }
     _stats.Add(stat.Key, stat);
 }
예제 #7
0
파일: Entity.cs 프로젝트: Bluegent/MeRpgBot
 public void AddStat(StatTemplate stat)
 {
     if (Stats.ContainsKey(stat.Key))
     {
         return;
     }
     Stats.Add(stat.Key, new StatInstance(this, stat));
     RefreshProperties();
 }
예제 #8
0
        public StatTemplate FromJson(JObject json)
        {
            StatTemplate result = new StatTemplate();

            result.LoadBase(json);

            string formulaString =
                JsonUtils.ValidateJsonEntry(GcConstants.General.FORMULA, json, JTokenType.String, $"Missing formula for stat {result.Name}.").ToString();

            result.Formula = TreeConverter.Build(formulaString, _engine);

            return(result);
        }
예제 #9
0
        public void LoadStatsFromFile(string path)
        {
            StatReader reader = new StatReader(_engine);
            JArray     json   = FileHandler.FromPath <JArray>(path);

            foreach (JToken entry in json)
            {
                if (entry.Type != JTokenType.Object)
                {
                    throw new MeException($"Expected a json object \"{path}\"at  \"{entry}\".");
                }

                StatTemplate newEntry = reader.FromJson(entry.ToObject <JObject>());
                AddStat(newEntry);
            }
        }
예제 #10
0
 public ITraitContextBuilder UseTrait(StatIdentifier statIdentifier, StatTemplate statTemplate)
 {
     statIdentifiers.Add(statIdentifier);
     statMapping.Add(statIdentifier, statTemplate);
     return(this);
 }