Пример #1
0
 public void Setup(GameplayEntity attacker, GameplayEntity target, int pushDistance, int hitDamage)
 {
     m_attacker     = attacker;
     m_target       = target;
     m_pushDistance = pushDistance;
     m_hitDamage    = hitDamage;
 }
Пример #2
0
        public void Begin()
        {
            //get list of selectable player
            for (int i = 0; i < m_manager.PlayerEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.PlayerEntities[i];
                if (entity.Status.Health > 0)
                {
                    if (entity.HaveAction)
                    {
                        m_selectablePlayer.Add(entity);
                    }
                }
            }

            if (m_selectablePlayer.Count == 0)
            {
                //end this state
                ShouldEnd = true;
            }
            else
            {
                ShouldEnd = false;
            }

            m_manager.Ui.SkipTurnButton.onClick.AddListener(OnSkipTurnClicked);
            m_manager.Ui.SkillsDropdown.onValueChanged.AddListener(OnDropDownValueChanged);

            m_manager.Ui.SkipTurnButton.gameObject.SetActive(true);
            m_manager.Ui.SkillsDropdownCanvasGroup.alpha = 0;
        }
        public T GetSkill <T>(GameplayEntity owner) where T : ISkill
        {
            T skill = System.Activator.CreateInstance <T>();

            skill.Initialize(owner, m_manager);
            return(skill);
        }
Пример #4
0
        public void Setup(GameplayEntity attacker, GameplayEntity target, int damage)
        {
            m_attacker = attacker;
            m_target = target;
            m_damage = damage;

        }
Пример #5
0
        public void Begin()
        {
            m_skill.GetValidPositions(m_spawnPositions);

            if (m_spawnPositions.Count > 0)
            {
                m_timer = 3f;
                Vector2Int spawnPosition = m_spawnPositions[Random.Range(0, m_spawnPositions.Count)];

                EntityType      spawnType = m_skill.SpawnType;
                EntityComponent visual    = m_manager.Service.InstantiateEntity(spawnPosition.x, spawnPosition.y, spawnType);

                GameplayEntity gameplayEntity = m_manager.RegisterEntity(visual);

                gameplayEntity.Move(spawnPosition, 0);

                m_manager.Service.PlayQuakeAnimation(spawnPosition.x, spawnPosition.y, 2);
                m_manager.Pathfinder.NavGraph.SetGridType(spawnPosition, visual.Type);

                if (m_owner.Visual.Type == spawnType)
                {
                    m_manager.Ui.ShowAndHideBanner("Reinforcement has arrived", 0, 2);
                }
                else
                {
                    m_manager.Ui.ShowAndHideBanner("Magic malfunction", 0, 2);
                }
            }
            else
            {
                m_timer = .1f;
            }
        }
Пример #6
0
        public void Begin()
        {
            m_timer = 2.5f;
            m_skill.GetValidTargets(m_targets);

            m_skill.Owner.Move(m_skill.Center, 0);

            m_manager.Service.PlayQuakeAnimation(m_skill.Center.x, m_skill.Center.y, m_skill.Radius, .2f);

            for (int i = 0; i < m_targets.Count; i++)
            {
                GameplayEntity target = m_targets[i];
                float          delay  = .2f + Vector2Int.Distance(m_skill.Center, target.Visual.GridPosition) * .1f;

                target.Status.Damage(1);

                target.PlayHealthBarAnimation(delay);
                target.Visual.PlayTakeDamageAnimation(delay);

                if (target.Status.Health <= 0)
                {
                    m_manager.Pathfinder.NavGraph.SetGridType(target.Visual.GridPosition, EntityType.None);
                    target.Visual.PlayDeathAnimation(delay + .15f);
                }
            }
        }
