Example #1
0
        protected void CheckNextCharacterAbility(Character character)
        {
            if (!_gameStarted)
            {
                return;
            }
            if (_encounterTransition)
            {
                return;
            }
            if (character == null)
            {
                return;
            }
            if (character.IsCasting)
            {
                return;
            }
            if (character.Dead)
            {
                return;
            }
            if (character.CastingCooldown)
            {
                return;
            }
            if (character.Player)
            {
                return;
            }

            var abilities   = Database.GetCharacterAbilities(character.Type);
            var nextAbility = abilities[_rng.Next(0, abilities.Count)];

            var heroes  = _heroCharacters.Where(c => !c.Dead).ToList();
            var enemies = _enemyCharacters.Where(c => !c.Dead).ToList();

            Character target;

            if (nextAbility.TargetSelf)
            {
                target = character;
            }
            else
            {
                if (!character.Enemy)
                {
                    if (nextAbility.TargetFriendly)
                    {
                        target = heroes.Count > 0 ? heroes[_rng.Next(0, heroes.Count)] : null;
                    }
                    else
                    {
                        target = enemies.Count > 0 ? enemies[_rng.Next(0, enemies.Count)] : null;
                    }
                }
                else
                {
                    if (nextAbility.TargetFriendly)
                    {
                        target = enemies.Count > 0 ? enemies[_rng.Next(0, enemies.Count)] : null;
                    }
                    else
                    {
                        target = heroes.Count > 0 ? heroes[_rng.Next(0, heroes.Count)] : null;
                    }
                }
            }

            if (target == null)
            {
                return;
            }

            var abilityTimer = new AbilityTimer(character, target, nextAbility);

            character.CastAbility(abilityTimer);
        }
Example #2
0
        public void CheckInput()
        {
            if (Triggers.PlayerSkill1.Released())
            {
                _uiManager.PlayerSelectedAbility = 1;
                _playerSelectedAbility           = _playerAbilities[0];
            }
            else if (Triggers.PlayerSkill2.Released())
            {
                _uiManager.PlayerSelectedAbility = 2;
                _playerSelectedAbility           = _playerAbilities[1];
            }
            else if (Triggers.PlayerSkill3.Released())
            {
                _uiManager.PlayerSelectedAbility = 3;
                _playerSelectedAbility           = _playerAbilities[2];
            }
            else if (Triggers.PlayerSkill4.Released())
            {
                _uiManager.PlayerSelectedAbility = 4;
                _playerSelectedAbility           = _playerAbilities[3];
            }
            else if (Triggers.PlayerSkill5.Released())
            {
                _uiManager.PlayerSelectedAbility = 5;
                _playerSelectedAbility           = _playerAbilities[4];
            }

            var mousePosition = new Vector2(InputHelper.NewMouse.X, InputHelper.NewMouse.Y);

            for (var i = 0; i < _characters.Count; i++)
            {
                _characters[i].Hover = false;
            }

            List <Character> hoverCharacters = new List <Character>();

            for (var i = 0; i < _characters.Count; i++)
            {
                if (_characters[i].PointInCharacter(mousePosition))
                {
                    hoverCharacters.Add(_characters[i]);
                }
            }

            hoverCharacters.Sort((i, j) => i.CollisionOrder.CompareTo(j.CollisionOrder));
            if (hoverCharacters.Count > 0)
            {
                hoverCharacters[0].Hover = true;
            }

            if (!_player.IsCasting && !_encounterTransition)
            {
                if (_playerSelectedAbility != null)
                {
                    if (Triggers.MouseLeftClick.Released())
                    {
                        List <Character> clickedCharacters = new List <Character>();

                        for (var i = 0; i < _characters.Count; i++)
                        {
                            if (_characters[i].PointInCharacter(mousePosition))
                            {
                                clickedCharacters.Add(_characters[i]);
                            }
                        }

                        var abilityCast = false;

                        clickedCharacters.Sort((i, j) => i.CollisionOrder.CompareTo(j.CollisionOrder));

                        for (var i = 0; i < clickedCharacters.Count; i++)
                        {
                            var clickedCharacter = clickedCharacters[i];
                            if (clickedCharacter != null && !abilityCast)
                            {
                                if (_playerSelectedAbility.TargetFriendly && clickedCharacter.Enemy)
                                {
                                    return;
                                }
                                if (!_playerSelectedAbility.TargetFriendly && !clickedCharacter.Enemy)
                                {
                                    return;
                                }

                                var abilityTimer = new AbilityTimer(_player, clickedCharacter, _playerSelectedAbility);
                                _player.CastAbility(abilityTimer);
                                Assets.SoundManager.PlaySound("sfx_player", (int)SoundType.UI);
                                _uiManager.PlayerSelectedAbility = -1;
                                _playerSelectedAbility           = null;
                                abilityCast = true;
                            }
                        }
                    }
                }
            }
        }