Esempio n. 1
0
    public override NodeState RunNode(float p_delta)
    {
        Script_IEntity targetEntity   = _tree.GetBlackBoardElement <Script_IEntity>(_targetEnemyFlag);
        bool           isForwardSwing = _tree.GetBlackBoardElement <bool> (_isForwardSwingFlag);

        if (targetEntity == null || targetEntity.GetGameObject() == null)
        {
            return(NodeState.Failed);
        }

        if (isForwardSwing)
        {
            NodeState success = ForwardSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity);
            if (success == NodeState.Success)
            {
                Script_Projectile projectile = new Script_Projectile(_manager, _entityToAttack, targetEntity, _projectileColor);
                _manager.CreateProjectile(projectile);
                return(NodeState.Success);
            }
        }
        else if (!isForwardSwing)
        {
            BackSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity);
        }
        return(NodeState.Running);
    }
    public override NodeState RunNode(float p_delta)
    {
        Script_IEntity targetEntity   = _tree.GetBlackBoardElement <Script_IEntity>(_targetEnemyFlag);
        bool           isForwardSwing = _tree.GetBlackBoardElement <bool> (_isForwardSwingFlag);

        if (targetEntity == null || targetEntity.GetGameObject() == null)
        {
            return(NodeState.Failed);
        }


        if (isForwardSwing)
        {
            NodeState success = ForwardSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity);
            if (success == NodeState.Success)
            {
                targetEntity.TakeDamage(_entityToAttack, _entityToAttack.GetStats()._damage);
                return(NodeState.Success);
            }
        }
        else if (!isForwardSwing)
        {
            BackSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity);
        }
        return(NodeState.Running);
    }
    public override NodeState RunNode(float p_delta)
    {
        Script_IEntity targetEntity = _tree.GetBlackBoardElement <Script_IEntity>(_targetEnemyFlag);

        bool isForwardSwing = _tree.GetBlackBoardElement <bool> (_isForwardSwingFlag);

        if (targetEntity == null || targetEntity.GetGameObject() == null)
        {
            return(NodeState.Failed);
        }

        if (isForwardSwing)
        {
            NodeState success = ForwardSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity);
            if (success == NodeState.Success)
            {
                Script_HealingVisualEffect healingEffect = new Script_HealingVisualEffect(_manager, targetEntity);
                _manager.CreateVisual(healingEffect);
                targetEntity.Heal(_entityToAttack.GetStats()._healPower);
                return(NodeState.Success);
            }
        }
        else if (!isForwardSwing)
        {
            BackSwing(p_delta, _entityToAttack.GetGridLocation(), _entityToAttack, targetEntity);
        }
        return(NodeState.Running);
    }
    private Script_Tile GetNearestAvailableTile(List <Script_Tile> p_tileList)
    {
        float       distance    = float.MaxValue;
        Script_Tile nearestTile = null;

        foreach (Script_Tile tile in p_tileList)
        {
            if (distance > Vector3Int.Distance(tile.GetGridPosition(), _fromEntity.GetGridLocation()))
            {
                distance    = Vector3Int.Distance(tile.GetGridPosition(), _fromEntity.GetGridLocation());
                nearestTile = tile;
            }
        }
        return(nearestTile);
    }
    public override NodeState RunNode(float p_delta)
    {
        List <Script_IEntity> entityList = _tree.GetBlackBoardElement <List <Script_IEntity> > (_entityListFlag);

        if (entityList.Count <= 0 || entityList == null)
        {
            return(NodeState.Failed);
        }

        if (_targetEntity == null)
        {
            return(NodeState.Failed);
        }


        _location = _targetEntity.GetGridLocation();

        List <Script_IEntity> entitiesWithinRange = GetEntitiesWithinRange(_range, entityList);

        if (entitiesWithinRange.Count > 0)
        {
            return(NodeState.Success);
        }

        return(NodeState.Failed);
    }
    public override NodeState RunNode(float p_delta)
    {
        List <Script_IEntity> entityList = _tree.GetBlackBoardElement <List <Script_IEntity> > (_entityListFlag);

        if (entityList.Count <= 0 || entityList == null)
        {
            return(NodeState.Failed);
        }

        if (_fromEntity == null)
        {
            return(NodeState.Failed);
        }


        _position = _fromEntity.GetGridLocation();

        List <Script_IEntity> entitiesWithinRange = GetEntitiesWithinRange(_range, entityList);

        if (entitiesWithinRange != null && entitiesWithinRange.Count > 0)
        {
            Script_IEntity nearestEntity = GetNearestEntity(entitiesWithinRange);
            _tree.SetBlackboardElement(_returnedNearestEntityFlag, nearestEntity);
            return(NodeState.Success);
        }

        return(NodeState.Failed);
    }
