Esempio n. 1
0
        // Convenience method for getting the stat
        public static int StatisticValue(this CreatureStatistics creatureStatistics, Statistics stat)
        {
            switch (stat)
            {
            case Statistics.Strength:
                return(creatureStatistics.Strength);

            case Statistics.Dexterity:
                return(creatureStatistics.Dexterity);

            case Statistics.Constitution:
                return(creatureStatistics.Constitution);

            case Statistics.Intelligence:
                return(creatureStatistics.Intelligence);

            case Statistics.Wisdom:
                return(creatureStatistics.Wisdom);

            case Statistics.Charisma:
                return(creatureStatistics.Charisma);

            default:
                return(0);
            }
        }
Esempio n. 2
0
        // Returns a stat array that represents modifiers to the char's existing stats
        // If I wanted to model stuff like the giant belts I'd probably split that mechanism out
        // into a separate function
        private static CreatureStatistics determineStatisticAdjustments(Character character)
        {
            CreatureStatistics statModifiers = new CreatureStatistics();

            // Looks like the only thing we've got in the model that affects this right now is items
            foreach (CharacterItem item in character.Items)
            {
                applyItemModifierToStats(item, statModifiers);
            }

            return(statModifiers);
        }
Esempio n. 3
0
 public static CreatureStatistics Copy(this CreatureStatistics statistics)
 {
     return(new CreatureStatistics()
     {
         Strength = statistics.Strength,
         Dexterity = statistics.Dexterity,
         Constitution = statistics.Constitution,
         Intelligence = statistics.Intelligence,
         Wisdom = statistics.Wisdom,
         Charisma = statistics.Charisma
     });
 }
Esempio n. 4
0
        // Takes an items, looks at its modifier object, and adjusts the statistics accordingly
        private static void applyItemModifierToStats(CharacterItem item, CreatureStatistics statistics)
        {
            if (item == null)
            {
                return;
            }
            if (item.Modifier == null)
            {
                return;
            }

            // If we're not affecting the stats array, dont bother.
            if (!CharacterJsonConstants.ObjectTypeStats.Equals(item.Modifier.AffectedObject?.ToLower()))
            {
                return;
            }

            switch (item.Modifier.AffectedValue?.ToLower())
            {
            case CharacterJsonConstants.StatStrength:
                statistics.Strength += item.Modifier.Value;
                break;

            case CharacterJsonConstants.StatDexterity:
                statistics.Dexterity += item.Modifier.Value;
                break;

            case CharacterJsonConstants.StatConstitution:
                statistics.Constitution += item.Modifier.Value;
                break;

            case CharacterJsonConstants.StatIntelligence:
                statistics.Intelligence += item.Modifier.Value;
                break;

            case CharacterJsonConstants.StatWisdom:
                statistics.Wisdom += item.Modifier.Value;
                break;

            case CharacterJsonConstants.StatCharisma:
                statistics.Charisma += item.Modifier.Value;
                break;

            default:
                break;
            }
        }
Esempio n. 5
0
        // Rather than storing the item-adjusted statistics on the model
        // I've chosen to calculate them when I need them - it's not computationally hard
        // and it keeps me from having to ensure two data structures are accurate.
        public static CreatureStatistics DerivedStatistics(this Character character)
        {
            CreatureStatistics creatureStatistics = character.Stats.Copy();

            // Theoretically we could apply the adjustments right to the stats here, but
            // it seemed like it might be nice to resolve all of the item bonuses first
            // If we ever do stuff like giant belts we'll want to be aware of the order we
            // do things in (eg my Str is set to 21, but another str bonus item shouldn't raise it past 20)
            CreatureStatistics statModifiers = determineStatisticAdjustments(character);

            creatureStatistics.Strength     += statModifiers.Strength;
            creatureStatistics.Dexterity    += statModifiers.Dexterity;
            creatureStatistics.Constitution += statModifiers.Constitution;
            creatureStatistics.Intelligence += statModifiers.Intelligence;
            creatureStatistics.Wisdom       += statModifiers.Wisdom;
            creatureStatistics.Charisma     += statModifiers.Charisma;

            return(creatureStatistics);
        }
Esempio n. 6
0
 // Gets the modifier value ((stat-10)/2, round down) for the given stat block and statistic
 public static int Modifier(this CreatureStatistics creatureStatistics, Statistics stat)
 {
     return(determineStatModifier(creatureStatistics.StatisticValue(stat)));
 }