Пример #7
0
    public void ReplaceWispCollision(GameplayEntity newCollidedWith)
    {
        var index     = GameplayComponentsLookup.WispCollision;
        var component = CreateComponent <DuckOfDoom.Danmaku.WispCollision>(index);

        component.CollidedWith = newCollidedWith;
        ReplaceComponent(index, component);
    }
        //determine which side go first, prioritize player first
        public void Begin()
        {
            m_timer = 0;

            m_manager.Ui.SkipTurnButton.gameObject.SetActive(false);

            //evaluate and remove dead entity
            m_manager.EnemiesEntities.Clear();
            m_manager.PlayerEntities.Clear();

            for (int i = 0; i < m_manager.GameplayEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.GameplayEntities[i];
                if (entity.Status.Health <= 0)
                {
                    m_manager.GameplayEntities.RemoveAt(i);
                    i--;
                }
                else
                {
                    if (entity.Visual.Type == EntityType.Player)
                    {
                        m_manager.PlayerEntities.Add(entity);
                    }
                    else if (entity.Visual.Type == EntityType.Enemy)
                    {
                        m_manager.EnemiesEntities.Add(entity);
                    }
                }
            }

            if (HaveMoveLeft(m_manager.PlayerEntities))
            {
                m_manager.StateManager.RegisterState <PlayerInputState>();
                if (m_manager.RoundInfo.PlayerRound != m_manager.RoundInfo.CurrentRound)
                {
                    m_manager.RoundInfo.PlayerRound = m_manager.RoundInfo.CurrentRound;
                    m_manager.Ui.ShowAndHideBanner("Player's Turn", 0, BannerDuration);
                    m_timer = BannerDuration;
                }
            }
            else if (HaveMoveLeft(m_manager.EnemiesEntities))
            {
                m_manager.StateManager.RegisterState <AIState>();
                if (m_manager.RoundInfo.EnemyRound != m_manager.RoundInfo.CurrentRound)
                {
                    m_manager.RoundInfo.EnemyRound = m_manager.RoundInfo.CurrentRound;
                    m_manager.Ui.ShowAndHideBanner("Enemy Turn", 0, BannerDuration);
                    m_timer = BannerDuration;
                }
            }
            else
            {
                m_manager.StateManager.RegisterState <StartRoundState>();
            }
        }
Пример #9
0
        private void SkipTurn()
        {
            for (int i = 0; i < m_manager.EnemiesEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.EnemiesEntities[i];
                entity.TurnState.CanAttack = entity.TurnState.CanMove = false;
            }

            m_manager.StateManager.RegisterState <StartTurnState>();
        }
Пример #10
0
 private static void AddDamage(GameplayEntity entity, float amount)
 {
     if (entity.hasDamage)
     {
         entity.damage.Amount += amount;
     }
     else
     {
         entity.AddDamage(amount);
     }
 }
Пример #11
0
        private void OnSkipTurnClicked()
        {
            for (int i = 0; i < m_selectablePlayer.Count; i++)
            {
                GameplayEntity entity = m_selectablePlayer[i];
                entity.Visual.ShowSelection(false);
                entity.TurnState.CanAttack = entity.TurnState.CanMove = false;
            }

            ShouldEnd = true;
            m_manager.StateManager.RegisterState <StartTurnState>();
        }