Esempio n. 7
0
    public override NodeState RunNode(float p_delta)
    {
        Script_IEntity entity = _tree.GetBlackBoardElement <Script_IEntity> (_entityFlag);

        if (entity == null)
        {
            return(NodeState.Failed);
        }

        if (_measuredFromEntity == null)
        {
            return(NodeState.Failed);
        }


        _location = _measuredFromEntity.GetGridLocation();


        if (IsEntityWithinRange(_range, entity))
        {
            return(NodeState.Success);
        }

        return(NodeState.Failed);
    }
Esempio n. 8
0
    public override NodeState RunNode(float p_delta)
    {
        if (_entityToMove == null)
        {
            return(NodeState.Failed);
        }

        _targetEntity = _tree.GetBlackBoardElement <Script_IEntity>(_entityFlag);

        if (_targetEntity == null || _targetEntity.GetGameObject() == null)
        {
            return(NodeState.Failed);
        }


        int maxRange     = _grid.GetWidth() > _grid.GetHeight() ? _grid.GetWidth() : _grid.GetHeight();
        int currentRange = 1;

        List <Script_Tile> availableTiles = new List <Script_Tile> ();

        while (currentRange <= maxRange && availableTiles.Count == 0)
        {
            availableTiles = GetAvailableTilesSurroundingEntity(currentRange, _targetEntity);
        }

        if (availableTiles.Count == 0)
        {
            return(NodeState.Failed);
        }

        foreach (Script_Tile tile in availableTiles)
        {
            if (_entityToMove.GetGridLocation() == tile.GetGridPosition() || _entityToMove.GetGridLocation() == _targetEntity.GetGridLocation())
            {
                return(NodeState.Success);
            }
        }


        GameObject entityObject       = _entityToMove.GetGameObject();
        GameObject targetEntityObject = _targetEntity.GetGameObject();

        entityObject.transform.position += (targetEntityObject.transform.position - entityObject.transform.position).normalized * p_delta;
        return(NodeState.Running);
    }
Esempio n. 9
0
    public Script_Projectile(Script_GameManager p_manager, Script_IEntity p_startEntity, Script_IEntity p_targetEntity, Color p_color)
    {
        _manager      = p_manager;
        _targetEntity = p_targetEntity;
        _startEntity  = p_startEntity;

        _speed = 3.0f;

        _projectileObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
        _projectileObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        _projectileObject.name = "DamageDealerProjectileObject";
        _objectMaterial        = _projectileObject.GetComponent <Renderer>().material;
        _objectMaterial.color  = p_color;
        _projectileObject.transform.position = _startEntity.GetGridLocation();
    }
    public override NodeState RunNode(float p_delta)
    {
        List <Script_IEntity> entityList = _tree.GetBlackBoardElement <List <Script_IEntity> > (_entityListFlag);

        if (entityList.Count == 0)
        {
            return(NodeState.Failed);
        }

        foreach (Script_IEntity entity in entityList)
        {
            if (entity.GetGridLocation() == _entityToCalculateFrom.GetGridLocation())
            {
                return(NodeState.Success);
            }
        }
        return(NodeState.Failed);
    }
