Exemplo n.º 1
0
 public Script_Action_MoveTowardsEntity(Script_BehaviourTree p_tree, Script_Grid p_grid, blackboard_flags p_entityFlag, Script_IEntity p_entityToMove)
 {
     _tree         = p_tree;
     _grid         = p_grid;
     _entityFlag   = p_entityFlag;
     _entityToMove = p_entityToMove;
 }
Exemplo n.º 2
0
    private void SetupFollowingSequence(Script_Sequence p_followingSequence, Script_IEntity p_entityToFollow)
    {
        Script_Action_SetFlag      setTargetToFollowFlag = new Script_Action_SetFlag(_behaviourTree, p_entityToFollow as Script_IEntity, _targetToFollowFlag);
        Script_Action_UnoccupyTile unoccupyTile          = new Script_Action_UnoccupyTile(_behaviourTree, _grid, _locationFlag);
        Script_Action_SetNearestLocationSurroundingEntity setLocationNearTarget = new Script_Action_SetNearestLocationSurroundingEntity(_behaviourTree, _grid, _targetToFollowFlag, this as Script_IEntity, _locationFlag);
        Script_Action_OccupyTile     occupyTile     = new Script_Action_OccupyTile(_behaviourTree, _grid, _locationFlag);
        Script_Action_MoveToLocation moveToLocation = new Script_Action_MoveToLocation(_behaviourTree, this as Script_IEntity, _locationFlag);

        Script_Condition_IsEntityNull isTargetNull = new Script_Condition_IsEntityNull(_behaviourTree, _targetToFollowFlag);

        Script_LeafTask setTargetToFollowFlagLeaf = new Script_LeafTask(_behaviourTree, setTargetToFollowFlag);
        Script_LeafTask isTargetNullLeaf          = new Script_LeafTask(_behaviourTree, isTargetNull);
        Script_LeafTask unoccupyTileLeaf          = new Script_LeafTask(_behaviourTree, unoccupyTile);
        Script_LeafTask setLocationNearTargetLeaf = new Script_LeafTask(_behaviourTree, setLocationNearTarget);
        Script_LeafTask occupyTileLeaf            = new Script_LeafTask(_behaviourTree, occupyTile);
        Script_LeafTask moveToLocationLeaf        = new Script_LeafTask(_behaviourTree, moveToLocation);

        Script_Decorator_Inverter isTargetNotNullDecorator = new Script_Decorator_Inverter(_behaviourTree, isTargetNullLeaf);

        p_followingSequence.AddTask(setTargetToFollowFlagLeaf);
        p_followingSequence.AddTask(isTargetNotNullDecorator);
        p_followingSequence.AddTask(unoccupyTileLeaf);
        p_followingSequence.AddTask(setLocationNearTargetLeaf);
        p_followingSequence.AddTask(occupyTileLeaf);
        p_followingSequence.AddTask(moveToLocationLeaf);
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
0
    public override int GetThreat(Script_IEntity p_entity)
    {
        Script_IFriendly friendly = p_entity as Script_IFriendly;

        Assert.IsNotNull(friendly);
        return(_threatDictionary [friendly]);
    }
Exemplo n.º 5
0
 public Script_Action_MoveToLocation(Script_BehaviourTree p_tree, Script_IEntity p_entity, blackboard_flags p_locationFlag)
 {
     _locationFlag = p_locationFlag;
     _location     = Vector3.zero;
     _entity       = p_entity;
     _tree         = p_tree;
 }
    private NodeState BackSwing(float p_delta, Vector3Int p_anchorPoint, Script_IEntity p_attackerEntity, Script_IEntity p_targetEntity)
    {
        GameObject attackerObject = p_attackerEntity.GetGameObject();
        GameObject targetObject   = p_targetEntity.GetGameObject();

        Vector3 backSwingPoint = (attackerObject.transform.position - targetObject.transform.position).normalized;
        Vector3 nextPosition   = attackerObject.transform.position + (backSwingPoint * p_delta);

        float backSwingSpeed = p_attackerEntity.GetStats()._attackSpeed;
        float downSwingSpeed = backSwingSpeed * 0.5f;

        if (attackerObject == targetObject)
        {
            JumpDownAnimation(p_attackerEntity, downSwingSpeed);
        }
        else
        {
            if (Vector3.Distance(p_anchorPoint, nextPosition) > _swingDistance)
            {
                attackerObject.transform.position = p_anchorPoint + (backSwingPoint * _swingDistance);
                _tree.SetBlackboardElement(_isForwardSwingFlag, true);
            }
            else
            {
                attackerObject.transform.position += backSwingPoint * p_delta * backSwingSpeed;
            }
        }
        return(NodeState.Running);
    }
Exemplo n.º 7
0
    private NodeState ForwardSwing(float p_delta, Vector3Int p_anchorPoint, Script_IEntity p_attackerEntity, Script_IEntity p_targetEntity)
    {
        GameObject attackerObject = p_attackerEntity.GetGameObject();
        GameObject targetObject   = p_targetEntity.GetGameObject();

        Vector3 forwardSwingPoint = (targetObject.transform.position - attackerObject.transform.position).normalized;

        Vector3 nextPosition      = attackerObject.transform.position + (forwardSwingPoint * p_delta);
        float   forwardSwingSpeed = p_attackerEntity.GetStats()._attackSpeed * 3;

        if (Vector3.Distance(p_anchorPoint, nextPosition) > _swingDistance)
        {
            attackerObject.transform.position = p_anchorPoint + (forwardSwingPoint * _swingDistance);
            Script_Projectile projectile = new Script_Projectile(_manager, p_attackerEntity, p_targetEntity, _projectileColor);
            _manager.CreateProjectile(projectile as Script_IProjectile);

            _tree.SetBlackboardElement(_isForwardSwingFlag, false);

            return(NodeState.Success);
        }
        else
        {
            attackerObject.transform.position += forwardSwingPoint * p_delta * forwardSwingSpeed;
        }
        return(NodeState.Running);
    }
Exemplo n.º 8
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)
    {
        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);
    }
