예제 #1
0
    public IEnumerator DoLogic()
    {
        while (!damageable.IsDead)
        {
            yield return(Patrol.PatrolUntilSight(movement, patrolParameters, sight));

            movement.LockRotation();

            Collider2D target = sight.GetVisibleObject();

            if (target != null)
            {
                yield return(LineUpShot.LineUp(target.transform, shootFrom.transform, movement, sight, targetOffset, lineUpSpeed));

                if (sight.canSeeObject(target.gameObject))
                {
                    shootFrom.Fire(gunStats);
                    gunStats.SetShotsLeft(variableStore, gunStats.GetShotsLeft(variableStore) - 1);
                    yield return(AsyncUtil.Pause(postFireDelay));

                    if (gunStats.GetShotsLeft(variableStore) <= 0)
                    {
                        var possibleCover = pathfinder.GetPathFinding().FindCover(target.transform.position, 0.5f);

                        pathfinder.PathToNearest(possibleCover);

                        movement.UnlockRotation();

                        var previousLocation = transform.position;

                        yield return(pathfinder.FollowPath());

                        movement.TargetVelocity = Vector2.zero;

                        yield return(ReloadGun.ReloadAnimation(gunStats, reloadLocation, variableStore));

                        pathfinder.PathTo(previousLocation);

                        yield return(pathfinder.FollowPath());

                        movement.LockRotation();
                    }
                }
            }

            movement.UnlockRotation();
        }
    }
예제 #2
0
    public static IEnumerator ReloadAnimation(GunStats forGun, Transform at, VariableStore variableStore)
    {
        ReloadAnimation currentReloadAnimation = Instantiate <ReloadAnimation>(forGun.reloadAnimation);

        currentReloadAnimation.transform.SetParent(at, false);
        currentReloadAnimation.transform.localPosition = Vector3.zero;
        int currentShots = 0;

        currentReloadAnimation.SetShotCount(currentShots);

        yield return(AsyncUtil.Pause(forGun.reloadDelay));

        while (currentShots < forGun.capacity)
        {
            ++currentShots;
            forGun.SetShotsLeft(variableStore, currentShots);
            currentReloadAnimation.SetShotCount(currentShots);
            yield return(AsyncUtil.Pause(forGun.reloadBulletDuration));
        }

        Destroy(currentReloadAnimation.gameObject);
    }
예제 #3
0
    public IEnumerator DoLogic()
    {
        while (!damageable.IsDead)
        {
            yield return(Patrol.PatrolUntilSight(movement, patrolParameters, sight));

            movement.LockRotation();

            Collider2D target = sight.GetVisibleObject();

            if (target != null)
            {
                yield return(LineUpShot.LineUp(target.transform, shootFrom.transform, movement, sight, targetOffset, lineUpSpeed));

                if (sight.canSeeObject(target.gameObject))
                {
                    if (animation != null)
                    {
                        animation.SetTigger("Firing");
                    }
                    yield return(AsyncUtil.Pause(preFireDelay));

                    shootFrom.Fire(gunStats);
                    gunStats.SetShotsLeft(variableStore, gunStats.GetShotsLeft(variableStore) - 1);
                    yield return(AsyncUtil.Pause(postFireDelay));

                    if (gunStats.GetShotsLeft(variableStore) <= 0)
                    {
                        yield return(ReloadGun.ReloadAnimation(gunStats, reloadLocation, variableStore));
                    }
                }
            }

            movement.UnlockRotation();
        }
    }
예제 #4
0
 public void SetShotsLeft(int value)
 {
     gunStats.SetShotsLeft(stateStore, value);
 }