Exemple #1
0
    // Use this for initialization
    void Start()
    {
        Planeador = new GoapPlanner();

        maquinaDeEstados    = new FSMGOAP();
        AccionesActuales    = new Queue <GoapAction>();
        AccionesDisponibles = new List <GoapAction>();

        // proveedor de datos del mundo
        goapData = GetComponent <IGOAP>();

        //Crear nuestros estados
        CrearEstadoIdle();
        CrearEstadoActuar();
        CrearEstadoMoverse();

        // empezamos pensando
        maquinaDeEstados.pushState(idleState);

        // Cargar las acciones que puede hacer el agente
        GoapAction[] acciones = GetComponents <GoapAction>();
        foreach (GoapAction a in acciones)
        {
            AccionesDisponibles.Add(a);
        }
    }
Exemple #2
0
    private void PlanAndExecute()
    {
        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true)
            .LinkedState(patrolState),

            new GOAPAction("Chase")
            .Pre("isPlayerInSight", true)
            .Effect("isPlayerNear", true)
            .LinkedState(chaseState),

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Effect("isPlayerAlive", false)
            .LinkedState(meleeAttackState)
        };

        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerAlive"]   = true;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        planner.OnPlanCompleted += OnPlanCompleted;
        planner.OnCantPlan      += OnCantPlan;

        planner.Run(from, to, actions, StartCoroutine);
    }
Exemple #3
0
    private void RePlan(object[] parameters)
    {
        if ((GOAPEnemy)parameters[0] == this)
        {
            //Tendriamos que hacer aca el seteo del estado dependiendo las condiciones????
            StopAllCoroutines();
            //IA2-P3
            var nIEActions = actions.Aggregate(new List <GOAPAction>(), (acum, action) =>
            {
                //Intento de "Costos dinamicos"
                if (action.name == "Charge Mana")
                {
                    acum.Add(action.Cost(2 - mana / maxMana));
                }
                else if (action.name == "Melee Attack")
                {
                    var playerPosAtMyHeight = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z);
                    var delta = (playerPosAtMyHeight - transform.position);
                    acum.Add(action.Cost(1 + Mathf.Clamp01(delta.magnitude / distanceToChooseMelee)));
                }
                else
                {
                    acum.Add(action);
                }

                return(acum);
            });

            actions = nIEActions;
            planner.Run(from, to, actions, StartCoroutine);
            _fsm = GoapPlanner.ConfigureFSM(actions, StartCoroutine);
        }
    }
Exemple #4
0
    private void PlanAndExecute()
    {
        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true)
            .LinkedState(patrolState),


            new GOAPAction("Chase")
            .Pre("isPlayerInSight", true)
            .Effect("isPlayerNear", true)
            .LinkedState(chaseState),

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Effect("isPlayerAlive", false)
            .LinkedState(meleeAttackState)
        };

        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerAlive"]   = true;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        var plan = planner.Run(from, to, actions);

        ConfigureFsm(plan);
    }
 public override void Run(GoapPlanner planner, GoapAgent agent)
 {
     _parentagent   = agent;
     _parentplanner = planner;
     _parentplanner.worldState["targetPosition"] = new Vector3(Random.Range(0f, 100f), 0, Random.Range(0f, 100f));
     _parentplanner.ExecuteNextPlanAction();
 }
Exemple #6
0
    private void CreateIdleState()
    {
        idleState = (fsm, gameObj) => {
            // GOAP Planning

            Dictionary <string, object> worldState = agent.WorldState();
            Dictionary <string, object> goal       = agent.CreateGoalState();

            Queue <GoapAction> plan = GoapPlanner.Plan(gameObject, availableActions, worldState, goal);

            if (plan != null)
            {
                currentPlan = plan;
                agent.PlanFound(goal, plan);

                fsm.PopState();
                fsm.PushState(performActionState);
            }
            else
            {
                Debug.Log("<color=orange>Failed Plan:</color>" + goal);
                agent.PlanFailed(goal);
                fsm.PopState();
                fsm.PushState(idleState);
            }
        };
    }
Exemple #7
0
 public override void Run(GoapPlanner planner, GoapAgent agent)
 {
     _parentagent   = agent;
     _parentplanner = planner;
     Debug.Log("Use");
     StartCoroutine(Use());
 }
Exemple #8
0
 public void Initialise()
 {
     // get actions
     AvailableActions.Clear();
     AvailableActions.AddRange(GetComponents <GoapAction>());
     SetupUtilityEngine();
     myPlanner = new GoapPlanner();
 }