Exemplo n.º 10
0
 public Script_Action_SetEnemyAttackingTarget(Script_BehaviourTree p_tree, blackboard_flags p_enemyListFlag, Script_IEntity p_targetEntity, blackboard_flags p_targetToAttackFlag)
 {
     _tree               = p_tree;
     _enemyListFlag      = p_enemyListFlag;
     _targetEntity       = p_targetEntity;
     _targetToAttackFlag = p_targetToAttackFlag;
 }
    public Script_Action_SetTargetToAttack(Script_BehaviourTree p_tree, blackboard_flags p_targetToAttackFlag, Script_IEntity p_enemyToSet)
    {
        _tree = p_tree;

        _targetToAttackFlag = p_targetToAttackFlag;
        _enemyToSet         = p_enemyToSet;
    }
    private NodeState ForwardSwing(float p_delta, Vector3Int p_anchorPoint, Script_IEntity p_attackerEntity, Script_IEntity p_targetEntity)
    {
        GameObject attackerObject = p_attackerEntity.GetGameObject();
        GameObject targetObject   = p_targetEntity.GetGameObject();

        Vector3 forwardSwingPoint = (targetObject.transform.position - attackerObject.transform.position).normalized;
        Vector3 nextPosition      = attackerObject.transform.position + (forwardSwingPoint * p_delta);

        float forwardSwingSpeed = p_attackerEntity.GetStats()._attackSpeed * 3;
        float upSwingSpeed      = forwardSwingSpeed * 0.5f;


        if (attackerObject == targetObject)
        {
            NodeState state = JumpForwardAnimation(p_attackerEntity, upSwingSpeed);
            if (state == NodeState.Success)
            {
                return(state);
            }
        }
        else
        {
            if (Vector3.Distance(p_anchorPoint, nextPosition) > _swingDistance)
            {
                attackerObject.transform.position = p_anchorPoint + (forwardSwingPoint * _swingDistance);
                _tree.SetBlackboardElement(_isForwardSwingFlag, false);
                return(NodeState.Success);
            }
            else
            {
                attackerObject.transform.position += forwardSwingPoint * p_delta * forwardSwingSpeed;
            }
        }
        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);
    }
