Beispiel #1
0
    public override void Update()
    {
        Health health;

        // Is the target still alive?
        if (!target || !(health = target.Get()) || !health.Alive)
        {
            CurrentStatus = Status.Failure;
            return;
        }

        Vector2 direction = health.transform.position - Brain.transform.position;

        // Was the health reached?
        if (direction.sqrMagnitude < minDistanceFromTargetSquared)
        {
            CurrentStatus = Status.Success;
            return;
        }

        // Still needs to go to the target.
        direction.Normalize();
        Mover.ConstantDirection = direction;
        Mover.ShouldMove        = true;
    }
Beispiel #2
0
    public override void InnerBeginn()
    {
        health = target.Get();

        min = minDistance.Get();
        max = maxDistance.Get();

        distanceFactor = (max + min) * 0.5f;
    }
Beispiel #3
0
    protected override bool InnerIsFulfilled()
    {
        float range = tree.AttachedBrain.GetComponent <EquippedWeapon>().Weapon.Range;

        Vector2 targetPosition = targetHealth.Get().transform.position;
        Vector2 ownPosition    = Brain.transform.position;

        Vector2 direction = ownPosition - targetPosition;

        return(direction.magnitude < range);
    }
Beispiel #4
0
    public override void InnerBeginn()
    {
        switch (mode)
        {
        case Mode.UseHealth:
            health = healthTarget.Get();
            break;

        case Mode.UseAbsolutePosition:
        case Mode.UseDirection:
            look = lookTarget.Get();
            break;
        }
    }
Beispiel #5
0
    public override void Update()
    {
        // Are we checking for a path?
        if (task == null)
        {
            Health health;
            if (!target || !(health = target.Get()) || !health.Alive) // Is the target still alive?
            {
                CurrentStatus = Status.Failure;
                return;
            }

            Vector2Int startPos = DungeonCreator.Instance.WorldPositionToTilePosition(Brain.transform.position);
            Vector2Int endPos   = DungeonCreator.Instance.WorldPositionToTilePosition(health.transform.position);

            //task = Task<List<Vector2>>.Factory.StartNew(() => DebugPathFinder.Instance.TryFindPath(startPos, endPos));
            //Debug.LogWarning("SetPathFromHealthNode is running with debug path finder! This will only work in the test scene!");
            task = Task <List <Vector2> > .Factory.StartNew(() => DungeonDict.Instance.dungeon.TryFindPath(startPos, endPos));

            return;
        }

        if (task.IsCompleted == false) // Is the path calculated yet?
        {
            return;
        }

        List <Vector2> path = task.Result;

        if (path.Count == 0) // Was there no path found?
        {
            CurrentStatus = Status.Failure;
            outPath.Set(path);
            return;
        }

        // Check if the path is the same, if it is then return true without setting a reference to the new list.
        // This is because other nodes may use the list reference as a way to check if the path has changed or not.
        if (outPath.IsSame(path))
        {
            CurrentStatus = Status.Success;
            return;
        }

        // Path found and set
        outPath.Set(path);
        CurrentStatus = Status.Success;
    }
Beispiel #6
0
    protected override bool InnerIsFulfilled()
    {
        Vector2 ownPos, healthPos, dir;
        Health  other;

        if (!otherHealth || !(other = otherHealth.Get()) || !other.Alive)
        {
            return(false);
        }

        healthPos = other.transform.position;
        ownPos    = Brain.transform.position;

        dir = healthPos - ownPos;

        RaycastHit2D hit = Physics2D.Raycast(ownPos, dir, dir.magnitude, LayerDict.Instance.GetBulletCollisionLayerMask());

        return(hit.collider == null);
    }
Beispiel #7
0
    public override void Update()
    {
        if (weaponStartedFiring == false)
        {
            health = targetHealth.Get();
            weaponStartedFiring = true;

            if (SetDirection())
            {
                return;
            }

            if (weapon.StartFire() == false)
            {
                // Weapon can not fire for whatever reason.
                CurrentStatus = Status.Failure;
                return;
            }
            else
            {
                // Check, if weapon uses some kind of "single trigger pull" weapon and stop firing
                System.Type shotModel = weapon.Weapon.ShotModel.GetType();
                if (shotModel == typeof(SingleShotModel) || shotModel == typeof(BurstFireModel))
                {
                    weapon.StopFire();
                }
            }

            return;
        }

        // Weapon is not firing anymore and entity.
        if (weapon.IsFiring == false)
        {
            CurrentStatus = Status.Failure;
            return;
        }

        SetDirection();
    }
Beispiel #8
0
 public override void InnerBeginn()
 {
     health       = target.Get();
     prefDistance = Brain.GetComponent <Enemy>().EquippedWeapon.Weapon.Range *distancePercent;
 }
Beispiel #9
0
 protected override bool InnerIsFulfilled() => targetHealth?targetHealth.Get().Alive : false;