Пример #1
0
        public void ChangeHealth(AttackEventArgs args, bool animate)
        {
            if (Stats.Hp != Stats.MaxHp || args.Damage < 0)
            {
                Stats.Hp += args.Damage;

                if (animate)
                {
                    HealthChanged.Invoke(args);
                }
            }
        }
Пример #2
0
        private void UpdateStatusEffects(GameTime gameTime)
        {
            foreach (Skill skill in AvailableSkills.FindAll(x => x.Type == SkillType.Passive))
            {
                foreach (StatusEffect skillPassive in skill.TargetEffects)
                {
                    if (!StatusEffects.Contains(skillPassive))
                        StatusEffects.Add(skillPassive);
                }
            }

            bool healingFromItem = false;

            for (int i = 0; i < StatusEffects.Count; i++)
            {
                StatusEffect effect = StatusEffects[i];

                // Se o efeito é ao longo do tempo
                if (effect.EffectTick > 0)
                {
                    // Só um item de regeneração (poção) funciona de cada vez)
                    if (!healingFromItem)
                    {
                        healingFromItem = true;

                        effect.EffectTickTimer += (float) gameTime.ElapsedGameTime.TotalMilliseconds;
                        effect.EffectTimer += (float) gameTime.ElapsedGameTime.TotalMilliseconds;

                        if (effect.EffectTickTimer > effect.EffectTick)
                        {
                            effect.EffectTickTimer = 0;

                            // Animate if its damage
                            bool animate = effect.HealthRegenTick < 0;
                            var args = new AttackEventArgs(this, this, effect.HealthRegenTick, animate);
                            ChangeHealth(args, animate);

                            float health = Stats.MaxHp;
                            animate = effect.HealthPercentTick < 0;
                            var args2 = new AttackEventArgs(this, this, (int) (effect.HealthPercentTick*health/100),
                                animate);
                            ChangeHealth(args2, animate);
                        }

                        if (effect.EffectTimer >= effect.EffectDuration)
                        {
                            effect.EffectTickTimer = 0;
                            effect.EffectTimer = 0;
                            StatusEffects.RemoveAt(i);
                            i--;
                        }
                    }
                }

                    // Se é um efeito instantaneo
                    #region Instant Effects

                else
                {
                    if (effect.PermanentEffect)
                    {
                        // Adicionar modificadores do efeito
                        if (effect.EffectTimer == 0)
                        {
                            Stats.AttackSpeedModifier += effect.AttackSpeedPercentage;
                            Stats.ArmorModifier += effect.DefensePercentage;
                            Stats.MagicResModifier += effect.MagicalDefensePercentage;
                            Stats.CriticalChanceModifier += effect.CritPercentage;
                            effect.EffectTimer = -1;
                        }
                    }
                    else
                    {
                        // Adicionar modificadores do efeito
                        if (effect.EffectTimer == 0)
                        {
                            Stats.AttackSpeedModifier += effect.AttackSpeedPercentage;
                            Stats.ArmorModifier += effect.DefensePercentage;
                            Stats.MagicResModifier += effect.MagicalDefensePercentage;
                            Stats.CriticalChanceModifier += effect.CritPercentage;
                        }

                        effect.EffectTimer += (float) gameTime.ElapsedGameTime.TotalMilliseconds;

                        if (effect.EffectTimer > effect.EffectDuration)
                        {
                            Stats.AttackSpeedModifier -= effect.AttackSpeedPercentage;

                            Stats.ArmorModifier -= effect.DefensePercentage;
                            Stats.MagicResModifier -= effect.MagicalDefensePercentage;
                            Stats.CriticalChanceModifier -= effect.CritPercentage;
                            effect.EffectTimer = 0f;
                            StatusEffects.RemoveAt(i);
                            i--;
                        }
                    }
                }

                #endregion
            }

            for (int i = 0; i < OnHitEffects.Count; i++)
            {
                StatusEffect effect = OnHitEffects[i];

                // Se o efeito é ao longo do tempo
                effect.EffectTimer += (float) gameTime.ElapsedGameTime.TotalMilliseconds;

                if (effect.EffectTimer >= effect.EffectDuration)
                {
                    OnHitEffects.RemoveAt(i);
                    i--;
                }
            }
        }
