Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using GrimoireEngine.Framework.Game;
- using GrimoireEngine.Framework.Interfaces;
- using GrimoireEngine.Framework.Logic;
- using GrimoireEngine.Framework.Maths;
- namespace GrimoireEngine.Framework.Collections
- {
- public class PrimaryAttributes : IEquatable<PrimaryAttributes>, ICopy<PrimaryAttributes>
- {
- private int _strength;
- private int _agility;
- private int _stamina;
- private int _intellect;
- private int _wisdom;
- private int _spirit;
- private int _luck;
- public const int Minimum = GameConstants.MinimumAttribute;
- public const int Maximum = GameConstants.MaximumAttribute;
- private static AttributeType[] _keys = (AttributeType[])Enum.GetValues(typeof(AttributeType));
- public AttributeType[] Keys
- {
- get
- {
- return _keys;
- }
- }
- public int Total
- {
- get
- {
- return _strength + _agility + _stamina + _intellect + _wisdom + _spirit + _luck;
- }
- }
- public int Strength
- {
- get { return _strength; }
- set { _strength = Clamp(value); }
- }
- public int Agility
- {
- get { return _agility; }
- set { _agility = Clamp(value); }
- }
- public int Stamina
- {
- get { return _stamina; }
- set { _stamina = Clamp(value); }
- }
- public int Intellect
- {
- get { return _intellect; }
- set { _intellect = Clamp(value); }
- }
- public int Wisdom
- {
- get { return _wisdom; }
- set { _wisdom = Clamp(value); }
- }
- public int Spirit
- {
- get { return _spirit; }
- set { _spirit = Clamp(value); }
- }
- public int Luck
- {
- get { return _luck; }
- set { _luck = Clamp(value); }
- }
- public AttributeType Highest
- {
- get
- {
- int value = (Minimum - 1);
- AttributeType highest = AttributeType.Strength;
- for (int i = 0; i < this.Keys.Length; i++)
- {
- int attributeValue = GetAttribute(this.Keys[i]);
- if (attributeValue > value)
- {
- highest = this.Keys[i];
- value = attributeValue;
- }
- }
- return highest;
- }
- }
- public AttributeType Lowest
- {
- get
- {
- int value = (Maximum + 1);
- AttributeType lowest = AttributeType.Strength;
- for (int i = 0; i < this.Keys.Length; i++)
- {
- int attributeValue = GetAttribute(this.Keys[i]);
- if (attributeValue < value)
- {
- lowest = this.Keys[i];
- value = attributeValue;
- }
- }
- return lowest;
- }
- }
- public PrimaryAttributes()
- {
- }
- public PrimaryAttributes(int strength, int agility, int stamina, int intellect, int wisdom, int spirit,
- int luck)
- {
- Copy(strength,agility,stamina,intellect,wisdom,spirit,luck);
- }
- public void Copy(int strength, int agility, int stamina, int intellect, int wisdom, int spirit,
- int luck)
- {
- this.Strength = strength;
- this.Agility = agility;
- this.Stamina = stamina;
- this.Intellect = intellect;
- this.Wisdom = wisdom;
- this.Spirit = spirit;
- this.Luck = luck;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public int GetHealth()
- {
- return ((_stamina + GetSpiritModifier()) * 24);
- }
- public int GetAttackpower()
- {
- return (_strength + ((_agility + (_spirit * 2)) / 2));
- }
- public int GetSpellpower()
- {
- return (_intellect + ((_wisdom + (_spirit * 2)) / 2));
- }
- public int GetSpiritModifier()
- {
- return (_spirit / 2);
- }
- public float GetCriticalstrike()
- {
- return ((_luck / 5f) / 100f);
- }
- public int GetAttribute(AttributeType attribute, bool includeSpiritModifier = false)
- {
- switch (attribute)
- {
- case AttributeType.Strength:
- return includeSpiritModifier ? (this._strength + GetSpiritModifier()) : this._strength;
- case AttributeType.Agility:
- return includeSpiritModifier ? (this._agility + GetSpiritModifier()) : this._agility;
- case AttributeType.Stamina:
- return includeSpiritModifier ? (this._stamina + GetSpiritModifier()) : this._stamina;
- case AttributeType.Intellect:
- return includeSpiritModifier ? (this._intellect + GetSpiritModifier()) : this._intellect;
- case AttributeType.Wisdom:
- return includeSpiritModifier ? (this._wisdom + GetSpiritModifier()) : this._wisdom;
- case AttributeType.Spirit:
- return includeSpiritModifier ? (this._spirit + GetSpiritModifier()) : this._spirit;
- case AttributeType.Luck:
- return includeSpiritModifier ? (this._luck + GetSpiritModifier()) : this._luck;
- default:
- throw new ArgumentOutOfRangeException(nameof(attribute), attribute, null);
- }
- }
- public void SetAttribute(AttributeType attribute, int value)
- {
- switch (attribute)
- {
- case AttributeType.Strength:
- Strength = value;
- break;
- case AttributeType.Agility:
- Agility = value;
- break;
- case AttributeType.Stamina:
- Stamina = value;
- break;
- case AttributeType.Intellect:
- Intellect = value;
- break;
- case AttributeType.Wisdom:
- Wisdom = value;
- break;
- case AttributeType.Spirit:
- Spirit = value;
- break;
- case AttributeType.Luck:
- Luck = value;
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(attribute), attribute, null);
- }
- }
- public void Multiply(AttributeType attribute, float multiplier)
- {
- SetAttribute(attribute, (int)(GetAttribute(attribute) * multiplier));
- }
- public void IncreaseAttribute(AttributeType attribute, int amount)
- {
- SetAttribute(attribute, GetAttribute(attribute) + amount);
- }
- public void DecreaseAttribute(AttributeType attribute, int amount)
- {
- SetAttribute(attribute, GetAttribute(attribute) - amount);
- }
- public void Clear()
- {
- _strength = Minimum;
- _agility = Minimum;
- _stamina = Minimum;
- _intellect = Minimum;
- _wisdom = Minimum;
- _spirit = Minimum;
- _luck = Minimum;
- }
- public void Clear(AttributeType attribute)
- {
- SetAttribute(attribute, 0);
- }
- public Dictionary<AttributeType, int> ToDictionary()
- {
- Dictionary<AttributeType, int> attributes = new Dictionary<AttributeType, int>
- {
- {AttributeType.Strength, _strength},
- {AttributeType.Agility, _agility},
- {AttributeType.Stamina, _stamina},
- {AttributeType.Intellect, _intellect},
- {AttributeType.Wisdom, _wisdom},
- {AttributeType.Spirit, _spirit},
- {AttributeType.Luck, _luck},
- };
- return attributes;
- }
- public void Add(PrimaryAttributes other)
- {
- this.Strength += other._strength;
- this.Agility += other._agility;
- this.Stamina += other._stamina;
- this.Intellect += other._intellect;
- this.Wisdom += other._wisdom;
- this.Spirit += other._spirit;
- this.Luck += other._luck;
- }
- public void Subtract(PrimaryAttributes other)
- {
- this.Strength -= other._strength;
- this.Agility -= other._agility;
- this.Stamina -= other._stamina;
- this.Intellect -= other._intellect;
- this.Wisdom -= other._wisdom;
- this.Spirit -= other._spirit;
- this.Luck -= other._luck;
- }
- private static int Clamp(int value)
- {
- return GrimoireMathHelper.Clamp(value, Minimum, Maximum);
- }
- public void Copy(PrimaryAttributes other)
- {
- _strength = other._strength;
- _agility = other._agility;
- _stamina = other._stamina;
- _intellect = other._intellect;
- _wisdom = other._wisdom;
- _spirit = other._spirit;
- _luck = other._luck;
- }
- public PrimaryAttributes MakeCopy()
- {
- PrimaryAttributes attributes = new PrimaryAttributes();
- attributes.Copy(this);
- return attributes;
- }
- public bool Equals(PrimaryAttributes other)
- {
- return other != null && (
- _strength == other._strength &&
- _agility == other._agility &&
- _stamina == other._stamina &&
- _intellect == other._intellect &&
- _wisdom == other._wisdom &&
- _spirit == other._spirit &&
- _luck == other._luck);
- }
- public override bool Equals(object obj)
- {
- return obj != null && Equals((PrimaryAttributes)obj);
- }
- public override int GetHashCode()
- {
- unchecked
- {
- int hashCode = _strength;
- hashCode = (hashCode * 397) ^ _agility;
- hashCode = (hashCode * 397) ^ _stamina;
- hashCode = (hashCode * 397) ^ _intellect;
- hashCode = (hashCode * 397) ^ _wisdom;
- hashCode = (hashCode * 397) ^ _spirit;
- hashCode = (hashCode * 397) ^ _luck;
- return hashCode;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement