Example #1
0
        private void TargetHit(Map map)
        {
            var elements = _target.Buffs.Select(b => b.Element).Distinct();

            AbilityElement opposite = OppositeElement(Ability.Element);

            foreach (var buff in _target.Buffs.Where(b => b.Element == opposite))
            {
                buff.Lifetime = 0;
            }

            bool bonusDmg = elements.Contains(BonusElement(Ability.Element));
            int  modifier = bonusDmg ? 2 : 1;

            _target.Hp = Math.Max(0, _target.Hp - Ability.Dmg * modifier);

            _target.Buffs.Add(Ability.ElementalEffect);
            foreach (var abilityBuff in Ability.Buffs)
            {
                _target.Buffs.Add(abilityBuff.DeepCopy());
            }

            foreach (var areaBuff in Ability.AreaBuffs)
            {
                var affectedArea = map.AllCoords.Where(x => map.CubeDistance(x, _target.Coord) <= areaBuff.Radius);
                Utils.Log(LogSeverity.Debug, nameof(UsableAbility), $"Applying buffs at {map.Guid}");
                foreach (var coord in affectedArea)
                {
                    map.BuffsAt(coord).Add(areaBuff.Effect.DeepCopy());
                }
            }

            _mob.Ap -= Ability.Cost;
        }
Example #2
0
 //method to handle adding the ability game objects to the list and dictionary
 //dictionary adds abilities in abilityelement groups e.g. all fire ability elements would be grouped together for easy access of all fire type abilities.
 public void AddToAbilityDictionary(AbilityElement element, BaseAbility ability)
 {
     ability.gameObject.name = ability.abilityName;
     ability.abilityElement  = element;
     abilityDictionary.Add(ability.abilityName, ability);
     abilityElementsDictionary [element].Add(ability);
 }
Example #3
0
    private void Start()
    {
        foreach (Ability ability in abilityCollection)
        {
            AbilityElement element = Instantiate(elementPrefab);
            element.transform.SetParent(parent);

            element.Initialize(ability);
        }
    }
Example #4
0
 /// <summary>
 /// The constructor for an ability setting default values.
 /// </summary>
 /// <param name="cost">by default 2</param>
 /// <param name="intensity">by default 1</param>
 /// <param name="duration">by default 0</param>
 /// <param name="cooldown">by default 5</param>
 /// <param name="target"></param>
 /// <param name="element"></param>
 /// <param name="name"></param>
 /// <param name="description"></param>
 public Ability( int cost = 2, int intensity = 1, int duration = 0, int cooldown = 5, AbilityTarget target = AbilityTarget.None, AbilityElement element = AbilityElement.None, string name = "", string description = "")
 {
     _cost = cost;
     _intensity = intensity;
     _duration = duration;
     _cooldown = cooldown;
     _target = target;
     _element = element;
     if (name != "")
         _name = name;
     else
         GenerateName();
     _description = description;
     GetIcon();
 }
Example #5
0
        private AbilityElement OppositeElement(AbilityElement element)
        {
            switch (element)
            {
            case AbilityElement.Earth:
                return(AbilityElement.Air);

            case AbilityElement.Fire:
                return(AbilityElement.Water);

            case AbilityElement.Air:
                return(AbilityElement.Earth);

            case AbilityElement.Water:
                return(AbilityElement.Fire);

            default:
                throw new InvalidOperationException("Invalid element type");
            }
        }
Example #6
0
 /// <summary>
 /// Loading method
 /// </summary>
 /// <param name="reader"></param>
 public void Load(XmlReader reader)
 {
     _name = reader.GetAttribute("name");
     _icon = new ImageData(
         reader.GetAttribute("iconfile"),
         new Rectangle(Convert.ToInt32(reader.GetAttribute("clipRectX")),
         Convert.ToInt32(reader.GetAttribute("clipRectY")),
         Convert.ToInt32(reader.GetAttribute("clipRectW")),
         Convert.ToInt32(reader.GetAttribute("clipRectH"))),
         new Coords(Convert.ToInt32(reader.GetAttribute("iconoffsetX")),
         Convert.ToInt32(reader.GetAttribute("iconoffsetY"))),
         new Coords(Convert.ToInt32(reader.GetAttribute("iconcropX")),
         Convert.ToInt32(reader.GetAttribute("iconcropY"))));
     _description = reader.GetAttribute("description");
     _cost = Convert.ToInt32(reader.GetAttribute("cost"));
     _intensity = Convert.ToInt32(reader.GetAttribute("intensity"));
     _duration = Convert.ToInt32(reader.GetAttribute("duration"));
     _cooldown = Convert.ToInt32(reader.GetAttribute("cooldown"));
     _currentCool = Convert.ToInt32(reader.GetAttribute("currentCool"));
     if (reader.GetAttribute("target") != null)
         _target = (AbilityTarget)Enum.Parse(typeof(AbilityTarget), reader.GetAttribute("target"));
     if (reader.GetAttribute("element") != null)
         _element = (AbilityElement)Enum.Parse(typeof(AbilityElement), reader.GetAttribute("element"));
 }