Пример #3
0
        public void AttackTarget(Character attacked)
        {
            int chance = BattleHelper.CalculateMeleeChance(this, attacked);
            int damage = BattleHelper.CalculatePhysicalDamage(this, attacked);
            damage = damage >= attacked.Stats.Hp ? attacked.Stats.Hp : damage;

            var rand = new Random(DateTime.Now.Millisecond);

            bool criticalHit = rand.Next(0, 100) <= BattleHelper.CalculateCriticalChance(this);

            if (rand.Next(100) < chance)
            {
                var args = new AttackEventArgs();
                args.Attacker = this;
                args.Target = attacked;

                StatusEffect lifeSteal = StatusEffects.Find(x => x.HealthOnAttack > 0);
                if (lifeSteal != null)
                {
                    args.Damage = lifeSteal.HealthOnAttack;
                    ChangeHealth(args, true);
                }

                if (criticalHit)
                    damage *= 2;
                args.Damage = -damage;

                attacked.ChangeHealth(args, true);
            }
        }
Пример #4
0
 private void UpdateRegeneration(GameTime gameTime)
 {
     int regenDelay = 1000;
     regenTimer += (float) gameTime.ElapsedGameTime.TotalMilliseconds;
     if (regenTimer >= regenDelay)
     {
         regenTimer = 0;
         Stats.Stamina += Class.StaminaRegen;
         Stats.Mana += Class.ManaRegen;
         var args = new AttackEventArgs(this, this, Class.HealthRegen, false);
         ChangeHealth(args, false);
     }
 }
        public void CastEnemySkill(Enemy character, Skill skill, Character.Character target = null)
        {
            if (character.CanCastSkill(skill))
            {
                var affected = new List<Character.Character>();
                if (affected.Count > 0 || target != null)
                {
                    character.StatusEffects.AddRange(skill.SelfEffects);
                    skill.CooldownTimer = skill.Cooldown;

                    #region Target effects

                    if (skill.AnimateAction)
                    {
                        character.StopMovement();
                        character.ActionState = ActionState.Attacking;
                        character.CharSprite.AnimateAction(AnimationType.Attack1);
                    }

                    if (skill.TargetArea == TargetArea.SingleTarget)
                    {
                        if (target != null && (target.Position - character.Position).Length() <= skill.Range)
                            affected.Add(target);
                    }

                    if (skill.Damage > 0)
                    {
                        affected.ForEach(x =>
                        {
                            var args = new AttackEventArgs(Player, x, -skill.Damage, false);
                            x.ChangeHealth(args, true);
                        });
                    }

                    if (skill.Healing > 0)
                    {
                        affected.ForEach(x =>
                        {
                            var args = new AttackEventArgs(Player, x, skill.Healing, false);
                            x.ChangeHealth(args, true);
                        });
                    }

                    affected.ForEach(x => x.StatusEffects.AddRange(skill.TargetEffects));

                    #endregion

                    #region Caster animation effects

                    if (skill.CasterAnimation != null)
                    {
                        skill.CasterAnimation.Position = character.Position;
                        animations.Add(skill.CasterAnimation);
                    }

                    #endregion

                    #region Caster movement

                    //if (skill.CasterMovement == CasterMovement.TeleportToTarget)
                    //{
                    //    character.Position = InputManager.MouseToMapVector;
                    //}
                    //else if (skill.CasterMovement == CasterMovement.Dash)
                    //{
                    //    float mouseAngle = MapHelper.GetAngleBetweenPoints(Player.Position, InputManager.MouseToMapVector);
                    //    Direction d = MapHelper.GetDirectionFromAngle(mouseAngle);
                    //    //Player.Dash(MapHelper.GetVectorFromDirection(d), (Player.Position - InputManager.MouseToMapVector).Length());
                    //}

                    #endregion

                    #region Target animation effects

                    if (skill.TargetAnimation != null)
                    {
                        switch (skill.TargetArea)
                        {
                            case TargetArea.SelfArea:
                            case TargetArea.SingleTarget:
                            case TargetArea.RangedArea:
                                foreach (Character.Character enemy in affected)
                                {
                                    var animation = new SpriteAnimation(skill.TargetAnimation.Texture,
                                        skill.TargetAnimation.SpriteFormat, skill.TargetAnimation.Interval);
                                    animation.Target = enemy;
                                    animations.Add(animation);
                                }
                                break;
                            case TargetArea.Self:
                                skill.TargetAnimation.Target = character;
                                animations.Add(skill.TargetAnimation);
                                break;
                        }
                    }

                    #endregion
                }
            }
        }
        private void CharacterHealthChanged(AttackEventArgs attack)
        {
            SpriteFont font = Fonts.ArialBlack14;
            Vector2 textSize = font.MeasureString(attack.Damage.ToString());

            if (attack.Damage != 0)
            {
                if (attack.Damage > 0)
                {
                    floatingText.Add(new TextAnimation(attack.Damage.ToString(), attack.Target.Position, font,
                        Color.LightGreen));
                }
                else
                {
                    if (attack.CriticalHit)
                    {
                        Camera.Shake(4, .3f);
                        floatingText.Add(new TextAnimation((-attack.Damage) + "!", attack.Target.Position, font,
                            Color.Red));
                    }
                    else
                    {
                        floatingText.Add(new TextAnimation((-attack.Damage).ToString(), attack.Target.Position, font,
                            Color.Red));
                    }
                }
            }
            else
            {
                textSize = Fonts.ArialBlack14.MeasureString(LanguageConfig.Config.BlockedText);
                floatingText.Add(new TextAnimation(LanguageConfig.Config.BlockedText, attack.Target.Position, font,
                    Color.LightBlue));
            }

            if (attack.Target.Stats.Hp <= 0 && attack.Target.IsAlive)
            {
                if (attack.Target.IsPlayer)
                {
                    KillPlayer();
                }
                else if (attack.Target is Npc)
                {
                    KillAlly(attack.Target);
                    attack.Attacker.Target = null;
                }
                else if (attack.Target is Enemy)
                {
                    KillEnemy(attack.Target, attack.Attacker.IsPlayer);
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            Game.GameStats.TotalTimePlayed =
                Game.GameStats.TotalTimePlayed.Add(new TimeSpan(0, 0, 0,
                    (int) gameTime.ElapsedGameTime.TotalMilliseconds));
            Game.CurrentSave.TimePlayedTicks += gameTime.ElapsedGameTime.Ticks;

            if (Player.Stats.Level > GameStats.HighestLevel)
                GameStats.HighestLevel = Player.Stats.Level;

            screenInfo.Update(gameTime, Player);
            UpdateInterface(gameTime);

            if (!Game.Paused)
            {
                UpdatePlayer(gameTime);
                UpdateEnemies(gameTime);
                UpdateNpcs(gameTime);
                UpdateMapEvents(gameTime);
                UpdateAnimations(gameTime);
                ProcessAttackQueue(gameTime);
                UpdateGameObjects();
            }
            else
            {
                gamePausedMenu.Update(gameTime);
            }

            for (int i = 0; i < Projectiles.Count; i++)
            {
                Projectile projectile = Projectiles[i];
                projectile.Update(gameTime);
                bool hitTarget = false;

                foreach (Enemy e in AliveEnemies)
                {
                    if (e.CollidesWithObject(projectile))
                    {
                        var args = new AttackEventArgs(Player, e, -10, true);
                        e.ChangeHealth(args, true);
                        Projectiles.RemoveAt(i);
                        i--;
                        hitTarget = true;
                        break;
                    }
                }

                if (hitTarget)
                    break;

                if (projectile.CurrentRange > projectile.MaxRange)
                {
                    Projectiles.RemoveAt(i);
                    i--;
                    break;
                }
            }

            Camera.LockToTarget(
                Player,
                GameConfig.Config.WindowWidth,
                GameConfig.Config.WindowHeight);

            Camera.Update(gameTime);

            Camera.ClampToArea(
                Game.CurrentMap.WidthInPixels - GameConfig.Config.WindowWidth,
                Game.CurrentMap.HeightInPixels - GameConfig.Config.WindowHeight);
        }
        public void CastSkill(Character.Character character, Skill skill)
        {
            if ((InputManager.MouseToMapVector - Player.Position).Length() > skill.Range)
            {
                currentPreCastSkill = null;
                return;
            }

            if (character.CanCastSkill(skill))
            {
                var affected = new List<Enemy>();

                character.Stats.Mana -= skill.ManaCost;
                character.StatusEffects.AddRange(skill.SelfEffects);
                skill.CooldownTimer = skill.Cooldown;

                #region Player Skills

                if (character.IsPlayer)
                {
                    #region Target effects

                    if (skill.AnimateAction)
                    {
                        character.StopMovement();
                        character.ActionState = ActionState.Attacking;
                        character.CharSprite.AnimateAction(AnimationType.Attack1);
                    }
                    if (skill.TargetArea == TargetArea.SelfArea)
                    {
                        affected = AliveEnemies.FindAll(e => (e.Position - character.Position).Length() <= skill.Range);
                    }
                    else if (skill.TargetArea == TargetArea.SingleTarget)
                    {
                        if (currentTarget is Enemy)
                            affected.Add(currentTarget as Enemy);
                    }

                    if (skill.DamageModificerPercentage > 0)
                    {
                        float damageBuff = skill.DamageModificerPercentage/100;
                        foreach (Enemy e in affected)
                        {
                            var damage = (int) (damageBuff*BattleHelper.CalculatePhysicalDamage(character, e));
                            var args = new AttackEventArgs(Player, e, -damage, false);
                            e.ChangeHealth(args, true);
                        }
                    }

                    if (skill.Damage > 0)
                    {
                        affected.ForEach(x =>
                        {
                            var args = new AttackEventArgs(Player, x, -skill.Damage, false);
                            x.ChangeHealth(args, true);
                        });
                    }

                    affected.ForEach(x => x.StatusEffects.AddRange(skill.TargetEffects));

                    #endregion

                    #region Caster animation effects

                    if (skill.CasterAnimation != null)
                    {
                        skill.CasterAnimation.Position = character.Position;
                        animations.Add(skill.CasterAnimation);
                    }

                    #endregion

                    #region Caster movement

                    if (skill.CasterMovement == CasterMovement.TeleportToTarget)
                    {
                        Player.Position = InputManager.MouseToMapVector;
                    }
                    else if (skill.CasterMovement == CasterMovement.Dash)
                    {
                        float mouseAngle = MapHelper.GetAngleBetweenPoints(Player.Position,
                            InputManager.MouseToMapVector);
                        Direction d = MapHelper.GetDirectionFromAngle(mouseAngle);
                        //Player.Dash(MapHelper.GetVectorFromDirection(d), (Player.Position - InputManager.MouseToMapVector).Length());
                    }

                    #endregion

                    #region Target animation effects

                    if (skill.TargetAnimation != null)
                    {
                        switch (skill.TargetArea)
                        {
                            case TargetArea.SelfArea:
                            case TargetArea.SingleTarget:
                            case TargetArea.RangedArea:
                                foreach (Enemy target in affected)
                                {
                                    var animation = new SpriteAnimation(skill.TargetAnimation.Texture,
                                        skill.TargetAnimation.SpriteFormat, skill.TargetAnimation.Interval);
                                    animation.Target = target;
                                    animations.Add(animation);
                                }
                                break;
                            case TargetArea.Self:
                                skill.TargetAnimation.Target = character;
                                animations.Add(skill.TargetAnimation);
                                break;
                            default:
                                break;
                        }
                    }

                    #endregion

                    currentPreCastSkill = null;
                }
                    #endregion

                    #region Enemy Skills

                #endregion
            }
        }