Ejemplo n.º 1
0
    public void formacionGrupo(GameObject WhoToFollow, GroupScript leaderGroup)
    {
        string[]     baseBehaviours = { "Arrive", "AvoidWall", "Face" };
        float[]      weightedBehavs = { 1f, 8, 1 };
        GameObject[] targetsarray   = { WhoToFollow, WhoToFollow, WhoToFollow };

        List <GameObject> mates;
        List <string>     baseBehavioursformates;
        List <float>      baseWeightsformates;

        foreach (var mate in leaderGroup.groupMembers)
        {
            mates = new List <GameObject>();
            baseBehavioursformates = new List <string>();
            baseWeightsformates    = new List <float>();

            mates.AddRange(targetsarray);
            baseBehavioursformates.AddRange(baseBehaviours);
            baseWeightsformates.AddRange(weightedBehavs);

            foreach (var othermate in leaderGroup.groupMembers)
            {
                if (mate != othermate)
                {
                    mates.Add(othermate);
                    baseBehavioursformates.Add("Leave");
                    baseWeightsformates.Add(2f);
                }
            }
            mates.Add(this.gameObject);
            baseBehavioursformates.Add("Leave");
            baseWeightsformates.Add(2f);
            behaviourManager.addBehavioursOver(mate, convertListToArray <GameObject>(mates), convertListToArray <string>(baseBehavioursformates),
                                               convertListToArray <float>(baseWeightsformates));
        }
    }
