/// <summary>
    /// Traduce a una string el objeto que tiene la IA para poder compararlo con el nombre
    /// del GameObject más prioritario y saber así si ya lo tiene o no
    /// </summary>
    /// <param name="personality"></param>
    /// <returns></returns>

    public string objectTraduction(PersonalityBase personality)
    {
        if (personality.myObject == ObjectHandler.ObjectType.AXE)
        {
            return("Axe");
        }
        else if (personality.myObject == ObjectHandler.ObjectType.BOOTS)
        {
            return("Boots");
        }
        else if (personality.myObject == ObjectHandler.ObjectType.FLASHLIGHT)
        {
            return("Flashlight");
        }
        else if (personality.myObject == ObjectHandler.ObjectType.JUMPSUIT)
        {
            return("Jumpsuit");
        }
        else if (personality.myObject == ObjectHandler.ObjectType.MEDICALAID)
        {
            return("Medicalaid");
        }
        else if (personality.myObject == ObjectHandler.ObjectType.SHIELD)
        {
            return("Shield");
        }
        else
        {
            return("NONE");
        }
    }
Beispiel #2
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);
    }
Beispiel #3
0
 void Start()
 {
     render            = menuConversation.GetComponent <SpriteRenderer>();
     player            = GameObject.FindGameObjectWithTag("Player");
     playerPersonality = player.GetComponent <PersonalityBase>();
     playerSprite      = player.GetComponent <SpriteRenderer>();
 }
Beispiel #4
0
    protected PriorityObjectDecision createPriorityObjectDecision(PersonalityBase myPers, PersonalityBase yourPers)
    {
        PriorityObjectDecision d = gameObject.AddComponent <PriorityObjectDecision>() as PriorityObjectDecision;

        d.characterPersonality = myPers;
        d.targetPersonality    = yourPers;

        return(d);
    }
Beispiel #5
0
    protected DecisionBool createDecisionsBool(bool vDecision, /* bool vTest*/ PersonalityBase personality, DecisionBool.BoolDecisionEnum boolType)
    {
        DecisionBool d;

        d = gameObject.AddComponent <DecisionBool>();
        d.valueDecision = vDecision;
        // d.valueTest = vTest;
        d.personalityScript  = personality;
        d.actualDecisionenum = boolType;

        return(d);
    }
Beispiel #6
0
    protected void updateTrust(bool increase, PersonalityBase pers, int index)
    {
        //	Debug.Log ("se esta actualizand la confianza de : " + pers.gameObject.name + " indice: " + index);

        if (increase)
        {
            pers.TrustInOthers [index] += 1;
        }
        else
        {
            pers.TrustInOthers [index] -= 1;
        }
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0)) //Si clicamos
        {
            Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 mousePos      = new Vector2(mouseWorldPos.x, mouseWorldPos.y); //Esto coje la posición en la pantalla

            Vector2        dir = Vector2.zero;
            RaycastHit2D[] hit = Physics2D.RaycastAll(mousePos, dir, 10000, avoidCollisionWith);


            string hitinfo = "";
            foreach (var h in hit)
            {
                GameObject GOclicked = h.collider.gameObject;

                //Debug.Log("Estoy pinchando en: " + h.collider);
                if (GOclicked.tag == "IA")
                {
                    PersonalityBase personality = this.GetComponent <PersonalityBase>();

                    if (personality.isMonster)
                    {
                        if (Vector3.Distance(this.transform.position, GOclicked.transform.position) < 50)
                        {
                            attack = true;
                        }
                    }
                    else
                    {
                        menuOpened = true;
                        attack     = false;
                    }
                }
                else
                {
                    menuOpened = false;
                    if (h.collider.gameObject.tag == "Object")
                    {
                        objectHandlerPlayer.desiredObject = h.collider.gameObject;
                        //Debug.Log("Deseo: " + objectHandlerPlayer.desiredObject);
                    }
                }


                hitinfo += h.collider.gameObject.name;
                GameObject aux = h.collider.gameObject;
                DetermineAction(this.gameObject, aux);
            }
        }
    }