Exemple #9
0
 private void ApplyPlanEffects(GoapPlanner planner)
 {
     foreach (var kvp in effects)
     {
         var key   = kvp.Key;
         var value = kvp.Value;
         planner.state[key] = value;
     }
 }
Exemple #10
0
    void Awake()
    {
        availableActions = new HashSet <GoapAction> ();
        currentPlan      = new Queue <GoapAction> ();
        planner          = new GoapPlanner();

        agentImplementation = GetComponent <IGoap>();
        FSM = GetComponent <Animator>();

        LoadActions();
    }
Exemple #11
0
 public bool PlanExecution(GoapPlanner planner)
 {
     if (ActionPossible(planner))
     {
         ApplyPlanEffects(planner);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #12
0
	void Start () {
		stateMachine = new FSM ();
		availableActions = new HashSet<GoapAction> ();
		currentActions = new Queue<GoapAction> ();
		planner = new GoapPlanner ();
		findDataProvider ();
		createIdleState ();
		createMoveToState ();
		createPerformActionState ();
		stateMachine.pushState (idleState);
		loadActions ();
	}
Exemple #13
0
 private bool ActionPossible(GoapPlanner planner)
 {
     foreach (var kvp in preconditions)
     {
         var key   = kvp.Key;
         var value = kvp.Value;
         if (!planner.state.ContainsKey(key) || !planner.state[key].Equals(value))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #14
0
 void Start()
 {
     m_StateMachine     = new GoapFSM();
     m_AvailableActions = new HashSet <GoapAction> ();
     m_CurrentActions   = new Queue <GoapAction> ();
     planner            = new GoapPlanner();
     FindDataProvider();
     CreateIdleState();
     CreateMoveToState();
     CreatePerformActionState();
     m_StateMachine.PushState(m_IdleState);
     LoadActions();
 }
Exemple #15
0
 // Start is called before the first frame update
 void Start()
 {
     stateMachine   = new FiniteStateMachine();
     currentActions = new Stack <GoapAction>();
     planner        = new GoapPlanner();
     FindEnemyTypeComponent();
     InitializeActions();
     planner.Initialize(gameObject, availableActions);
     CreateIdleState();
     CreateMoveToState();
     CreatePerformActionState();
     stateMachine.PushState(idleState);
 }
 void Start()
 {
     _stateMachine     = new FSM();
     _availableActions = new HashSet <GoapAction>();
     _currentActions   = new Queue <GoapAction>();
     _planner          = new GoapPlanner();
     FindDataProvider();
     CreateIdleState();
     CreateMoveToState();
     CreatePerformActionState();
     _stateMachine.PushState(_idleState);
     LoadActions();
 }
Exemple #17
0
    public override void Run(GoapPlanner planner, GoapAgent agent)
    {
        _parentagent   = agent;
        _parentplanner = planner;
        float random_1 = Random.Range(0.0f, 100.0f);
        float random_2 = Random.Range(0.0f, 100.0f);

        actionState = EActionState.RUNNING;
        Debug.Log("Move" + (Vector3)_parentplanner.worldState["targetPosition"]);
        vec = (Vector3)_parentplanner.worldState["targetPosition"];
        agent.navAgent.destination = vec;
        Debug.Log(agent.navAgent.destination);
    }
Exemple #18
0
 void Start()
 {
     stateMachine     = new FSM();
     availableActions = new HashSet <GoapAction>();
     currentPlan      = new Queue <GoapAction>();
     planner          = new GoapPlanner();
     FindAgent();
     CreateIdleState();
     CreateMoveToState();
     CreatePerformActionState();
     stateMachine.PushState(idleState);
     LoadActions();
 }
 void Start()
 {
     stateMachine     = new FSM();
     availableActions = new HashSet <GoapAction> ();
     currentActions   = new Queue <GoapAction> ();
     planner          = new GoapPlanner();
     findDataProvider();
     createIdleState();
     createMoveToState();
     createPerformActionState();
     stateMachine.pushState(idleState);
     loadActions();
 }
Exemple #20
0
    private void OnCantPlan()
    {
        Debug.LogWarning("!!! NO PUDO COMPLETAR EL PLAN !!!");

        actions = new List <GOAPAction>
        {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true)
            .LinkedState(patrolState)
            .Cost(2),

            new GOAPAction("Chase")
            .Pre("isPlayerInSight", true)
            .Effect("isPlayerNear", true)
            .Effect("isPlayerInRange", true)
            .LinkedState(chaseState),

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Effect("isPlayerAlive", false)
            .LinkedState(meleeAttackState),

            new GOAPAction("Range Attack")
            .Pre("isPlayerInRange", true)
            .Pre("hasMana", true)
            .Effect("isPlayerAlive", false)
            .Effect("hasMana", false)
            .LinkedState(rangeAttackState),

            new GOAPAction("Charge Mana")
            .Effect("hasMana", true)
            .LinkedState(chargeManaState)
        };
        from = new GOAPState();
        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerInRange"] = false;
        from.values["hasMana"]         = false;
        from.values["isPlayerAlive"]   = true;
        to = new GOAPState();
        to.values["isPlayerAlive"] = false;

        planner = new GoapPlanner();
        planner.OnPlanCompleted += OnPlanCompleted;
        planner.OnCantPlan      += OnCantPlan;

        planner.Run(from, to, actions, StartCoroutine);

        _fsm = GoapPlanner.ConfigureFSM(actions, StartCoroutine);
    }
Exemple #21
0
    private void OnlyPlan()
    {
        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true),

            new GOAPAction("Chase")
            .Pre("isPlayerInSight", true)
            .Effect("isPlayerInRange", true)
            .Effect("isPlayerNear", true),

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Pre("hasMeleeWeapon", true)
            .Effect("isPlayerAlive", false)
            .Cost(2f),

            new GOAPAction("Range Attack")
            .Pre("isPlayerInRange", true)
            .Pre("hasRangeWeapon", true)
            .Effect("isPlayerAlive", false),

            new GOAPAction("Pick Melee Weapon")
            .Effect("hasMeleeWeapon", true)
            .Cost(2f),

            new GOAPAction("Pick Range Weapon")
            .Effect("hasRangeWeapon", true)
        };
        var from = new GOAPState();

        from.values["isPlayerInSight"] = true;
        from.values["isPlayerNear"]    = true;
        from.values["isPlayerInRange"] = true;
        from.values["isPlayerAlive"]   = true;
        from.values["hasRangeWeapon"]  = true;
        from.values["hasMeleeWeapon"]  = false;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        //planner.OnPlanCompleted += OnPlanCompleted;
        //planner.OnCantPlan      += OnCantPlan;

        planner.Run(from, to, actions, StartCoroutine);
    }
Exemple #22
0
 /// <summary>
 /// 开始
 /// </summary>
 private void Start()
 {
     //开始 初始化
     stateMachine     = new FSM();
     availableActions = new HashSet <GoapAction>();
     currentActions   = new Queue <GoapAction>();
     planner          = new GoapPlanner();
     //结束初始化
     FindDataProvider();
     CreateIdleState();
     CreateMoveToState();
     CreatePerformActionState();
     stateMachine.pushState(idleState);
     LoadActions();
 }
Exemple #23
0
        void Start()
        {
            availableActions = new HashSet <GoapAction> ();
            currentActions   = new Queue <GoapAction> ();
            planner          = new GoapPlanner();

            findDataProvider();
            LoadActions();
//			HashSet<KeyValuePair<string,object>> worldState = dataProvider.getWorldState();
//			HashSet<KeyValuePair<string,object>> goal = dataProvider.createGoalState();
//
//			Queue<GoapAction> plan = planner.plan(gameObject, availableActions, worldState, goal);

            ChangeState(new Idle());
        }
Exemple #24
0
    public void Start()
    {
        fsm = new FSM();
        availableActions = new HashSet <Action>();
        currentActions   = new Queue <Action>();
        planner          = new GoapPlanner();

        if (fsm.fsmStack.Count <= 0)
        {
            fsm.pushFSM("Idle");
        }
        player = gameObject.GetComponent <Player>();

        loadActions();
        IdleState();
    }
 void Start()
 {
     metrics = new Dictionary <string, int>();
     metrics.Add("actionsDone", 0);
     metrics.Add("abortedPlans", 0);
     stateMachine     = new FSM();
     availableActions = new HashSet <GoapAction>();
     currentActions   = new Queue <GoapAction>();
     planner          = new GoapPlanner();
     findDataProvider();
     createIdleState();
     createMoveToState();
     createPerformActionState();
     stateMachine.pushState(idleState);
     loadActions();
 }
Exemple #26
0
    public void Initialize(Character character)
    {
        _parentCharacter = character;

        WorkingMemory = new WorkingMemory();
        WorkingMemory.Initialize(_parentCharacter);

        BlackBoard = new BlackBoard();
        Sensor     = new AISensor();
        Sensor.Initialize(_parentCharacter);
        TargetingSystem = new AITargeting();
        TargetingSystem.Initialize(_parentCharacter);
        WeaponSystem = new AIWeapon();
        WeaponSystem.Initialize(_parentCharacter);
        Planner = new GoapPlanner(this);


        _goals              = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.GoapID);
        _actions            = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.GoapID);
        _currentWorldStates = new List <GoapWorldState>();

        _parentCharacter.MyEventHandler.OnCurrentActionComplete -= OnCurrentActionComplete;
        _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete;
        _parentCharacter.MyEventHandler.OnPerFrameTimer         -= PerFrameUpdate;
        _parentCharacter.MyEventHandler.OnPerFrameTimer         += PerFrameUpdate;

        //update parent character for each action
        foreach (GoapAction action in _actions)
        {
            action.ParentCharacter = _parentCharacter;
        }

        //BlackBoard.PatrolLoc = new Vector3(63.9f, 0.3f, -13.3f);
        //BlackBoard.PatrolRange = new Vector3(30, 10, 15);

        if (ControlType != AIControlType.Player)
        {
            BlackBoard.GuardLevel = 1;
            _parentCharacter.SendCommand(CharacterCommands.SetAlert);
        }

        _currentGoal   = null;
        _currentAction = null;


        _parentCharacter.MyEventHandler.OnOneSecondTimer += OnOneSecondTimer;
    }
