示例#1
0
 protected void DoAttack()
 {
     attackStep          = AttackStep.WARMUP;
     nextAttackPhaseTime = Time.time + AttackPhaseTimes[0];
     ChangeAnimState(AnimState.ATTACK);
     gameController.Audio.PlayOneShot(ProjectileSound);
 }
示例#2
0
        private void OnAttackStateEnter()
        {
            if (AttackingTile != null)
            {
                AttackingTile.SetTileGameState(TileGameState.NotAvailable);
            }

            if (DefendingTile != null)
            {
                DefendingTile.SetTileGameState(TileGameState.NotAvailable);
            }

            attackStep = AttackStep.SelectTarget;

            if (!IsAttackPossible())
            {
                GameStateMachine.Instance.DoTransition <ReceiveUnitsTransition>();

                return;
            }

            defendingTiles = MarkAndGetDefenderTiles();

            PlayerInput.Instance.TapEvent += OnTap;
        }
示例#3
0
    protected override void Update()
    {
        base.Update();
        if (Active & gameController.State == GameState.RUNNING)
        {
            switch (State)
            {
            case AnimState.ATTACK:
                switch (attackStep)
                {
                case AttackStep.WARMUP:
                    if (Time.time > nextAttackPhaseTime)
                    {
                        attackStep  = AttackStep.FIRE;
                        currentShot = 0;
                    }
                    break;

                case AttackStep.FIRE:
                    GameObject projectileObject = Instantiate(BulletPrefab, BulletSpawnPoint.position, Quaternion.identity);
                    Projectile projectile       = projectileObject.GetComponent <Projectile>();
                    projectile.Velocity *= Facing;
                    nextAttackPhaseTime  = Time.time + AttackPhaseTimes[1];
                    attackStep           = AttackStep.COOLDOWN;
                    currentShot++;
                    break;

                case AttackStep.COOLDOWN:
                    if (Time.time > nextAttackPhaseTime)
                    {
                        if (currentShot == AttackShots)
                        {
                            attackStep = AttackStep.DONE;
                        }
                        else
                        {
                            attackStep = AttackStep.FIRE;
                        }
                    }
                    break;

                case AttackStep.DONE:
                    ChangeAnimState(AnimState.IDLE);
                    break;
                }
                break;
            }
        }
    }
示例#4
0
        protected PlanStep AttackAdjacentEnemy()
        {
            AttackStep aStep = new AttackStep(Me.TilePosition, StealthManager.Instance.PlayerLoc);

            /// as based on previous call of Attack:
            ///if(map.D.Next(0,100) > 65)//35% chance of them using a heavy attack
            ///{
            ///    Action = 4;
            ///}
            ///else
            ///{ //65% chance of a regular attack
            ///    Action = 3;
            ///}
            aStep.IsHeavy = map.D.Next(0, 100) > 65;
            return(aStep);
        }
示例#5
0
        private IEnumerator AttackPatternLoop(AttackPatternType pattern, float timeBeforeStarting)
        {
            yield return(new WaitForSeconds(timeBeforeStarting));

            while (true)
            {
                int        currentStep = _currentSteps[pattern];
                AttackStep attackStep  = AttackPatterns.GetNextAttackStep(pattern, currentStep);
                foreach (ProjectileAttack attack in attackStep.ProjectileAttacks)
                {
                    GameObject       prefab           = _prefabs[attack.Type];
                    Vector2          trajectory       = attack.Trajectory.magnitude == 0f ? GetTrajectoryTowardsPlayer() : attack.Trajectory;
                    GameObject       projectile       = Instantiate(prefab, _transform.position, LookRotation2D(trajectory), _bulletContainer);
                    ProjectileScript projectileScript = projectile.GetComponent <ProjectileScript>();

                    projectileScript.Initialize(playSpawnSound: attack.PlayAudio);
                }

                _currentSteps[pattern]++;
                yield return(new WaitForSeconds(attackStep.StepDelay));
            }
            // ReSharper disable once IteratorNeverReturns
        }
示例#6
0
        private void OnTap(Vector2 position)
        {
            if (attackStep == AttackStep.SelectTarget)
            {
                for (int i = 0; i < defendingTiles.Count; i++)
                {
                    Tile tile = defendingTiles[i];

                    if (!tile.TileInput.TapTile(position))
                    {
                        continue;
                    }

                    tile.SetTileGameState(TileGameState.SelectedAsTarget);

                    DefendingTile = tile;

                    attackingTiles = MarkAndGetAttackerTiles();

                    attackStep = AttackStep.SelectAttacker;

                    break;
                }

                // Reset all tiles
                for (int i = 0; i < defendingTiles.Count; i++)
                {
                    Tile tile = defendingTiles[i];

                    if (tile == DefendingTile)
                    {
                        continue;
                    }

                    tile.SetTileGameState(TileGameState.NotAvailable);
                }
            }
            else if (attackStep == AttackStep.SelectAttacker)
            {
                for (int i = 0; i < attackingTiles.Count; i++)
                {
                    Tile tile = attackingTiles[i];

                    if (!tile.TileInput.TapTile(position))
                    {
                        continue;
                    }

                    tile.SetTileGameState(TileGameState.SelectedAsAttacker);

                    AttackingTile = tile;

                    break;
                }

                // Reset all tiles
                for (int i = 0; i < attackingTiles.Count; i++)
                {
                    Tile tile = attackingTiles[i];

                    if (tile == AttackingTile)
                    {
                        continue;
                    }

                    tile.SetTileGameState(TileGameState.NotAvailable);
                }

                GameStateMachine.Instance.DoTransition <BattleTransition>();
            }
        }