Exemplo n.º 1
0
        /// <summary>
        /// Applies the effects of the ability being used on all of it's targets.
        /// </summary>
        /// <param name="attacker">The entity performing the ability.</param>
        /// <param name="ability">The ability to apply the effects of.</param>
        /// <param name="targets">The targets of the ability.</param>
        private void ApplyEffects(CombatEntity attacker, Ability ability, IEnumerable <CombatEntity> targets)
        {
            bool isCrit = IsCritical(attacker, ability);

            foreach (var target in targets)
            {
                var damage  = DamageCalculator.GetTotalDamage(attacker, target, ability, isCrit);
                var healing = DamageCalculator.GetHeal(attacker, ability, isCrit);
                healing += target.Resources.MaxHealth * ability.PercentHeal / 100;

                target.Resources.CurrentHealth += healing;
                target.Resources.CurrentHealth -= DamageCalculator.GetDamageTypesAsInt(damage);
                if (target.Resources.CurrentHealth > 0)
                {
                    _statusEffectManager.Apply(target, attacker, ability.AppliedStatusEffects, isCrit);
                    if (target.Resources.CurrentHealth > target.Resources.MaxHealth)
                    {
                        target.Resources.CurrentHealth = target.Resources.MaxHealth;
                    }
                }
                else
                {
                    _statusEffectManager.RemoveAll(target);
                    target.Resources.CurrentHealth = 0;
                }
            }

            if (ability.SelfAppliedStatusEffects.Any())
            {
                _statusEffectManager.Apply(attacker, attacker, ability.SelfAppliedStatusEffects, isCrit);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Equips an item onto a CombatEntity and applys its effects. Will unequip any items that also belong to the
        /// same EquipPosition as the item being applied.
        /// </summary>
        /// <param name="entity">The CombatEntity to equip the item on to.</param>
        /// <param name="item">The item to equip.</param>
        /// <returns>Returns true if the operation was successful. Will fail if the item is unequippable.</returns>
        public bool Equip(CombatEntity entity, Item item)
        {
            if (!item.IsEquippable)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(item.Type.EquipPosition))
            {
                return(false);
            }

            var oldItem = entity.EquippedItems.FirstOrDefault(i => i.Type.EquipPosition == item.Type.EquipPosition);

            Unequip(entity, oldItem);

            entity.PlayerInventory.Items.Remove(item);
            var tracking = entity.PlayerInventory.TrackedItems.FirstOrDefault(i => i.BaseItemId == item.Id);

            if (tracking != null)
            {
                entity.PlayerInventory.TrackedItems.Remove(tracking);
                entity.TrackedItems.Add(tracking);
            }

            entity.EquippedItems.Add(item);
            entity.Abilities.AddRange(item.EquippedAbilities);
            entity.SecondaryStats += item.SecondaryStats;
            entity.Stats          += item.Stats;
            _statusEffectManager.Apply(entity, entity, item.SelfAppliedStatusEffects);
            ChangeIconUri(entity, item.Type.EquipPosition, item.EquipIconUri);
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs a flee action for the provided CombatEntity.
        /// </summary>
        /// <param name="actor">The CombatEntity performing the flee action.</param>
        /// <param name="actorFormation">The Formation of the CombatEntity performing the flee action.</param>
        /// <returns>Contains an IEnumerable of CombatEntities affected by the flee or defend command.</returns>
        private IEnumerable <CombatEntity> PerformFlee(CombatEntity actor, Formation actorFormation)
        {
            IEnumerable <CombatEntity> affectedEntities = null;

            var task = _statusEffectRepo.GetDataAsync();

            task.Wait();

            var statusEffects = task.Result;
            var fleeStatus    = statusEffects.FirstOrDefault(se => se.Id == GameplayConstants.FleeingStatusEffectId);

            lock (_key)
            {
                _statusEffectManager.Apply(actor, actor, fleeStatus);
                _battle.ActionsLeftPerFormation[actorFormation].Remove(actor);
            }

            affectedEntities = new List <CombatEntity> {
                actor
            };

            return(affectedEntities);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a CombatEntity using an EnemyEntityBase. The result is an ai-controlled CombatEntity.
        /// </summary>
        /// <param name="entityBase">The base to use for the resultant CombatEntity.</param>
        /// <returns></returns>
        public CombatEntity Create(AiEntityBase entityBase)
        {
            var secondaryStats = StatsCalculator.GetSecondaryStats(entityBase.Stats);

            secondaryStats += entityBase.SecondaryStats;

            int health    = entityBase.Resources.MaxHealth + StatsCalculator.GetHealth(entityBase.Stats);
            int mana      = entityBase.Resources.MaxMana + StatsCalculator.GetMana(entityBase.Stats);
            var resources = new ResourceStats
            {
                CurrentHealth       = health,
                CurrentMana         = mana,
                MaxHealth           = health,
                MaxMana             = mana,
                UnmodifiedMaxHealth = health,
                UnmodifiedMaxMana   = mana
            };

            var iconUris = new CharacterIconSet(entityBase.IconUris);
            var entity   = new CombatEntity
            {
                Id              = _id++,
                Name            = entityBase.Name,
                OwnerId         = GameplayConstants.AiId,
                IconUris        = iconUris,
                Abilities       = entityBase.Abilities,
                ComboCounter    = 0,
                OwnerName       = entityBase.FactionName,
                Stats           = entityBase.Stats.Copy(),
                SecondaryStats  = entityBase.SecondaryStats,
                StatusEffects   = new List <AppliedStatusEffect>(),
                UnmodifiedStats = entityBase.Stats,
                Resources       = resources
            };

            _statusEffectManager.Apply(entity, entity, entityBase.StatusEffects);

            return(entity);
        }