示例#1
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);
            }
        }
示例#2
0
        public void Face(Character character)
        {
            float angle = MapHelper.GetAngleBetweenPoints(Position, character.Position);
            if (angle < 0)
                angle += 360;

            Direction dir = MapHelper.GetDirectionFromAngle(angle);
            Turn(dir);
        }
        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
                }
            }
        }
        public void SetCurrentSprite(SpriteSet currentSpriteSet, SpriteSetConfiguration currentSpriteSetConfiguration)
        {
            CurrentSpriteSet = currentSpriteSet;
            CurrentSpriteSetConfig = currentSpriteSetConfiguration;

            if (currentSpriteSet != null)
            {
                CurrentCharacter = new Character(new CharacterSprite(currentSpriteSet));
            }
            else
            {
                CurrentCharacter = null;
            }
        }
        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
            }
        }
        private void LootEnemy(Character.Character enemy)
        {
            foreach (Loot item in (enemy as Enemy).Loot.LootItems)
            {
                var r = new Random(DateTime.Now.Millisecond);
                int dropRoll = r.Next(0, 101);
                if (dropRoll <= item.DropChance)
                {
                    int count = r.Next(1, item.MaxAmount + 1);
                    lootLog.Add(new LootScreenLog(item.Item, count, new Vector2(30, 30), Fonts.ArialBlack14Italic));

                    if (item.Item.Stackable)
                    {
                        //Item it = Item.Load(item.Id);
                        item.Item.Amount = count;
                        Player.Inventory.Add(item.Item);
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                            Player.Inventory.Add(item.Item);
                    }
                }
            }
        }
        private void KillEnemy(Character.Character enemy, bool byPlayer)
        {
            var xpFont = Fonts.ArialBlack12;

            if (byPlayer)
            {
                #region user stats

                if (!Game.GameStats.EnemiesKilled.ContainsKey(enemy.Id))
                {
                    Game.GameStats.EnemiesKilled.Add(enemy.Id, 0);
                }

                Game.GameStats.EnemiesKilled[enemy.Id]++;

                #endregion

                floatingText.Add(new TextAnimation(enemy.Stats.Experience + "exp", Player.Position, xpFont, Color.LightGray));

                Player.AddExperience(enemy.Stats.Experience);

                if (enemy is Enemy)
                    LootEnemy(enemy);

                List<Quest> results =
                    Game.PlayerQuests.FindAll(e => e.Goal.Type == QuestGoalType.KillCreatures && e.Goal.GoalObjectId == enemy.Id);

                if (results.Count > 0)
                    results.ForEach(x => x.Goal.CurrentCount++);
            }
            AliveNpcs.FindAll(x => x.Target == enemy).ForEach(x => x.Target = null);

            Player.Target = null;
            enemy.IsAlive = false;
            enemy.CharSprite.AnimateAction(AnimationType.Death);
        }
 private void KillAlly(Character.Character ally)
 {
     ally.IsAlive = false;
     ally.CharSprite.AnimateAction(AnimationType.Death);
 }
示例#9
0
        public void CreatePlayers()
        {
            Characters = new Dictionary<CharacterClass, Character.Character>();

            var spriteSet = SpriteCollection.FirstOrDefault(s => s.Name.ToLower() == "human");
            var sprite = new CharacterSprite(spriteSet);
            var shinobi = new Character.Character(sprite)
            {
                Equipment =
                {
                    MainWeapon = (Weapon) Item.Find("Battle Knife")
                }
            };

            shinobi.Name = "Shinobi";
            shinobi.SetClass(Classes[CharacterClass.Shinobi]);
            shinobi.Stats.Speed = 1.6f;
            Characters.Add(CharacterClass.Shinobi, shinobi);

            Player = Characters[CharacterClass.Shinobi];
        }