Exemplo n.º 1
0
    public override void Action()
    {
        Debug.Log("convinceAction");

        GameObject player = GameObject.FindGameObjectWithTag("Player");

        targetIA = menuController.GetTargetIA();

        PersonalityBase targetPers = targetIA.GetComponent <AIPersonality> ();

        targetPers.interactionFromOtherCharacter = ActionsEnum.Actions.JOIN;

        updateTrust(true, targetPers, player.GetComponent <PersonalityBase> ().GetMyOwnIndex());


        reactionTree = targetIA.GetComponent <DecisionTreeReactionAfterInteraction>();

        if (reactionTree != null)
        {
            DestroyImmediate(reactionTree);
        }

        targetIA.gameObject.GetComponent <AIPersonality> ().oldNodes = targetIA.gameObject.GetComponents <DecisionTreeNode> ();
        foreach (DecisionTreeNode n in targetIA.gameObject.GetComponent <AIPersonality>().oldNodes)
        {
            DestroyImmediate(n);
        }

        reactionTree = targetIA.AddComponent <DecisionTreeReactionAfterInteraction>();

        reactionTree.target = GameObject.FindGameObjectWithTag("Player");

        this.gameObject.transform.parent.gameObject.SetActive(false);
    }
Exemplo n.º 2
0
    public void waitForAttack()
    {
        GameObject  player      = GameObject.FindGameObjectWithTag("Player");
        GroupScript myGroup     = player.GetComponent <GroupScript>();
        int         totalAttack = player.GetComponent <PlayerPersonality>().attack;

        foreach (var member in myGroup.groupMembers)
        {
            totalAttack += member.GetComponent <AIPersonality>().attack;
            //animacion numeritos
        }

        targetIA = menuController.GetTargetIA();

        PersonalityBase targetPers = targetIA.GetComponent <AIPersonality>();

        targetPers.interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK;
        targetIA.GetComponent <GroupScript>().ExitGroup();
        targetIA.GetComponent <VisibilityConeCycleIA>().enabled = true;

        targetPers.takeDamage(totalAttack, player.GetComponent <PersonalityBase> ());

        updateTrust(false, targetPers, player.GetComponent <PersonalityBase>().GetMyOwnIndex());


        reactionTree = targetIA.GetComponent <DecisionTreeReactionAfterInteraction>();

        if (reactionTree != null)
        {
            DestroyImmediate(reactionTree);
        }

        targetIA.gameObject.GetComponent <AIPersonality>().oldNodes = targetIA.gameObject.GetComponents <DecisionTreeNode>();

        foreach (DecisionTreeNode n in targetIA.gameObject.GetComponent <AIPersonality>().oldNodes)
        {
            DestroyImmediate(n);
        }

        reactionTree        = targetIA.AddComponent <DecisionTreeReactionAfterInteraction>();
        reactionTree.target = GameObject.FindGameObjectWithTag("Player");

        GroupScript leaderGroup = player.GetComponent <GroupScript>().groupLeader.GetComponent <GroupScript>();

        player.GetComponent <PersonalityBase>().formacionGrupo(leaderGroup.groupLeader, leaderGroup);
    }
Exemplo n.º 3
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
        }
    }