Esempio n. 11
0
    public override NodeState RunNode(float p_delta)
    {
        Vector3Int gridPos = _entity.GetGridLocation();

        int x = Random.Range(gridPos.x - _range, gridPos.x + _range + 1);
        int z = Random.Range(gridPos.z - _range, gridPos.z + _range + 1);

        x = Mathf.Min(x, _grid.GetWidth() - 1);
        x = Mathf.Max(x, 0);

        z = Mathf.Min(z, _grid.GetHeight() - 1);
        z = Mathf.Max(z, 0);

        if (_grid.AccessGridTile(x, z).GetOccupied())
        {
            return(NodeState.Running);
        }

        _location = new Vector3Int(x, 0, z);

        _tree.SetBlackboardElement(_locationFlag, _location);
        return(NodeState.Success);
    }
    private List <Script_IEntity> GetEntitiesWithinRange(int p_range, List <Script_IEntity> p_listOfEntities)
    {
        List <Script_IEntity> entitiesWithinRange = new List <Script_IEntity>();
        int xCurrent = _entityToCalculateRangeFrom.GetGridLocation().x;
        int zCurrent = _entityToCalculateRangeFrom.GetGridLocation().z;

        int xMin = xCurrent;
        int xMax = xCurrent;
        int zMin = zCurrent;
        int zMax = zCurrent;

        for (int x = xCurrent - p_range; x <= xCurrent; x++)
        {
            if (x < 0)
            {
                continue;
            }

            xMin = x;
            break;
        }
        for (int x = xCurrent + p_range; x >= xCurrent; x--)
        {
            if (x >= _grid.GetWidth())
            {
                continue;
            }

            xMax = x;
            break;
        }
        for (int z = zCurrent - p_range; z <= zCurrent; z++)
        {
            if (z < 0)
            {
                continue;
            }

            zMin = z;
            break;
        }
        for (int z = zCurrent + p_range; z >= zCurrent; z--)
        {
            if (z >= _grid.GetHeight())
            {
                continue;
            }

            zMax = z;
            break;
        }

        for (int z = zMin; z <= zMax; z++)
        {
            for (int x = xMin; x <= xMax; x++)
            {
                foreach (Script_IEntity entity in p_listOfEntities.ToList())
                {
                    if (entity.GetGridLocation().x == x && entity.GetGridLocation().z == z)
                    {
                        entitiesWithinRange.Add(entity);
                    }
                }
            }
        }
        return(entitiesWithinRange);
    }
Esempio n. 13
0
    private List <Script_Tile> GetAvailableTilesSurroundingEntity(int p_range, Script_IEntity p_entity)
    {
        List <Script_Tile> surroundingTiles = new List <Script_Tile>();

        int xCurrent = p_entity.GetGridLocation().x;
        int zCurrent = p_entity.GetGridLocation().z;

        int xMin = xCurrent;
        int xMax = xCurrent;
        int zMin = zCurrent;
        int zMax = zCurrent;

        for (int x = xCurrent - p_range; x <= xCurrent; x++)
        {
            if (x < 0)
            {
                continue;
            }

            xMin = x;
            break;
        }
        for (int x = xCurrent + p_range; x >= xCurrent; x--)
        {
            if (x >= _grid.GetWidth())
            {
                continue;
            }

            xMax = x;
            break;
        }
        for (int z = zCurrent - p_range; z <= zCurrent; z++)
        {
            if (z < 0)
            {
                continue;
            }

            zMin = z;
            break;
        }
        for (int z = zCurrent + p_range; z >= zCurrent; z--)
        {
            if (z >= _grid.GetHeight())
            {
                continue;
            }

            zMax = z;
            break;
        }

        for (int z = zMin; z <= zMax; z++)
        {
            for (int x = xMin; x <= xMax; x++)
            {
                surroundingTiles.Add(_grid.AccessGridTile(x, z));
            }
        }
        return(surroundingTiles);
    }
Esempio n. 14
0
    private bool IsEntityWithinRange(int p_range, Script_IEntity p_entity)
    {
        int xCurrent = (int)_location.x;
        int zCurrent = (int)_location.z;

        int xMin = xCurrent;
        int xMax = xCurrent;
        int zMin = zCurrent;
        int zMax = zCurrent;

        for (int x = xCurrent - p_range; x <= xCurrent; x++)
        {
            if (x < 0)
            {
                continue;
            }

            xMin = x;
            break;
        }
        for (int x = xCurrent + p_range; x >= xCurrent; x--)
        {
            if (x >= _grid.GetWidth())
            {
                continue;
            }

            xMax = x;
            break;
        }
        for (int z = zCurrent - p_range; z <= zCurrent; z++)
        {
            if (z < 0)
            {
                continue;
            }

            zMin = z;
            break;
        }
        for (int z = zCurrent + p_range; z >= zCurrent; z--)
        {
            if (z >= _grid.GetHeight())
            {
                continue;
            }

            zMax = z;
            break;
        }

        for (int z = zMin; z <= zMax; z++)
        {
            for (int x = xMin; x <= xMax; x++)
            {
                if (p_entity.GetGridLocation().x == x && p_entity.GetGridLocation().z == z)
                {
                    return(true);
                }
            }
        }

        return(false);
    }