Exemplo n.º 14
0
    public Script_Enemy(Script_GameManager p_manager, Script_Grid p_grid, Vector3Int p_gridLocation)
    {
        _attackRange       = 1;
        _engageTargetRange = 3;

        _threatMultiplier = 1;
        _stats            = new EntityStats(10, 0, 100, 1.5f);

        _targetToAttack = null;

        _threatDictionary = new Dictionary <Script_IFriendly, int> ();

        _health = _stats._maxHealth;


        _manager = p_manager;
        _grid    = p_grid;

        _gridLocation = p_gridLocation;
        _position     = p_gridLocation;

        _gameObject                    = GameObject.CreatePrimitive(PrimitiveType.Cube);
        _gameObject.name               = "EnemyObject";
        _objectMaterial                = _gameObject.GetComponent <Renderer>().material;
        _objectMaterial.color          = Color.red;
        _gameObject.transform.position = p_gridLocation;



        InitializeThreatList();


        InitializeBehaviourTree();
    }
    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);
    }
Exemplo n.º 16
0
 public Script_Action_SetRandomLocationWithinRange(Script_BehaviourTree p_tree, blackboard_flags p_locationFlag, Script_IEntity p_entityToCalculateFrom, Script_Grid p_grid, int p_range)
 {
     _tree         = p_tree;
     _entity       = p_entityToCalculateFrom;
     _locationFlag = p_locationFlag;
     _grid         = p_grid;
     _range        = p_range;
 }
 public Script_Action_SetNearestLocationSurroundingEntity(Script_BehaviourTree p_tree, Script_Grid p_grid, blackboard_flags p_entityToGetLocationAround, Script_IEntity p_fromEntity, blackboard_flags p_locationToMoveTowardsFlag)
 {
     _tree       = p_tree;
     _grid       = p_grid;
     _fromEntity = p_fromEntity;
     _locationToMoveTowardsFlag = p_locationToMoveTowardsFlag;
     _entityToGetLocationAround = p_entityToGetLocationAround;
 }
Exemplo n.º 18
0
    public override void TakeDamage(Script_IEntity p_attacker, int p_damage)
    {
        Script_IEnemy attacker = p_attacker as Script_IEnemy;

        Assert.IsNotNull(attacker);

        _health -= p_damage;
    }
 public Script_Action_SetNearestEntityFromEntityWithinRange(Script_BehaviourTree p_tree, Script_Grid p_grid, blackboard_flags p_entityListFlag, int p_range, Script_IEntity p_fromEntity, blackboard_flags p_returnedEntityFlag)
 {
     _grid                      = p_grid;
     _tree                      = p_tree;
     _entityListFlag            = p_entityListFlag;
     _range                     = p_range;
     _fromEntity                = p_fromEntity;
     _returnedNearestEntityFlag = p_returnedEntityFlag;
 }
 public Script_Action_Heal(Script_BehaviourTree p_tree, Script_GameManager p_manager, blackboard_flags p_targetEnemyFlag, blackboard_flags p_locationAnchorPointFlag, Script_IEntity p_entityToAttack, blackboard_flags p_isForwardSwingFlag)
 {
     _manager            = p_manager;
     _tree               = p_tree;
     _targetEnemyFlag    = p_targetEnemyFlag;
     _entityToAttack     = p_entityToAttack;
     _isForwardSwingFlag = p_isForwardSwingFlag;
     _swingDistance      = _manager.GetTileSize() * 0.4f;
 }
    public Script_Condition_IsEntityTypeNearby(Script_BehaviourTree p_tree, Script_Grid p_grid, blackboard_flags p_entityListFlag, Script_IEntity p_targetEntity, int p_range)
    {
        _tree           = p_tree;
        _entityListFlag = p_entityListFlag;
        _grid           = p_grid;

        _targetEntity = p_targetEntity;

        _range = p_range;
    }