Пример #12
0
        public GameplayEntity GetEntityAtPosition(Vector2Int position, List <GameplayEntity> list)
        {
            for (int i = 0; i < list.Count; i++)
            {
                GameplayEntity entity = list[i];
                if (entity.Visual.GridPosition == position)
                {
                    return(entity);
                }
            }

            return(null);
        }
        private bool HaveMoveLeft(List <GameplayEntity> entities)
        {
            for (int i = 0; i < entities.Count; i++)
            {
                GameplayEntity entity = entities[i];

                if (entity.HaveAction)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #14
0
        public void GetValidTargets(List <GameplayEntity> results)
        {
            results.Clear();

            for (int i = 0; i < m_manager.GameplayEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.GameplayEntities[i];

                if (entity.Visual.GridPosition != Center &&
                    Vector2.Distance(Center, entity.Visual.GridPosition) <= Radius)
                {
                    results.Add(entity);
                }
            }
        }
Пример #15
0
        public void GetValidTargets(List<GameplayEntity> results)
        {
            results.Clear();

            for (int i = 0; i < m_manager.GameplayEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.GameplayEntities[i];
                if (m_owner.Visual.Type != entity.Visual.Type)
                {
                    if (Vector2Int.Distance(m_owner.Visual.GridPosition, entity.Visual.GridPosition) <= 1)
                    {
                        results.Add(entity);
                    }
                }
            }
        }
Пример #16
0
        public GameplayEntity RegisterEntity(EntityComponent visualEntity)
        {
            GameplayEntity entity = new GameplayEntity(visualEntity);

            entity.Status.MaxTraverseCount = 7;//6 grids + current grid

            entity.Skills.Add(m_skillManager.GetSkill <BasicAttack>(entity));

            //assign special skills
            if (Random.value < .5f)
            {
                entity.Skills.Add(m_skillManager.GetSkill <PushAttack>(entity));
            }

            if (Random.value < .5f)
            {
                entity.Skills.Add(m_skillManager.GetSkill <Reinforcement>(entity));
            }

            if (Random.value < .5f)
            {
                entity.Skills.Add(m_skillManager.GetSkill <GroundSlam>(entity));
            }

            if (Random.value < .5f)
            {
                entity.Skills.Add(m_skillManager.GetSkill <Convert>(entity));
            }

            if (Random.value < .5f)
            {
                entity.Skills.Add(m_skillManager.GetSkill <Heal>(entity));
            }

            GameplayEntities.Add(entity);

            if (entity.Visual.Type == EntityType.Player)
            {
                PlayerEntities.Add(entity);
            }
            else if (entity.Visual.Type == EntityType.Enemy)
            {
                EnemiesEntities.Add(entity);
            }

            return(entity);
        }
Пример #17
0
        private IEnumerator ConvertActions(GameplayEntity targetConvert, EntityType convertTo, float delay)
        {
            yield return(new WaitForSeconds(delay));

            EntityComponent visual         = m_manager.Service.InstantiateEntity(targetConvert.Visual.GridPosition.x, targetConvert.Visual.GridPosition.y, convertTo);
            GameplayEntity  gameplayEntity = m_manager.RegisterEntity(visual);

            gameplayEntity.Status.SetHealth(targetConvert.Status.Health);
            gameplayEntity.Visual.PlayHealthBarAnimation(gameplayEntity.Status.HealthPercentage);

            targetConvert.Status.SetHealth(0);
            targetConvert.Visual.gameObject.SetActive(false);

            yield return(new WaitForSeconds(2));

            m_end = true;
        }
Пример #18
0
        private void PushBack(GameplayEntity entity, Vector2Int location, int damage, float delay)
        {
            entity.Status.Damage(damage);

            entity.Visual.Leap(location, delay);
            entity.Visual.PlayTakeDamageAnimation(delay);
            entity.PlayHealthBarAnimation(delay);

            m_manager.Pathfinder.NavGraph.SetGridType(entity.Visual.GridPosition, EntityType.None);

            if (entity.Status.Health <= 0)
            {
                entity.Visual.PlayDeathAnimation(delay + .3f);
            }
            else
            {
                m_manager.Pathfinder.NavGraph.SetGridType(location, entity.Visual.Type);
            }
        }
        public void Begin()
        {
            m_manager.Ui.SkipTurnButton.gameObject.SetActive(false);

            //update gameplay entities before starting round
            for (int i = 0; i < m_manager.GameplayEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.GameplayEntities[i];
                entity.InitializeTurn();
            }

            if (m_manager.PlayerEntities.Count == 0 || m_manager.EnemiesEntities.Count == 0)
            {
                m_manager.StateManager.RegisterState <GameOverState>();
            }
            else
            {
                m_manager.RoundInfo.CurrentRound++;
                m_manager.StateManager.RegisterState <StartTurnState>();
            }
        }
Пример #20
0
        private IEnumerator Spawn(GameplayEntity e, ISpawnerSettings settings)
        {
            var currentBurstCount = 0f;
            var currentBurstDelay = settings.Burst.Delay;

            while (e.isEnabled && currentBurstCount < settings.Burst.Count)
            {
                if (currentBurstDelay >= settings.Burst.Delay)
                {
                    var angleDelta   = Mathf.PI * 2 / settings.Pattern.Size;
                    var angle        = 0f;
                    var centerOffset = 0.1f;

                    while (angle < Mathf.PI * 2)
                    {
                        var vectorAway = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
                        var pos        = vectorAway * 2f * centerOffset + e.position.Value;

                        _projectilesFactory.SpawnProjectile(
                            pos,
                            vectorAway * 5f + (e.hasVelocity ? e.velocity.Linear : Vector2.zero)
                            );

                        angle += angleDelta;
                    }

                    currentBurstDelay = 0;
                    currentBurstCount++;
                }
                else
                {
                    currentBurstDelay += _gameTime.DeltaTime;
                }

                yield return(null);
            }
        }
Пример #21
0
 public void Move(GameplayEntity entity, List <Vector2Int> path)
 {
     m_entity = entity;
     m_path   = path;
 }
Пример #22
0
 public void Execute(GameplayEntity target)
 {
     m_manager.StateManager.RegisterState <ReinforcementState>().Setup(m_owner, this);
 }
Пример #23
0
 public void Initialize(GameplayEntity owner, GameManager manager)
 {
     m_manager = manager;
     m_owner   = owner;
 }
Пример #24
0
 public void Setup(GameplayEntity owner, Reinforcement skill)
 {
     m_owner = owner;
     m_skill = skill;
 }
Пример #25
0
        public void Begin()
        {
            if (m_manager.PlayerEntities.Count == 0)
            {
                //no target left skip turn
                SkipTurn();
                return;
            }
            for (int i = 0; i < m_manager.EnemiesEntities.Count; i++)
            {
                GameplayEntity entity = m_manager.EnemiesEntities[i];
                if (entity.Status.Health > 0)
                {
                    //get closest enemy
                    if (entity.TurnState.CanAttack)
                    {
                        int randomness = Random.Range(0, entity.Skills.Count);

                        m_alternateAttacks.Clear();

                        for (int j = 0; j < entity.Skills.Count; j++)
                        {
                            ISkill skill = entity.Skills[(j + randomness) % entity.Skills.Count];

                            skill.GetValidTargets(m_targetableEntities);

                            //filter targets
                            for (int k = 0; k < m_targetableEntities.Count; k++)
                            {
                                GameplayEntity targetEntity = m_targetableEntities[k];

                                if (skill.Type == ESkillType.Offensive &&
                                    targetEntity.Visual.Type == EntityType.Enemy)
                                {
                                    m_targetableEntities.RemoveAt(k);
                                    k--;
                                }
                                else if (targetEntity.Visual.Type == EntityType.Obstacle)
                                {
                                    m_alternateAttacks.Add(new KeyValuePair <ISkill, GameplayEntity>(skill, targetEntity));
                                    m_targetableEntities.RemoveAt(k);
                                    k--;
                                }
                            }

                            if (m_targetableEntities.Count > 0)
                            {
                                GameplayEntity bestTarget = m_targetableEntities[0];
                                for (int k = 1; k < m_targetableEntities.Count; k++)
                                {
                                    GameplayEntity target = m_targetableEntities[k];
                                    if (target.Status.Health < bestTarget.Status.Health)
                                    {
                                        bestTarget = target;
                                    }
                                }

                                //do attack here
                                skill.Execute(bestTarget);
                                entity.TurnState.CanAttack = false;
                                return;
                            }
                        }

                        if (!entity.TurnState.CanMove)
                        {
                            bool noPathToPlayer = true;
                            for (int j = 0; j < m_manager.PlayerEntities.Count; j++)
                            {
                                if (m_manager.Pathfinder.Navigate(entity.Visual.GridPosition, m_manager.PlayerEntities[j].Visual.GridPosition, m_pathBuffer))
                                {
                                    noPathToPlayer = false;
                                    break;
                                }
                            }

                            if (noPathToPlayer)
                            {
                                //no enemies in target, attack whatever
                                if (m_alternateAttacks.Count > 0)
                                {
                                    KeyValuePair <ISkill, GameplayEntity> alternate = m_alternateAttacks[Random.Range(0, m_alternateAttacks.Count)];

                                    alternate.Key.Execute(alternate.Value);
                                    entity.TurnState.CanAttack = false;
                                    return;
                                }
                            }
                        }
                    }

                    if (entity.TurnState.CanMove)
                    {
                        GameplayEntity bestTarget = m_manager.PlayerEntities[0];
                        m_manager.Pathfinder.Navigate(entity.Visual.GridPosition, bestTarget.Visual.GridPosition, m_bestPathBuffer);

                        for (int j = 1; j < m_manager.PlayerEntities.Count; j++)
                        {
                            GameplayEntity target = m_manager.PlayerEntities[j];
                            m_manager.Pathfinder.Navigate(entity.Visual.GridPosition, target.Visual.GridPosition, m_pathBuffer);

                            if (m_pathBuffer.Count < m_bestPathBuffer.Count)
                            {
                                m_bestPathBuffer.Clear();
                                m_bestPathBuffer.AddRange(m_pathBuffer);
                            }
                        }

                        entity.TurnState.CanMove = false;

                        if (m_bestPathBuffer.Count >= 2)
                        {
                            entity.ValidateMovement(m_bestPathBuffer);
                            m_manager.StateManager.RegisterState <EntityMoveState>().Move(entity, m_bestPathBuffer);
                            return;
                        }
                    }
                }
            }

            SkipTurn();
        }
Пример #26
0
 public void Execute(GameplayEntity target)
 {
     m_manager.StateManager.RegisterState<BasicAttackState>().Setup(m_owner,target, 1);
 }
Пример #27
0
 public void Execute(GameplayEntity target)
 {
     m_manager.StateManager.RegisterState <ConvertState>().Setup(m_owner, target);
 }
Пример #28
0
 private void OnPlayerCollision(IGroup <GameplayEntity> group, GameplayEntity entity, int index, IComponent component)
 {
     ProcessCollision(entity.wispCollision);
     entity.Destroy();
 }
Пример #29
0
        public void Tick()
        {
            Vector2Int currentMousePosition = LevelGrid.MouseToGridCoordinates();

            GameplayEntity selectedPlayerEntity = m_manager.GetEntityAtPosition(currentMousePosition, m_selectablePlayer);

            if (Input.GetMouseButtonDown(0) &&
                selectedPlayerEntity != null &&
                selectedPlayerEntity != m_activeEntity &&
                !selectedPlayerEntity.Visual.AttackTargetSelection.activeSelf)
            {
                m_activeEntity?.Visual.ShowSelection(false);

                m_activeEntity = selectedPlayerEntity;

                m_activeEntity.Visual.ShowSelection(true);

                if (m_activeEntity.TurnState.CanAttack)
                {
                    m_DropdownOptions.Clear();
                    for (int i = 0; i < m_activeEntity.Skills.Count; i++)
                    {
                        m_DropdownOptions.Add(new Dropdown.OptionData(m_activeEntity.Skills[i].Name));
                    }

                    m_skillSelected = 0;
                    Dropdown dropdown = m_manager.Ui.SkillsDropdown;
                    dropdown.ClearOptions();
                    dropdown.AddOptions(m_DropdownOptions);
                    dropdown.value = m_skillSelected;

                    dropdown.RefreshShownValue();

                    CanvasGroup canvasGroup = dropdown.GetComponentInChildren <CanvasGroup>();//<-fix for unity bug
                    if (canvasGroup != null)
                    {
                        canvasGroup.alpha = 1;
                    }

                    m_manager.Ui.SkillsDropdownCanvasGroup.alpha = 1;
                    UpdateSkillTarget();
                }
                else
                {
                    m_manager.Ui.SkillsDropdownCanvasGroup.alpha = 0;
                    ToggleTarget(false);
                    m_targetableEntities.Clear();
                }

                m_forceRepath = true;
                return;
            }

            if (m_activeEntity != null)
            {
                if (m_activeEntity.TurnState.CanAttack)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        GameplayEntity entity = m_manager.GetEntityAtPosition(currentMousePosition, m_targetableEntities);
                        if (entity != null)
                        {
                            //reset
                            m_manager.Service.HideAllBreadCrumbs();
                            ToggleTarget(false);
                            //attack state
                            m_activeEntity.Visual.ShowSelection(false);
                            m_activeEntity.Skills[m_skillSelected].Execute(entity);
                            m_activeEntity.TurnState.CanAttack = false;
                            ShouldEnd = true;
                            return;
                        }
                    }
                }

                if (m_activeEntity.TurnState.CanMove)
                {
                    if (m_forceRepath || currentMousePosition != m_previousMouse)
                    {
                        m_manager.Pathfinder.Navigate(m_activeEntity.Visual.GridPosition, currentMousePosition, m_pathBuffer);

                        m_activeEntity.ValidateMovement(m_pathBuffer);

                        m_manager.Service.HideAllBreadCrumbs();

                        for (int i = 1; i < m_pathBuffer.Count; i++)
                        {
                            Vector2Int coord = m_pathBuffer[i];
                            m_manager.Service.ShowBreadCrumb(coord.x, coord.y, true, i * .05f);
                        }

                        m_previousMouse = currentMousePosition;
                        m_forceRepath   = false;
                    }

                    if (Input.GetMouseButtonDown(0) && m_pathBuffer.Count >= 2)
                    {
                        //move
                        ToggleTarget(false);
                        m_activeEntity.Visual.ShowSelection(false);
                        m_manager.StateManager.RegisterState <EntityMoveState>().Move(m_activeEntity, m_pathBuffer);
                        m_activeEntity.TurnState.CanMove = false;
                        ShouldEnd = true;
                        return;
                    }
                }
            }
        }
Пример #30
0
 public void Setup(GameplayEntity attacker, GameplayEntity target)
 {
     m_attacker = attacker;
     m_target   = target;
 }