Exemplo n.º 4
0
    protected override void CreateTree()
    {
        //  base.targetPersonality = targetpers; //TESTING
        //Debug.Log("creando arbol what to do ");
        if (target.tag == "Player")
        {
            targetPersonality = this.GetComponent <DecisionTreeCreator>().target.GetComponent <PlayerPersonality>();
        }
        else
        {
            targetPersonality = this.GetComponent <DecisionTreeCreator>().target.GetComponent <AIPersonality>();
        }
        //Esto puede ser necesario en algun momento, pensamos que como se modifica desde fuera no es necesario
        //target = targetPersonality.gameObject;
        root = createDistanceDecisionFloat(this.gameObject.transform, target.transform, 60);

        iAmMonster         = createDecisionsBool(true, myPersonality, DecisionBool.BoolDecisionEnum.ISMONSTER);
        targetIsHuman      = createDecisionsBool(false, targetPersonality, DecisionBool.BoolDecisionEnum.ISMONSTER);
        isHeMonster        = createDecisionsBool(true, targetPersonality, DecisionBool.BoolDecisionEnum.ISMONSTER);
        targetInGroup      = createDecisionsBool(true, targetPersonality, DecisionBool.BoolDecisionEnum.INGROUP);
        iamInGroup         = createDecisionsBool(true, myPersonality, DecisionBool.BoolDecisionEnum.INGROUP);
        healthBigger70     = createDecisionsFloat(70, 100, myPersonality, FloatDecision.FloatDecisionTypes.HEALTH);
        TrustHimMore7      = createDecisionsFloat(7, 10, myPersonality, FloatDecision.FloatDecisionTypes.CONFIDENCEINOTHER);
        isInMyGroup        = createDecisionsBool(true, targetPersonality, DecisionBool.BoolDecisionEnum.IAMGROUPLEADER);
        hisHealthLess40    = createDecisionsFloat(0, 40, targetPersonality, FloatDecision.FloatDecisionTypes.HEALTH);
        iHaveBotiquin      = createObjectDecision(ObjectHandler.ObjectType.MEDICALAID, myPersonality);
        iHaveMono          = createObjectDecision(ObjectHandler.ObjectType.JUMPSUIT, myPersonality);
        iHaveShield        = createObjectDecision(ObjectHandler.ObjectType.SHIELD, myPersonality);
        TrustHimMore8      = createDecisionsFloat(8, 10, myPersonality, FloatDecision.FloatDecisionTypes.CONFIDENCEINOTHER);
        MyObjectIsNothing1 = createObjectDecision(ObjectHandler.ObjectType.NONE, myPersonality);
        CharismBigger3     = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.CHARISMA);
        MyObjectIsNothing2 = createObjectDecision(ObjectHandler.ObjectType.NONE, myPersonality);
        random1            = createRandomDecisionFloat(1, 3, 1, 2);
        TrustHimmore5      = createDecisionsFloat(5, 10, myPersonality, FloatDecision.FloatDecisionTypes.CONFIDENCEINOTHER);
        hisHealthLess45    = createDecisionsFloat(0, 45, targetPersonality, FloatDecision.FloatDecisionTypes.HEALTH);
        Agressive          = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.AGGRESSIVENESS);
        random2            = random1 = createRandomDecisionFloat(1, 3, 1, 2);
        iHaveBotiquin2     = createObjectDecision(ObjectHandler.ObjectType.MEDICALAID, myPersonality);
        CharismaBigger3_2  = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.CHARISMA);
        iHaveBotiquin2     = createObjectDecision(ObjectHandler.ObjectType.MEDICALAID, myPersonality);
        iHaveMono2         = createObjectDecision(ObjectHandler.ObjectType.JUMPSUIT, myPersonality);
        iHaveShield2       = createObjectDecision(ObjectHandler.ObjectType.SHIELD, myPersonality);
        CharismBigger3_3   = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.CHARISMA);
        Fear              = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.FEAR);
        random3           = createRandomDecisionFloat(1, 10, 8, 10);
        random4           = createRandomDecisionFloat(1, 5, 1, 2);
        TrustHimLess3     = createDecisionsFloat(0, 3, myPersonality, FloatDecision.FloatDecisionTypes.CONFIDENCEINOTHER);;
        Agressive2        = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.AGGRESSIVENESS);
        CharismaBigger3_4 = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.CHARISMA);
        iHaveAxe          = createObjectDecision(ObjectHandler.ObjectType.AXE, myPersonality);
        myHealthBigger80  = createDecisionsFloat(80, 100, myPersonality, FloatDecision.FloatDecisionTypes.HEALTH);
        Agressive3        = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.AGGRESSIVENESS);
        hisHealthLess45_2 = createDecisionsFloat(0, 45, targetPersonality, FloatDecision.FloatDecisionTypes.HEALTH);
        random5           = createRandomDecisionFloat(1, 10, 1, 8);
        CharismaBigger3_5 = createDecisionsFloat(3, 10, myPersonality, FloatDecision.FloatDecisionTypes.CHARISMA);
        random6           = createRandomDecisionFloat(1, 10, 1, 4);



        root.nodeTrue  = iAmMonster;
        root.nodeFalse = root;


        iAmMonster.nodeTrue  = targetIsHuman;
        iAmMonster.nodeFalse = isHeMonster;

        createLeaves(targetInGroup, addActionEvade(), addActionAttack());

        targetIsHuman.nodeTrue  = targetInGroup;
        targetIsHuman.nodeFalse = addActionNothing();


        isHeMonster.nodeTrue  = iamInGroup;
        isHeMonster.nodeFalse = TrustHimMore7;
        iamInGroup.nodeTrue   = healthBigger70;
        iamInGroup.nodeFalse  = addActionEvade();
        createLeaves(healthBigger70, addActionAttack(), addActionEvade());


        TrustHimMore7.nodeTrue  = isInMyGroup;
        TrustHimMore7.nodeFalse = TrustHimmore5;

        isInMyGroup.nodeTrue      = hisHealthLess40;
        isInMyGroup.nodeFalse     = addActionOfferJoinGroup();                 // OFREZCO unirse a mi grupo
        hisHealthLess40.nodeTrue  = iHaveBotiquin;
        hisHealthLess40.nodeFalse = TrustHimMore8;
        iHaveBotiquin.nodeTrue    = addActionOffer();
        iHaveBotiquin.nodeFalse   = iHaveMono;

        TrustHimMore8.nodeTrue  = MyObjectIsNothing1;
        TrustHimMore8.nodeFalse = CharismBigger3;

        CharismBigger3.nodeTrue      = MyObjectIsNothing2;
        CharismBigger3.nodeFalse     = addActionNothing();
        iHaveMono.nodeTrue           = addActionOffer();
        iHaveMono.nodeFalse          = iHaveShield;
        MyObjectIsNothing1.nodeTrue  = addActionNothing();
        MyObjectIsNothing1.nodeFalse = addActionOffer();
        MyObjectIsNothing2.nodeTrue  = addActionNothing();
        MyObjectIsNothing2.nodeFalse = random1;
        createLeaves(iHaveShield, addActionOffer(), addActionNothing());
        createLeaves(random1, addActionOffer(), addActionNothing());

        TrustHimmore5.nodeTrue  = hisHealthLess45;
        TrustHimmore5.nodeFalse = TrustHimLess3;

        hisHealthLess45.nodeTrue  = Agressive;
        hisHealthLess45.nodeFalse = CharismBigger3_3;

        Agressive.nodeTrue  = random2;
        Agressive.nodeFalse = iHaveBotiquin2;

        createLeaves(random2, addActionAttack(), addActionNothing());

        iHaveBotiquin2.nodeTrue  = addActionOffer();
        iHaveBotiquin2.nodeFalse = CharismaBigger3_2;

        CharismaBigger3_2.nodeTrue  = iHaveMono2;
        CharismaBigger3_2.nodeFalse = addActionNothing();

        iHaveMono2.nodeTrue  = addActionOffer();
        iHaveMono2.nodeFalse = iHaveShield2;

        createLeaves(iHaveShield2, addActionOffer(), addActionNothing());


        CharismBigger3_3.nodeTrue  = addActionOfferJoinGroup();
        CharismBigger3_3.nodeFalse = Fear;

        Fear.nodeTrue  = random3;
        Fear.nodeFalse = random4;
        createLeaves(random3, addActionOfferJoinGroup(), addActionNothing());
        createLeaves(random4, addActionAttack(), addActionOfferJoinGroup());


        TrustHimLess3.nodeTrue  = Agressive2;
        TrustHimLess3.nodeFalse = Agressive3;

        Agressive2.nodeTrue  = addActionAttack();
        Agressive2.nodeFalse = CharismaBigger3_4;

        CharismaBigger3_4.nodeTrue  = iHaveAxe;
        CharismaBigger3_4.nodeFalse = addActionNothing();

        iHaveAxe.nodeTrue  = myHealthBigger80;
        iHaveAxe.nodeFalse = addActionNothing();

        createLeaves(myHealthBigger80, addActionAttack(), addActionNothing());

        Agressive3.nodeTrue  = hisHealthLess45;
        Agressive3.nodeFalse = CharismaBigger3_5;

        hisHealthLess45.nodeTrue  = addActionAttack();
        hisHealthLess45.nodeFalse = random5;

        CharismaBigger3_5.nodeTrue  = random6;
        CharismaBigger3_5.nodeFalse = addActionNothing();

        createLeaves(random5, addActionAttack(), addActionNothing());
        createLeaves(random6, addActionOfferJoinGroup(), addActionNothing());
        DecisionCompleted = true;
        reaction          = this.GetComponent <DecisionTreeReactionAfterInteraction>();
        StartTheDecision();
    }