Exemple #27
0
    private void OnlyPlan()
    {
        //var distanceKnife =

        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true),

            new GOAPAction("Chase")
            .Pre("isPlayerInSight", true)
            .Effect("isPlayerInRange", true)
            .Effect("isPlayerNear", true),

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Pre("hasMeleeWeapon", true)
            .Effect("isPlayerAlive", false)
            .Cost(2f),

            new GOAPAction("Range Attack")
            .Pre("isPlayerInRange", true)
            .Pre("hasRangeWeapon", true)
            .Effect("isPlayerAlive", false),

            new GOAPAction("Pick Melee Weapon")
            .Effect("hasMeleeWeapon", true),

            new GOAPAction("Pick Range Weapon")
            .Effect("hasRangeWeapon", true)
        };
        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerInRange"] = false;
        from.values["isPlayerAlive"]   = true;
        from.values["hasRangeWeapon"]  = false;
        from.values["hasMeleeWeapon"]  = false;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        planner.Run(from, to, actions);
    }
Exemple #28
0
    void Start()
    {
        // plan = gameObject.GetComponent<GoapPlanner>().plan; //i do this in goapplanner
        // UIcontent = GameObject.Find("Content");
        gp = GetComponent <GoapPlanner>();
        Node start = new Node(GameM.caravanState, GameM.inventoryState, -1, null);

        plan = gp.buildPlan(start);
        //  planCopy = new Stack<Node>();
        thief         = th.GetComponent <NavMeshAgent>();
        textInventory = new GameObject[] { TuInv, SaInv, CaInv, CiInv, ClInv, PeInv, SuInv };
        textCaravan   = new GameObject[] { TuCar, SaCar, CaCar, CiCar, ClCar, PeCar, SuCar };

        buildScroll();



        // plan = gp.plan();
        // velocity = player.velocity;
        // int count = 0;


        // if (p1== null) Debug.Log("hi");

        List <GameObject> ptexts = new List <GameObject> {
            p1, p2, p3, p4, p5, p6, p7, p8
        };
        //if(ptexts.Count == 0) Debug.Log("hi");
        List <Vector3> posStatic = new List <Vector3> {
            GameM.pos1, GameM.pos2, GameM.pos3, GameM.pos4, GameM.pos5, GameM.pos6, GameM.pos7, GameM.pos8
        };

        pos = new List <Vector3> {
            GameM.pos1, GameM.pos2, GameM.pos3, GameM.pos4, GameM.pos5, GameM.pos6, GameM.pos7, GameM.pos8
        };
        Shuffle(pos);
        pos.Add(GameM.caravanPos);
        pos.Add(GameM.caravanPos);

        // int count = 0;
        for (int i = 0; i < ptexts.Count; i++)
        {
            tm      = ptexts[i].GetComponent <TextMesh>();
            tm.text = "T" + (pos.IndexOf(posStatic[i]) + 1);
            //count++;
        }
    }