Exemplo n.º 22
0
    public Script_Condition_IsEntityNearby(Script_BehaviourTree p_tree, Script_Grid p_grid, blackboard_flags p_entityFlag, Script_IEntity p_measuredFromEntity, int p_range)
    {
        _tree       = p_tree;
        _entityFlag = p_entityFlag;
        _grid       = p_grid;

        _measuredFromEntity = p_measuredFromEntity;

        _range = p_range;
    }
 public Script_Action_SetEntitiesWithinRange(Script_BehaviourTree p_tree, Script_Grid p_grid, blackboard_flags p_listOfEntitiesFlag,
                                             blackboard_flags p_listOfEntitiesWithinRangeFlag, Script_IEntity p_entityToCalculateRangeFrom, int p_range)
 {
     _tree  = p_tree;
     _range = p_range;
     _entityToCalculateRangeFrom    = p_entityToCalculateRangeFrom;
     _listOfEntitiesFlag            = p_listOfEntitiesFlag;
     _listOfEntitiesWithinRangeFlag = p_listOfEntitiesWithinRangeFlag;
     _grid = p_grid;
 }
    public override NodeState RunNode(float p_delta)
    {
        _entity = _tree.GetBlackBoardElement <Script_IEntity> (_entityFlag);

        if (_entity == null || _entity.GetGameObject() == null)
        {
            return(NodeState.Success);
        }

        return(NodeState.Failed);
    }
    private void JumpDownAnimation(Script_IEntity p_jumpingEntity, float p_speed)
    {
        GameObject jumpingObject = p_jumpingEntity.GetGameObject();
        float      groundHeight  = _manager.GetGrid().GetGridDepthPosition();

        if ((jumpingObject.transform.position.y - groundHeight) < groundHeight)
        {
            _tree.SetBlackboardElement(_isForwardSwingFlag, true);
        }
        else
        {
            jumpingObject.transform.position += new Vector3(0, -1, 0) * p_speed * Time.deltaTime;
        }
    }
    public override NodeState RunNode(float p_delta)
    {
        List <Script_IEntity> entityList = _tree.GetBlackBoardElement <List <Script_IEntity> >(_entityListFlag);
        Script_IEntity        entityWithHighestThreat = GetHighestThreat(entityList);

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

        _tree.SetBlackboardElement(_entityWithHighestThreatFlag, entityWithHighestThreat);

        return(NodeState.Success);
    }
    private Script_IEntity GetEntityWithLowestHealth(List <Script_IEntity> p_listOfEntities)
    {
        int            health             = int.MaxValue;
        Script_IEntity lowestHealthEntity = null;

        foreach (Script_IEntity entity in p_listOfEntities.ToList())
        {
            if (entity.GetHealth() < health)
            {
                health             = entity.GetHealth();
                lowestHealthEntity = entity;
            }
        }
        return(lowestHealthEntity);
    }
Exemplo n.º 28
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)
    {
        Script_IEntity targetToAttack = _tree.GetBlackBoardElement <Script_IEntity> (_targetToAttackFlag);

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

        Script_IEnemy enemyToSet = _enemyToSet as Script_IEnemy;

        enemyToSet.SetTargetToAttack(targetToAttack);

        return(NodeState.Success);
    }
    private Script_IEntity GetNearestEntity(List <Script_IEntity> p_listToCheck)
    {
        float          range         = float.MaxValue;
        Script_IEntity nearestEntity = null;

        foreach (Script_IEntity entity in p_listToCheck)
        {
            if (Vector3Int.Distance(entity.GetGridLocation(), _position) < range)
            {
                range         = Vector3Int.Distance(entity.GetGridLocation(), _position);
                nearestEntity = entity;
            }
        }

        return(nearestEntity);
    }