Exemplo n.º 5
0
    public override void CommunicateAction(Action actionNew)
    {
        // Debug.Log("He acabado y comunico accion");

        if (target.gameObject.tag == "IA" || target.tag == "Player")
        {  //avisar de que vamos a interactuar con él
            ActionAttack attack = new ActionAttack();
            ActionOffer  offer  = new ActionOffer();
            ActionOfferOtherJoinMyGroup join = new ActionOfferOtherJoinMyGroup();

            // Debug.Log(actionNew.GetType() + ", " + attack.GetType());

            bool decision = true;

            if (Object.ReferenceEquals(actionNew.GetType(), attack.GetType())) // compare classes
            {
                if (target.tag == "Player")
                {
                    target.GetComponent <PlayerPersonality>().interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK;
                    GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController>().OpenMenu(PlayerMenuController.MenuTypes.MENU_ATTACKED, target);
                    GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().SetTargetIA(this.gameObject);
                }
                else
                {
                    target.GetComponent <AIPersonality>().interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK;
                }

//                Debug.Log("Le he dicho que le ataco");
            }
            else if (Object.ReferenceEquals(actionNew.GetType(), offer.GetType())) // compare classes
            {
                if (target.tag == "Player")
                {
                    target.GetComponent <PlayerPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.OFFER;
                    GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().OpenMenu(PlayerMenuController.MenuTypes.MENU_OFFERED_OBJECT, target);
                    GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().SetTargetIA(this.gameObject);
                }
                else
                {
                    target.GetComponent <AIPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.OFFER;
                }
            }

            else if (Object.ReferenceEquals(actionNew.GetType(), join.GetType())) // compare classes
            {
                if (this.gameObject.GetComponent <GroupScript> ().groupMembers.Count
                    + target.GetComponent <GroupScript> ().groupMembers.Count < 2)
                {
                    if (target.tag == "Player")
                    {
                        target.GetComponent <PlayerPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.JOIN;
                        GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().OpenMenu(PlayerMenuController.MenuTypes.MENU_OFFERED_JOIN, target);
                        GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController> ().SetTargetIA(this.gameObject);
                    }
                    else
                    {
                        target.GetComponent <AIPersonality> ().interactionFromOtherCharacter = ActionsEnum.Actions.JOIN;
                    }
                    //Debug.Log("Le he dicho que se una a mi grupo");
                }
                else
                {
                    //Debug.Log ("El grupo es muy grande te jodes");
                    decision = false;
                }
            }
            else
            {
                //Debug.Log("Mi accion es NOTHING y NO le digo nada");
                decision = false;
            }



            if (decision)
            {
                if (target.tag != "Player")
                {
                    if (reaction != null)
                    {
                        Destroy(reaction);
                    }
                    reaction = target.AddComponent <DecisionTreeReactionAfterInteraction> ();
                    if (this != null)
                    {
                        reaction.target = this.gameObject;
                    }
                    target.GetComponent <VisibilityConeCycleIA>().enabled = false;
                }
            }
        }
    }