Beispiel #8
0
    void Attack(int a)
    {
        var arbol = this.GetComponent <DecisionTreeCreator>();

        if (arbol != null)
        {
            try
            {
                if (!triggered)
                {
                    targetAttack = arbol.target;
                }
            }
            catch
            {
                Debug.LogError("Ha ocurrido error en " + this.name);
            }

            PersonalityBase targetPers = targetAttack.GetComponent <PersonalityBase>();

            GroupScript targetGroup = targetPers.gameObject.GetComponent <GroupScript>();
            if (targetGroup.groupLeader == this.gameObject.GetComponent <GroupScript>().groupLeader)
            {
                if (targetGroup.groupMembers.Count > 0)
                {
                    if (targetGroup.IAmTheLeader)
                    {
                        var members = targetGroup.groupMembers;
                        targetGroup.ExitGroup();
                        foreach (var m in members)
                        {
                            GroupScript memberGroup = m.GetComponent <GroupScript>();
                            memberGroup.groupLeader = members[0];
                        }
                    }
                    else
                    {
                        targetGroup.ExitGroup();
                    }
                }
            }
            updateTrust(false, targetPers, this.GetComponent <PersonalityBase>().GetMyOwnIndex());
            targetPers.takeDamage(a, this.GetComponent <PersonalityBase>());

            //HAY QUE RECORRER EL GRUPO DEL TARGET Y REDUCIR LA CONFIANZA DE TODOS
        }
    }
Beispiel #9
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);
    }
    public override void takeDamage(int damage, PersonalityBase personality)
    {
        health -= (int)(damage * defense);
        HealthImage.GetComponent <Image>().fillAmount = health / 100f;

        Debug.Log(HealthImage.GetComponent <Image>().fillAmount);
        if (health > 50)
        {
            HealthImage.GetComponent <Image>().color = new Color(82f / 255, 178f / 255, 82f / 255);
        }
        else if (health <= 50 && health > 33)
        {
            HealthImage.GetComponent <Image>().color = new Color(226f / 255, 213f / 255, 89f / 255);
        }
        else if (health <= 33 && health > 0)
        {
            HealthImage.GetComponent <Image>().color = new Color(193f / 255, 52 / 255f, 52f / 255);
        }
        else if (health <= 0)
        {
            VisibleElements.visibleGameObjects.Remove(this.gameObject);

            gameController gc = GameObject.FindGameObjectWithTag("GameController").GetComponent <gameController> ();

            if (personality.isMonster && !theThing)
            {
                theThing = true;
                health   = 100;
                Debug.Log("soy humano y me infectan");
                gc.numberOfMonsters++;
                GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController>().CheckIfMonster();
                gc.decreaseHumans();
            }
            else
            {
                youLost();
            }
            Debug.Log("humanos: " + gc.numberOfHumans + " monstruos: " + gc.numberOfMonsters);
        }
    }
Beispiel #11
0
    public override void Start()
    {
        //   Debug.Log("start dec tree creator");

        //target = this.gameObject; //just to create the decisiontree

        myPersonality = this.gameObject.GetComponent <AIPersonality>();
        if (target.tag == "Player")
        {
            targetPersonality = target.gameObject.GetComponent <PlayerPersonality>();
        }
        else
        {
            targetPersonality = target.gameObject.GetComponent <AIPersonality>();
        }

        indexCharacterInteractedWithMe = targetPersonality.GetMyOwnIndex();
        myTrustInOther = myPersonality.TrustInOthers[indexCharacterInteractedWithMe];



        CreateTree();
    }
 public virtual void takeDamage(int damage, PersonalityBase personality)
 {
 }
Beispiel #13
0
    protected ObjectDecision createObjectDecision(ObjectHandler.ObjectType objecttest, PersonalityBase pers)
    {
        ObjectDecision d = gameObject.AddComponent <ObjectDecision>() as ObjectDecision;

        d.myPersonality = pers;
        d.objectWanted  = objecttest;

        return(d);
    }
Beispiel #14
0
    protected FloatDecision createDecisionsFloat(float min, float max /*,float testValue*/, PersonalityBase personality, FloatDecision.FloatDecisionTypes type)
    {
        FloatDecision d = gameObject.AddComponent <FloatDecision>() as FloatDecision;

        d.minvalue = min;
        d.maxValue = max;
        // d.testValue = testValue;
        d.characterPersonality = personality;
        d.actualDecisionType   = type;

        if (type == FloatDecision.FloatDecisionTypes.CONFIDENCEINOTHER)
        {
            d.targetPersonality = targetPersonality;
        }

        return(d);
    }
