Example #1
0
 public State(STATE stateName, AbstractNPCBrain brain, UnityAction onEnter = null, UnityAction onExit = null)
 {
     this.stateName = stateName;
     this.brain     = brain;
     this.OnEnter   = onEnter;
     this.OnExit    = onExit;
 }
Example #2
0
 public static void AddBehaviours(AbstractNPCBrain abstracNpc, List <Action> _behaviours, State _state)
 {
     foreach (State state in abstracNpc.states)
     {
         if (state == _state)
         {
             state.actions = _behaviours;
         }
     }
 }
Example #3
0
    public static void DeleteTransition(AbstractNPCBrain abstracNpc, State currentState, List <NextStateInfo> nextStatesInfos)
    {
        Transition _transition = new Transition(currentState, nextStatesInfos);

        foreach (Transition trans in abstracNpc.transitions)
        {
            if (trans == _transition)
            {
                abstracNpc.transitions.Remove(trans);
            }
        }
    }
Example #4
0
    public static void AddTransition(AbstractNPCBrain abstracNpc, STATE currentStateName, List <NextStateInfo> nextStateInfos)
    {
        State _currentState = abstracNpc.states.Find((x) => x.stateName == currentStateName);
        List <NextStateInfo> _nextStateInfos = nextStateInfos;

        Transition _transition = new Transition(_currentState, _nextStateInfos);

        foreach (Transition trans in abstracNpc.transitions)
        {
            if (trans == _transition) //TODO: falta delimitarlo más.
            {
                Debug.Log("Can't add it because there already is a transition like this");
            }
        }
        abstracNpc.transitions.Add(_transition);
    }
Example #5
0
        private void AnalyzeSurroundingInfluences(List <AITaskCommand> aiTaskCommands,
                                                  StrategicObjective chosenStrategicObjective, Entity analyzedEntity,
                                                  Entity[] playerControlledEntites, LevelController levelController)
        {
            AbstractNPCBrain analyzedNpc = analyzedEntity.GetComponent <AbstractNPCBrain>();

            if (analyzedNpc != null) // es una entidad con brain, es decir, no es un muro
            {
                //get node of the entity in the influence map
                // look in a ring
                InfluenceMap.Node node          = _influenceMapComponent.GetNodeAtLocation(analyzedNpc.transform.position);
                List <Node>       influenceData = _influenceMapComponent.GetKRingsOfNodes(node, chosenStrategicObjective.SampleRadius);

                Entity chosenTarget = chosenStrategicObjective.DecideBasedOnInfluenceData(analyzedNpc, influenceData, playerControlledEntites, levelController);

                if (chosenTarget == null && !(analyzedNpc is Troop))
                {
                    return;
                }
                if (chosenTarget == null && analyzedNpc is Troop) //no hay nadie a quien atacar o mejorar, pues movemos.
                {
                    Debug.Log("trying to move");
                    aiTaskCommands.Add(new MoveAITaskCommand(analyzedNpc));
                }
                else if (chosenTarget.owner == Entity.Owner.AI)
                {
                    //mejorar
                    Debug.Log("trying to upgrade");
                    aiTaskCommands.Add(new UpgradeAITaskCommand(chosenTarget));
                }
                else if (chosenTarget.owner == Entity.Owner.Player)
                {
                    Debug.Log("trying to attack");
                    aiTaskCommands.Add(new AttackAITaskCommand(analyzedNpc, chosenTarget));
                }
            }
            else // es un muro
            {
                return;
            }
        }
Example #6
0
 public static State GetNextState(AbstractNPCBrain abstracNpc, bool _bool, State currentState, Order order)
 {
     foreach (Transition trans in abstracNpc.transitions)
     {
         if (trans.currentState == currentState)
         {
             foreach (NextStateInfo nsi in trans.nextStateInfo)
             {
                 if (order == nsi.order && _bool)
                 {
                     return(nsi.stateCaseTrue);
                 }
                 else if (order == nsi.order && !_bool)
                 {
                     return(nsi.stateCaseFalse);
                 }
             }
         }
     }
     return(null);
 }
Example #7
0
        public override Entity DecideBasedOnInfluenceData(AbstractNPCBrain analyzedNPC, List <Node> influenceData,
                                                          Entity[] playerControlledEntites, LevelController levelController)
        {
            Entity[] coreEntities = levelController.playerCoreEntities.ToArray();

            //Cuando se lanze este método, todas las unidades solo podran atacar al core.
            if (analyzedNPC is Troop)
            {
                Debug.Log("generamos posibles nodos a mover. ");
                Entity closestCore = GetClosestEntityInCollection(analyzedNPC, coreEntities);
                analyzedNPC.GetComponent <Troop>().GetCellsWithEnemiesInRange();
                if (analyzedNPC.GetComponent <Troop>().possibleAttacks.Contains(closestCore.cell.PNode))
                {
                    return(closestCore);
                }
                else
                {
                    return(null);
                }
            }

            //si hay null no pasa nada, se gestiona luego
            return(null);
        }