Exemple #29
0
	public void Initialize(Character character)
	{
		_parentCharacter = character;

		WorkingMemory = new WorkingMemory();
		WorkingMemory.Initialize(_parentCharacter);

		BlackBoard = new BlackBoard();
		Sensor = new AISensor();
		Sensor.Initialize(_parentCharacter);
		TargetingSystem = new AITargeting();
		TargetingSystem.Initialize(_parentCharacter);
		WeaponSystem = new AIWeapon();
		WeaponSystem.Initialize(_parentCharacter);
		Planner = new GoapPlanner(this);


		_goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.GoapID);
		_actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.GoapID);
		_currentWorldStates = new List<GoapWorldState>();

		_parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete;
		_parentCharacter.MyEventHandler.OnPerFrameTimer += PerFrameUpdate;

		//update parent character for each action
		foreach(GoapAction action in _actions)
		{
			action.ParentCharacter = _parentCharacter;
		}

		//BlackBoard.PatrolLoc = new Vector3(63.9f, 0.3f, -13.3f);
		//BlackBoard.PatrolRange = new Vector3(30, 10, 15);

		if(ControlType != AIControlType.Player)
		{
			BlackBoard.GuardLevel = 1;
			_parentCharacter.SendCommand(CharacterCommands.SetAlert);
		}

		_currentGoal = null;
		_currentAction = null;


		_parentCharacter.MyEventHandler.OnOneSecondTimer += OnOneSecondTimer;
	
	}
    private void Start()
    {
        fsm     = new FSM();
        planner = new GoapPlanner();

        availableActions = new List <GoapAction>();
        actionQueue      = new Queue <GoapAction>();

        FindDataProvider();
        CreateIdleState();
        CreateMoveToState();
        CreateActionState();

        fsm.PushState(idleState);

        LoadActions();
    }
    void Start()
    {
        ID = idIncrem;
        idIncrem++;
        stateMachine     = new FSM();
        availableActions = new HashSet <GoapAction> ();
        currentActions   = new Queue <GoapAction> ();
        planner          = new GoapPlanner();
        loadActions();
        findDataProvider();
        createIdleState();
        createMoveToState();
        createPerformActionState();
        stateMachine.pushState(idleState);

        Debug.Log("GoapAgent -- " + gameObject.name + " instance ID: " + gameObject.GetInstanceID());
    }