Beispiel #15
0
    protected DecisionActionsEnum createDecisionsEnum(ActionsEnum.Actions vDecision /*, ActionsEnum.Actions vTest*/, PersonalityBase pers)
    {
        DecisionActionsEnum d = gameObject.AddComponent <DecisionActionsEnum>();

        d.valueDecision = vDecision;
        d.personality   = pers;

        return(d);
    }
    public int GetPriority(GameObject target, PersonalityBase Personality)
    {
        if (target.name == "Medicalaid") // Es botiquin
        {
            if (Personality.health < 20)
            {
                priority = 4;
            }

            else
            {
                priority = 0;
            }
        }
        else // No es botiquin
        {
            if (Personality.charisma > Personality.selfAssertion && Personality.charisma > Personality.fear) //Es carismática
            {
                //Debug.Log("SUperCarismática");
                if (target.tag == "IA" || target.tag == "player") // Es una MockIAa
                {
                    GroupScript iagroup    = target.GetComponent <GroupScript>();
                    int         confidence = Personality.TrustInOthers[target.GetComponent <PersonalityBase>().GetMyOwnIndex()];

                    if (confidence > 5) // Confía en ella
                    {
                        if (iagroup.checkIAInGroup(this.gameObject))
                        {
                            priority = 0;
                        }
                        else
                        {
                            if (iagroup.groupLeader == target && iagroup.inGroup)
                            {
                                priority = 3;
                            }
                            else if (!iagroup.inGroup)
                            {
                                priority = 0;
                            }
                            else
                            {
                                priority = -1;
                            }
                        }
                    }
                    else // No confía en ella
                    {
                        priority = 1;
                    }
                }
                else // No es una MockIAa
                {
                    if (target.name == "Axe") // es un hacha FALTA condicion y no llevo
                    {
                        if (Personality.selfAssertion > Personality.fear) // más agresivo que miedoso
                        {
                            priority = 2;
                        }
                        else // más miedoso que agresivo
                        {
                            priority = 1;
                        }
                    }
                    else if (target.name == "Shield")                     // es un mono// no es hacha
                    {
                        if (Personality.selfAssertion > Personality.fear) // es agresivo más que miedoso
                        {
                            priority = 1;
                        }
                        else
                        {
                            priority = 2;
                        }
                    }
                    else // es otro objeto
                    {
                        priority = 1;
                    }
                }
            }

            else if (Personality.fear > Personality.selfAssertion)
            {
                /*  Debug.Log("Miedo: " + Personality.fear);
                 * Debug.Log("Agresividad: " + Personality.selfAssertion);
                 * Debug.Log("Miedoso");*/
                if (target.tag == "IA" || target.tag == "player")
                {
                    GroupScript iagroup    = target.GetComponent <GroupScript>();
                    int         confidence = Personality.TrustInOthers[target.GetComponent <PersonalityBase>().GetMyOwnIndex()];
                    if (confidence > 5)
                    {
                        if (target.GetComponent <GroupScript>().checkIAInGroup(this.gameObject))
                        {
                            priority = 0;
                        }
                        else
                        {
                            if (iagroup.groupLeader == target && iagroup.inGroup)
                            {
                                priority = 1;
                            }
                            else if (!iagroup.inGroup)
                            {
                                priority = 0;
                            }
                            else
                            {
                                priority = -1;
                            }
                        }
                    }
                    else
                    {
                        priority = 0;
                    }
                }
                else
                {
                    if (target.name == "Shield")
                    {
                        priority = 2;
                    }
                    else if (target.name == "Axe")
                    {
                        if (Personality.selfAssertion > Personality.charisma)
                        {
                            priority = 2;
                        }
                        else
                        {
                            priority = 1;
                        }
                    }
                    else
                    {
                        priority = 1;
                    }
                }
            }
            else
            {
                /* Debug.Log("Miedo: " + Personality.fear);
                 * Debug.Log("Agresividad: " + Personality.selfAssertion);
                 * Debug.Log("Agresivo");*/
                if (target.tag == "IA" || target.tag == "player")
                {
                    GroupScript iagroup    = target.GetComponent <GroupScript>();
                    int         confidence = Personality.TrustInOthers[target.GetComponent <PersonalityBase>().GetMyOwnIndex()];
                    if (confidence > 5)
                    {
                        if (target.GetComponent <GroupScript>().checkIAInGroup(this.gameObject))
                        {
                            priority = 0;
                        }
                        else
                        {
                            if (iagroup.groupLeader == target && iagroup.inGroup)
                            {
                                if (Personality.charisma > Personality.fear)
                                {
                                    priority = 3;
                                }
                                else
                                {
                                    priority = 2;
                                }
                            }
                            else if (!iagroup.inGroup)
                            {
                                priority = 0;
                            }
                            else
                            {
                                priority = -1;
                            }
                        }
                    }
                    else
                    {
                        priority = 1;
                    }
                }
                else if (target.name == "Axe")
                {
                    priority = 3;
                }
                else if (Personality.fear > Personality.charisma)
                {
                    if (target.name == "Shield")
                    {
                        priority = 2;
                    }
                    else
                    {
                        priority = 1;
                    }
                }
                else
                {
                    if (target.name == "Boots")
                    {
                        priority = 2;
                    }
                    else
                    {
                        priority = 1;
                    }
                }
            }
        }
        //        Debug.Log("La prioridad es: " + priority);
        //Debug.Log("Soy : "+ this.gameObject.name+ " y veo a T : " + target + " y la prio es " +priority);

        return(priority);
    }
    public override void takeDamage(int damage, PersonalityBase personality)
    {
        health -= (int)(damage * defense);
        HealthImage.GetComponent <Image>().fillAmount = health / 100f;
        if (health <= 50 && health > 33)
        {
            HealthImage.GetComponent <Image>().color = new Color(255, 255, 0);
        }
        else if (health <= 33 && health > 0)
        {
            HealthImage.GetComponent <Image>().color = new Color(255, 0, 0);
        }
        else if (health <= 0)
        {
            if (personality.isMonster && !theThing)
            {
                theThing = true;

                HealthImage.GetComponent <Image>().color = new Color(0, 255, 0);

                controller.numberOfMonsters++;
                controller.decreaseHumans();
                Debug.Log("me mata un puto monstruo y me he convertido.\thumanos: " + controller.numberOfHumans + " monstruos: " + controller.numberOfMonsters);
            }
            else
            {
                if (theThing)
                {
                    controller.numberOfMonsters--;
                    if (controller.CheckPlayerWin())
                    {
                        //Debug.Log ("ha devuelto true en win");
                        controller.youWin(true);
                    }
                    else if (controller.CheckPlayerLost())
                    {
                        //Debug.Log ("ha devuelto true en lost");
                        controller.youWin(false);
                    }
                }

                else
                {
                    controller.decreaseHumans();
                }

                Debug.Log("humanos: " + controller.numberOfHumans + " monstruos: " + controller.numberOfMonsters + "muere " + this.name);

                this.GetComponent <VisibilityConeCycleIA>().enabled = false;
                VisibleElements.visibleGameObjects.Remove(this.gameObject);
                string  nameIAdeath     = this.name + "ghost";
                Vector3 IADeathPosition = this.transform.position;

                this.enabled = false;

                var mygroup = this.GetComponent <GroupScript>();

                if (mygroup.groupMembers.Count > 0)
                {
                    if (mygroup.IAmTheLeader)
                    {
                        var members = mygroup.groupMembers;
                        mygroup.ExitGroup();
                        foreach (var m in members)
                        {
                            GroupScript memberGroup = m.GetComponent <GroupScript>();
                            memberGroup.groupLeader = members[0];
                        }
                        members[0].GetComponent <GroupScript>().makeLeader();
                        members[0].GetComponent <PersonalityBase>().formacionGrupo(members[0], members[0].GetComponent <GroupScript>());
                    }
                    else
                    {
                        mygroup.ExitGroup();
                    }
                }

                var IAs = GameObject.FindGameObjectsWithTag("IA");

                foreach (var ia in IAs)
                {
                    var arbol = ia.GetComponent <DecisionTreeCreator>();
                    if (arbol != null)
                    {
                        if (arbol.target == this.gameObject)
                        {
                            Destroy(this.GetComponent <DecisionTreeCreator>());

                            ia.GetComponent <AIPersonality>().oldNodes = ia.GetComponents <DecisionTreeNode>();
                            foreach (var item in ia.GetComponent <AIPersonality>().oldNodes)
                            {
                                DestroyImmediate(item);
                            }
                        }
                    }
                }

                PlayerMenuController menu = controller.GetComponent <PlayerMenuController> ();
                menu.CloseAttackMenu();
                menu.menuConversation.SetActive(false);
                menu.CloseJoinMenu();
                menu.CloseObjectMenu();


                GameObject ghost = new GameObject();
                ghost.AddComponent <SpriteRenderer>();
                ghost.GetComponent <SpriteRenderer>().sprite           = ghostSprite;
                ghost.GetComponent <SpriteRenderer>().sortingLayerName = "Personajes";
                ghost.transform.localScale = new Vector2(5f, 5f);
                ghost.name = nameIAdeath;
                ghost.transform.position = IADeathPosition;


                Destroy(personality.gameObject.GetComponent <Pursue> ());

                this.gameObject.SetActive(false);
                Invoke("DestroyIA", 1f);
            }
        }
    }