Example #8
0
 public MoveAITaskCommand(AbstractNPCBrain brain)
 {
     _levelController = Object.FindObjectOfType <LevelController>();
     this.troopToMove = brain.GetComponent <Troop>();
 }
Example #9
0
    public static State FindState(AbstractNPCBrain abstracNpc, STATE stateName)
    {
        State returnState = abstracNpc.states.Find((x) => x.stateName == stateName);

        return(returnState);
    }
Example #10
0
 public static void AddState(AbstractNPCBrain abstracNpc, State newState)
 {
     abstracNpc.states.Add(newState);
 }
        public override Entity DecideBasedOnInfluenceData(AbstractNPCBrain analyzedNPC, List <Node> influenceData, Entity[] playerControlledEntites, LevelController levelController)
        {
            List <float> dataSum       = new List <float>();
            Entity       minDistEntity = null;

            float coreSum      = 0f;
            float prisionerSum = 0f;
            float launcherSum  = 0f;
            float tankSum      = 0f;
            float turretSum    = 0f;

            //calculo todas las influencias cercanas del npc
            foreach (var node in influenceData)
            {
                if (node.HasInfluenceOfType(InfluenceType.Core))
                {
                    coreSum += node.GetInfluenceOfType(InfluenceType.Core).Value;
                }
                else if (node.HasInfluenceOfType(InfluenceType.Prisioner))
                {
                    prisionerSum += node.GetInfluenceOfType(InfluenceType.Prisioner).Value;
                }
                else if (node.HasInfluenceOfType(InfluenceType.Launcher))
                {
                    launcherSum += node.GetInfluenceOfType(InfluenceType.Launcher).Value;
                }
                else if (node.HasInfluenceOfType(InfluenceType.Tank))
                {
                    tankSum += node.GetInfluenceOfType(InfluenceType.Tank).Value;
                }
                else if (node.HasInfluenceOfType(InfluenceType.Turret))
                {
                    turretSum += node.GetInfluenceOfType(InfluenceType.Turret).Value;
                }

                //todo influencia del core
            }

            dataSum.Add(coreSum);
            dataSum.Add(prisionerSum);
            dataSum.Add(launcherSum);
            dataSum.Add(tankSum);
            dataSum.Add(turretSum);

            //si el npc es launcher o prisioner podran atacar a todo tipo de entidades, ya sean tropas, torretas o el core
            if (analyzedNPC.entityType == ENTITY.Launcher || analyzedNPC.entityType == ENTITY.Prisioner)
            {
                if (coreSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, levelController.playerCoreEntities.ToArray(), ENTITY.Core);
                }
                else if (launcherSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, playerControlledEntites, ENTITY.Launcher);
                }
                else if (prisionerSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, playerControlledEntites, ENTITY.Prisioner);
                }
                else if (tankSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, playerControlledEntites, ENTITY.Tank);
                }
                else if (turretSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, playerControlledEntites, ENTITY.Turret);
                }

                if (minDistEntity != null)
                {
                    analyzedNPC.GetComponent <Troop>().GetCellsWithEnemiesInRange();

                    if (analyzedNPC.GetComponent <Troop>().possibleAttacks.Contains(minDistEntity.cell.PNode))
                    {
                        return(minDistEntity);
                    }
                }
            }
            else if (analyzedNPC.entityType == ENTITY.Tank) //si es tanque, solo podra atacar al core y a torretas
            {
                dataSum.Remove(launcherSum);
                dataSum.Remove(prisionerSum);
                dataSum.Remove(tankSum);

                if (coreSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, levelController.playerCoreEntities.ToArray());
                }

                else if (turretSum == Mathf.Max(dataSum.ToArray()))
                {
                    minDistEntity = GetClosestEntityInCollection(analyzedNPC, playerControlledEntites, ENTITY.Turret);
                }

                if (minDistEntity != null)
                {
                    analyzedNPC.GetComponent <Troop>().GetCellsWithEnemiesInRange();

                    if (analyzedNPC.GetComponent <Troop>().possibleAttacks.Contains(minDistEntity.cell.PNode))
                    {
                        return(minDistEntity);
                    }
                }
            }

            else if (analyzedNPC.entityType == ENTITY.Turret)
            {
                return(analyzedNPC);
            }

            return(null);
        }
 public abstract Entity DecideBasedOnInfluenceData(AbstractNPCBrain analyzedNpc, List <Node> influenceData,
                                                   Entity[] playerControlledEntites, LevelController levelController);
 public AttackAITaskCommand(AbstractNPCBrain analyzedEntity, Entity chosenTarget) //si devuelve null chosenTarget, significa que es Turret
 {
     _doer             = analyzedEntity;
     this.chosenTarget = chosenTarget;
 }
Example #14
0
 public NextStateInfo(AbstractNPCBrain abstractNpc, STATE stateTrue, STATE stateFalse, Order order)
 {
     this.stateCaseTrue  = FSMSystem.FindState(abstractNpc, stateTrue);
     this.stateCaseFalse = FSMSystem.FindState(abstractNpc, stateFalse);
     this.order          = order;
 }