Exemple #32
0
    void Start()
    {
        fsm = new FSM();
        availableActions = new List <GoapAction>();
        currentActions   = new Queue <GoapAction>();
        planner          = new GoapPlanner();

        LoadAgent();

        //FSM:
        IdleState();
        MoveState();
        ActionState();

        fsm.pushState(idle);

        LoadActions();
    }
Exemple #33
0
    public void Initialize(Character character)
    {
        _parentCharacter = character;

        WorkingMemory = new WorkingMemory();
        WorkingMemory.Initialize(_parentCharacter);

        BlackBoard = new BlackBoard();
        Sensor = new AISensor();
        Sensor.Initialize(_parentCharacter);
        TargetingSystem = new AITargeting();
        TargetingSystem.Initialize(_parentCharacter);
        WeaponSystem = new AIWeapon();
        WeaponSystem.Initialize(_parentCharacter);
        Planner = new GoapPlanner(this);

        _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.ID);
        _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.ID);
        _currentWorldStates = new List<GoapWorldState>();

        _parentCharacter.MyEventHandler.OnNewEnemyTargetFound += OnImportantEvent;
        _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete;

        //update parent character for each action
        foreach(GoapAction action in _actions)
        {
            action.ParentCharacter = _parentCharacter;
        }

        BlackBoard.PatrolLoc = new Vector3(-15, 0, -15);
        BlackBoard.PatrolRange = new Vector3(20, 10, 20);
        BlackBoard.HasPatrolInfo = true;

        if(ControlType != AIControlType.Player)
        {
            _currentGoal = null;
            _currentAction = null;

            FindAndExecuteAction();
        }
    }
Exemple #34
0
    public void Start()
    {
        fsm = new FSM();
        availableActions = new HashSet<Action>();
        currentActions = new Queue<Action>();
        planner = new GoapPlanner();

        if(fsm.fsmStack.Count <= 0){
            fsm.pushFSM("Idle");
        }
        player = gameObject.GetComponent<Player>();

        loadActions();
        IdleState();
    }