Ejemplo n.º 2
0
    public void DetermineAction(GameObject behaviorReceiber, GameObject aux)
    {
        if (aux.tag == "IA")

        {
            aux.GetComponent <VisibilityConeCycleIA>().enabled = false;

            if (Mathf.Abs(Vector3.Distance(behaviorReceiber.transform.position, aux.transform.position)) <= MinDistanceOpenMenu && menuOpened)
            {
                // Debug.Log("estan cerca, abro menu");
                behaviourController.openConversationMenu(behaviorReceiber, aux);
            }
            else
            {
//                Debug.Log("esta lejos, me acercare");
                clickedOnTile = true;
                lastLinear    = movementScript.linearVelocity;

                string[] behaviours     = { "Arrive", "AvoidWall", "LookWhereYouAreGoing" };
                float[]  weightedBehavs = { 1f, 5f, 1 };

                GameObject[] targets = { aux, aux, aux };
                behaviourController.addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs);              //if IA character is too far, we need to arrive/pursue him in order to be near, so we can talk to him

                if (attack)
                {
                    aux.GetComponent <PersonalityBase>().interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK;
                    ActionAttack a = gameObject.AddComponent <ActionAttack>();
                    a.targetAttack = aux;
                    a.triggered    = true;
                    a.DoAction();

                    DecisionTreeReactionAfterInteraction reaction = aux.GetComponent <DecisionTreeReactionAfterInteraction>();
                    if (reaction != null)
                    {
                        DestroyImmediate(reaction);
                    }

                    DecisionTreeNode[] oldNodes = aux.GetComponents <DecisionTreeNode>();
                    foreach (DecisionTreeNode n in oldNodes)
                    {
                        DestroyImmediate(n);
                    }

                    reaction = aux.AddComponent <DecisionTreeReactionAfterInteraction>();

                    // Debug.Log("h collider es :" + aux.name + " reaction es " + reaction);
                    reaction.target = this.gameObject;
                    attack          = false;
                    // Debug.Log("reaction target es :" + reaction.target);
                }
            }
        }

        else if (aux.tag == "MenuButton")
        {
            aux.GetComponent <ButtonAction>().Action();
        }
        else if (aux.tag == "Player")
        {
            //Debug.Log("Pa k clikas en el player, jaja salu2");
        }
        else if (aux.layer == 8 || aux.layer == 10)
        {
            //Esto es para que al clickar en un muro o en los muebles no haga nada
        }
        else
        { // target is floor
            string[]     behaviours     = { "Arrive", "AvoidWall", "LookWhereYouAreGoing" };
            float[]      weightedBehavs = { 0.7f, 1, 1 };
            GameObject[] targets        = { aux, aux, aux, };
            behaviourController.addBehavioursOver(behaviorReceiber, targets, behaviours, weightedBehavs);
            //ActionWhenClick(behaviorReceiber, aux); //if IA character is too far, we need to arrive/pursue him in order to be near, so we can talk to him
        }
    }
    private void checkObjectsWithinCone()
    {
        string  objectINeedRemember = ObjectINeedRemember();
        Vector2 A, B, C;

        A = VisibleConePoints.First.Value;
        B = source;
        C = VisibleConePoints.Last.Value;
        foreach (var singleObject in Objects)
        {
            Debug.DrawLine(A, B);
            Debug.DrawLine(B, C);
            Debug.DrawLine(C, A);
            if (isInTriangleABC(singleObject.transform.position, A, B, C))
            {
                if (singleObject != this.gameObject)
                {
                    visibleGameobjects.Add(singleObject);
                }
                //singleObject.GetComponent<SpriteRenderer>().color = Color.Lerp(Color.white, Color.red, Random.Range(0f, 1f));
            }
        }

        if (visibleGameobjects.Count > 0)
        {
            if (objectINeedRemember != "None")
            {
                // = RememberedObject(objectINeedRemember);
                RoomMemory rM = this.gameObject.GetComponent <RoomMemory>();
                if (personality.myMemory.objectWithinRoom.ContainsKey(objectINeedRemember))
                {
                    rM.SetDestinyRoom(personality.myMemory.objectWithinRoom[objectINeedRemember]);
                }
                //Debug.Log("Quiero ir a por el " + objectINeedRemember + ", que está en " + personality.myMemory.objectWithinRoom[objectINeedRemember]);
                priorityGO = RememberedObjectInARoom(objectINeedRemember);

                //Debug.Log("necesito el objeto: " + priorityGO);
            }
            else
            {
                priorityGO = decisionTargetScript.ChooseTarget(visibleGameobjects, this.gameObject);
                //Debug.Log("SOY: "+ this.gameObject.name +" PRIORITY GO ES " + priorityGO);
            }

            visibleGameobjects.Clear();
            //Debug.Log ("priority object= " + priorityGO.name);
            if (priorityGO == null) // no ha visto nada
            {
                moveRandomly(A, C);
            }
            else
            {
                if (priorityGO.tag == "IA")                   //lo más prioritario es una persona
                {
                    #region deccidingReg
                    if (!IDecided)
                    {
                        //  Debug.Log("veo una Ia voy a decidir, soy " + this.name );
                        IDecided = true;

                        priorityGO.GetComponent <VisibilityConeCycleIA>().enabled = false;

                        if (whatToDoScript == null)
                        {
                            whatToDoScript = this.gameObject.AddComponent <DecisionTreeISeeSomeoneWhatShouldIDo>();
                        }
                        else
                        {
                            DestroyImmediate(whatToDoScript);

                            DecisionTreeNode[] oldNodes = this.gameObject.GetComponents <DecisionTreeNode>();
                            foreach (DecisionTreeNode n in oldNodes)
                            {
                                DestroyImmediate(n);
                            }

                            whatToDoScript = this.gameObject.AddComponent <DecisionTreeISeeSomeoneWhatShouldIDo>();
                        }

                        whatToDoScript.target = priorityGO;

                        string[] behaviours = new string[3] {
                            "Pursue", "AvoidWall", "Face"
                        };
                        float[]      weightedBehavs = { 0.7f, 1, 1 };
                        GameObject[] targets        = { priorityGO, priorityGO, priorityGO };
                        movementController.addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs);
                    }
                    #endregion decidingReg
                }
                else if (priorityGO.tag == "Player")                   //lo más prioritario es una persona
                {
                    #region deccidingReg
                    if (!IDecided)
                    {
                        //Debug.Log ("veo al player");
                        //  Debug.Log("veo una Ia voy a decidir, soy " + this.name );
                        IDecided = true;

                        // Debug.Log("yo " + this.gameObject.transform + "veo a  " + priorityGO + " (target)");
                        if (whatToDoScript == null)
                        {
                            whatToDoScript = this.gameObject.AddComponent <DecisionTreeISeeSomeoneWhatShouldIDo>();
                        }
                        else
                        {
                            DestroyImmediate(whatToDoScript);

                            whatToDoScript = this.gameObject.AddComponent <DecisionTreeISeeSomeoneWhatShouldIDo>();
                        }

                        whatToDoScript.target = priorityGO;

                        string[] behaviours = new string[3] {
                            "Pursue", "AvoidWall", "Face"
                        };
                        float[]      weightedBehavs = { 0.7f, 1, 1 };
                        GameObject[] targets        = { priorityGO, priorityGO, priorityGO };
                        movementController.addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs);
                    }
                    #endregion decidingReg
                }
                else //lo más prioritario es un objeto
                {
                    if (VisibleElements.visibleGameObjects.Contains(priorityGO))
                    {
                        //Debug.Log("priorityGo es: " + priorityGO);
                        if (priorityGO.tag == "Object")
                        {
                            objecthand.desiredObject = priorityGO;
                        }
                        GameObject targetGO = (GameObject)Instantiate(ghostTarget, priorityGO.transform.position, Quaternion.identity);
                        targetsAux.Add(targetGO);
                        // Debug.Log("busco el objeto");
                        //Debug.Log ("Deseo " + objecthand.desiredObject);
                        //objecthand.setDesiredGameObject(priorityGO);
                        string[] behaviours = new string[3] {
                            "Arrive", "AvoidWall", "LookWhereYouAreGoing"
                        };
                        float[]      weightedBehavs = { 0.7f, 1, 1 };
                        GameObject[] targets        = { targetGO, targetGO, targetGO };
                        movementController.addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs);
                        DeleteTargetAux();
                    }
                    else
                    {
                        moveRandomly(A, C);
                    }
                }
            }
        }
        else
        {
            if (this.GetComponent <AgentPositionController>() == null)
            {
                Debug.Log("no tengo control de movimiento y lo añado");
                this.gameObject.AddComponent <AgentPositionController>();
            }
            if (objectINeedRemember != "None")
            {
                //priorityGO = RememberedObject(objectINeedRemember);
                RoomMemory rM = this.gameObject.GetComponent <RoomMemory>();
                if (personality.myMemory.objectWithinRoom.ContainsKey(objectINeedRemember))
                {
                    rM.SetDestinyRoom(personality.myMemory.objectWithinRoom[objectINeedRemember]);
                }
                //Debug.Log("Quiero ir a por el " + objectINeedRemember + ", que está en " + personality.myMemory.objectWithinRoom[objectINeedRemember]);
                priorityGO = RememberedObjectInARoom(objectINeedRemember);

                if (priorityGO != null)
                {
                    if (priorityGO.tag == "Object")
                    {
                        objecthand.desiredObject = priorityGO;
                    }
                    //Debug.Log("Deseo " + objecthand.desiredObject);
                    GameObject targetGO = (GameObject)Instantiate(ghostTarget, priorityGO.transform.position, Quaternion.identity);
                    targetsAux.Add(targetGO);
                    string[] behaviours = new string[3] {
                        "Arrive", "AvoidWall", "LookWhereYouAreGoing"
                    };
                    float[]      weightedBehavs = { 0.7f, 1, 1 };
                    GameObject[] targets        = { targetGO, targetGO, targetGO };
                    movementController.addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs);
                    DeleteTargetAux();
                }
                else
                {
                    moveRandomly(A, C);
                }
            }
            else
            {
                moveRandomly(A, C);
            }
        }
    }