void convertToMonster()
    {
        lastAttackValue = attack;
//		Debug.Log ("convirtiendome");
        attack = 20;
        GetComponent <AgentPositionController>().maxLinearVelocity = 150;
        GetComponent <SpriteRenderer>().sprite = playerMonsterStateImage;
        isMonster = true;

        GroupScript myGroup = this.GetComponent <GroupScript>();

        if (myGroup.groupMembers.Count > 1)
        {
            Debug.LogError("hay mas de uno");
        }
        else if (myGroup.groupMembers.Count > 0)
        {
            if (myGroup.IAmTheLeader)
            {
                myGroup.groupMembers [0].GetComponent <GroupScript> ().ExitGroup();
            }
            else
            {
                myGroup.ExitGroup();
            }
        }
    }
Exemple #2
0
    public override void DoAction()
    {
        base.visibiCone.IDecided = false;
        Reaction.spawnReaction(ResponseController.responseEnum.GROUP, ResponseController.responseEnum.OK, this.gameObject);
        // Debug.Log("me uno a tu grupo");

        //Debug.Log("mytarget es " + this.GetComponent<DecisionTreeCreator>().target);

        GameObject  t           = this.GetComponent <DecisionTreeCreator>().target;
        GroupScript myGroup     = this.GetComponent <GroupScript>();
        GroupScript leadergroup = t.GetComponent <GroupScript>();

        t = leadergroup.groupLeader;



        if (t.tag == "Player" && myGroup.IAmTheLeader == false && myGroup.groupLeader != this.gameObject)
        {
            myGroup.ExitGroup();
            myGroup.groupLeader  = t;
            myGroup.inGroup      = true;
            myGroup.IAmTheLeader = false;
            leadergroup.updateGroups(this.gameObject, myGroup.groupMembers);
            leadergroup.makeLeader();
            myGroup.groupMembers = new List <GameObject>();
            myGroup.groupMembers.AddRange(leadergroup.groupMembers);
            myGroup.groupMembers.Remove(this.gameObject);
            myGroup.addSingleMember(t);
            this.gameObject.GetComponent <SpriteRenderer>().color = leadergroup.getColor();
        }
        else
        {
            myGroup.groupLeader  = t;
            myGroup.inGroup      = true;
            myGroup.IAmTheLeader = false;
            leadergroup.updateGroups(this.gameObject, myGroup.groupMembers);
            leadergroup.makeLeader();
            myGroup.addSingleMember(t);

            leadergroup.resetMembersOfGroups(t.GetComponent <SpriteRenderer>());
        }

        if (this.gameObject.tag != "Player")
        {
            string[]     behaviours     = { "Pursue", "Leave", "AvoidWall", "Face" };
            float[]      weightedBehavs = { 0.8f, 0.1f, 1, 1 };
            GameObject   target         = this.GetComponent <DecisionTreeCreator>().target.GetComponent <GroupScript>().groupLeader;
            GameObject[] targets        = { target, target, target, target };
            GameObject.FindGameObjectWithTag("GameController").GetComponent <BehaviourAdder>().addBehavioursOver(this.gameObject, targets, behaviours, weightedBehavs);
            base.DestroyTrees();
        }
        t.GetComponent <PersonalityBase>().formacionGrupo(t, leadergroup);


        DecisionTreeNode[] oldNodes = this.gameObject.GetComponents <DecisionTreeNode>();
        foreach (DecisionTreeNode n in oldNodes)
        {
            DestroyImmediate(n);
        }
    }
Exemple #3
0
    public override void DoAction()
    {
        GameObject target;

        if (this.GetComponent <DecisionTreeCreator>() != null)
        {
            target = this.GetComponent <DecisionTreeCreator>().target;
        }
        else
        {
            target = targetAttack;
        }



        GroupScript myGroup = this.gameObject.GetComponent <GroupScript>();
        // GameObject target = this.GetComponent<DecisionTreeCreator>().target;
        GroupScript attackedGroup = target.gameObject.GetComponent <GroupScript>();;

        if (myGroup.groupLeader != attackedGroup.groupLeader && myGroup.inGroup)
        {
            myGroup.groupLeader.GetComponent <PersonalityBase>().formacionAtaque(target, myGroup.groupLeader.GetComponent <GroupScript>());
            Invoke("waitForAttack", 2f);
        }
        else
        {
//            Debug.Log("no tengo que formar ataco");
            waitForAttack();
        }
    }
    public void ExitGroup()
    {
        List <GameObject> members = groupLeader.GetComponent <GroupScript>().groupMembers;

        foreach (var m in members)
        {
            m.GetComponent <GroupScript>().groupMembers.Remove(this.gameObject);
        }
        GroupScript leaderGroup = groupLeader.GetComponent <GroupScript>();

        leaderGroup.groupMembers.Remove(this.gameObject);
        if (leaderGroup.groupMembers.Count == 0)
        {
            leaderGroup.groupLeader  = leaderGroup.gameObject;
            leaderGroup.inGroup      = false;
            leaderGroup.IAmTheLeader = false;
        }
        groupLeader = this.gameObject;
        inGroup     = false;
        groupMembers.Clear();
        this.gameObject.GetComponent <SpriteRenderer>().color = originalColor;

        if (this.gameObject.tag != "Player")
        {
            foreach (var comp in this.GetComponents <AgentBehaviour>())
            {
                DestroyImmediate(comp);
            }
            GetComponent <VisibilityConeCycleIA>().enabled = true;
        }
    }
    public override DecisionTreeNode GetBranch()
    {
        switch (actualDecisionenum)
        {
        case BoolDecisionEnum.ISMONSTER:
            if (valueDecision == personalityScript.isMonster)
            {
                return(nodeTrue);
            }
            break;

        case BoolDecisionEnum.INGROUP:
            groupScript = personalityScript.gameObject.GetComponent <GroupScript>();
            if (valueDecision == groupScript.inGroup)
            {
                return(nodeTrue);
            }
            break;

        case BoolDecisionEnum.IAMGROUPLEADER:
            groupScript = personalityScript.gameObject.GetComponent <GroupScript>();
            // Debug.Log("target es: " + personalityScript.gameObject.name+ "yo soy" + this.gameObject.name);

            if (groupScript.groupLeader == this.gameObject)     //check if the group leader is me
            {
                Debug.Log("soy el lider del grupo proceedo por nodo true " + personalityScript.gameObject.name);
                return(nodeTrue);
            }
            break;
        }

        return(nodeFalse);
    }
    public override void Action()
    {
        player      = GameObject.FindGameObjectWithTag("Player");
        playerPers  = player.GetComponent <PlayerPersonality>();
        playerGroup = player.GetComponent <GroupScript>();

        // Debug.Log("YES");

        targetIA = menuController.GetTargetIA();

        if (playerPers.interactionFromOtherCharacter == ActionsEnum.Actions.OFFER)
        {
            playerPers.myObject = targetIA.GetComponent <AIPersonality>().myObject;

            player.GetComponent <ObjectHandler> ().hasObject      = true;
            player.GetComponent <ObjectHandler>().currentObject   = targetIA.GetComponent <ObjectHandler>().currentObject;
            targetIA.GetComponent <AIPersonality>().myObject      = ObjectHandler.ObjectType.NONE;
            targetIA.GetComponent <ObjectHandler> ().hasObject    = false;
            targetIA.GetComponent <ObjectHandler>().currentObject = null;

            Debug.Log("player:he cogido tu objeto");
        }

        else if (playerPers.interactionFromOtherCharacter == ActionsEnum.Actions.JOIN)
        {
            //	playerGroup.addSingleMember (targetIA);
            //	targetIA.GetComponent<GroupScript> ().updateGroups (player);
            //Debug.Log("player:me uno a tu grupo bro");

            GroupScript myGroup     = playerPers.gameObject.GetComponent <GroupScript>();
            GroupScript leadergroup = targetIA.GetComponent <GroupScript>();
            //Debug.Log(targetIA);


            /*myGroup.groupLeader = targetIA ;
             * myGroup.inGroup = true;
             * myGroup.IAmTheLeader = false;
             * myGroup.groupMembers.Clear();
             * myGroup.groupMembers.AddRange(leadergroup.copyGroup());
             * myGroup.addSingleMember(targetIA);
             * leadergroup.updateGroups(playerPers.gameObject);
             * leadergroup.makeLeader();*/
            GameObject t = leadergroup.groupLeader;
            myGroup.groupLeader  = t;
            myGroup.inGroup      = true;
            myGroup.IAmTheLeader = false;
            leadergroup.updateGroups(myGroup.gameObject, myGroup.groupMembers);
            leadergroup.makeLeader();
            myGroup.addSingleMember(t);

            leadergroup.resetMembersOfGroups(t.GetComponent <SpriteRenderer>());
        }


        this.gameObject.transform.parent.gameObject.SetActive(false);
    }
Exemple #7
0
    private void waitForAttack()
    {
        Reaction.spawnReaction(ResponseController.responseEnum.ATTACK, ResponseController.responseEnum.ATTACK, this.gameObject);
        // Debug.Log("voy a atacar . Soy "+this.gameObject.name);


        GroupScript myGroup     = this.GetComponent <GroupScript>();
        int         totalAttack = 0;

        if (this.gameObject.tag == "Player")
        {
            totalAttack = this.GetComponent <PlayerPersonality>().attack;
        }
        else
        {
            totalAttack = this.GetComponent <AIPersonality>().attack;
        }


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

        Attack(totalAttack);
        //END ATTACK

        //GameObject target = this.GetComponent<DecisionTreeCreator>().target;
        GameObject leader = myGroup.groupLeader;

        leader.GetComponent <PersonalityBase>().formacionGrupo(leader, leader.GetComponent <GroupScript>());


        if (this != null && this.gameObject.tag != "Player")
        {
            GameObject target;
            if (this.GetComponent <DecisionTreeCreator> () != null)
            {
                target = this.GetComponent <DecisionTreeCreator>().target;
            }
            else
            {
                target = targetAttack;
            }
            base.DestroyTrees();
            if (target == null || target.GetComponent <PersonalityBase>().health > 0)
            {
                Invoke("EnableCone", 1f);
            }
        }
    }
 void Start()
 {
     controller            = GameObject.FindGameObjectWithTag("GameController").GetComponent <gameController>();
     numberOfIAs           = controller.GetComponent <gameController>().numberOfIAs;
     TrustInOthers         = new int[numberOfIAs];
     myMemory              = GetComponent <Memory>();
     base.behaviourManager = controller.GetComponent <BehaviourAdder>();
     // interactionFromOtherCharacter = ActionsEnum.Actions.ATTACK;
     initializeTrustInOthers(numberOfIAs);
     aiGroup = GetComponent <GroupScript> ();
     cone    = GetComponent <VisibilityConeCycleIA> ();
     playerNormalStateImage = gameObject.GetComponent <SpriteRenderer> ().sprite;
 }
Exemple #9
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
        }
    }
Exemple #10
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);
    }
Exemple #11
0
    public void openConversationMenu(GameObject character, GameObject targetIA)
    {
        GroupScript characterGroup = character.GetComponent <GroupScript>();
        GroupScript targetGroup    = targetIA.GetComponent <GroupScript>();

        if (targetIA.GetComponent <AIPersonality>().theThing)
        {
            menuController.OpenMenu(PlayerMenuController.MenuTypes.MENU_ATTACKED, targetIA);
        }
        else if (characterGroup.groupLeader == targetGroup.groupLeader || (characterGroup.groupMembers.Count + targetGroup.groupMembers.Count >= 3))
        {
            menuController.OpenMenu(PlayerMenuController.MenuTypes.MENU_CONVERSATION_WITH_MYGROUP, targetIA);
        }
        else
        {
            menuController.OpenMenu(PlayerMenuController.MenuTypes.MENU_CONVERSATION, targetIA);
        }
    }
Exemple #12
0
    public override void Action()
    {
        Debug.Log("attackAction");

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

        targetIA = menuController.GetTargetIA();
        GroupScript attackedGroup = targetIA.GetComponent <GroupScript>();;
        GroupScript myGroup       = player.GetComponent <GroupScript>();

        if (myGroup.groupLeader != attackedGroup.groupLeader && myGroup.inGroup)
        {
            myGroup.groupLeader.GetComponent <PersonalityBase>().formacionAtaque(targetIA, myGroup.groupLeader.GetComponent <GroupScript>());
            Invoke("waitForAttack", 3f);
        }
        else
        {
            waitForAttack();
        }

        this.gameObject.transform.parent.gameObject.SetActive(false);
    }
Exemple #13
0
 private void Awake()
 {
     name = GetComponent <SpriteRenderer>().sprite.name;
     manipulatorScript = Camera.main.GetComponent <ManipulatorScript>();
     cScript           = GameObject.Find("CoreManager").GetComponent <CoreScript>();
     gScript           = GetComponent <GroupScript>();
     gScript.inGroup   = true;
     if (!enabled)
     {
         return;
     }
     allies.Clear();
     alliesNames.Clear();
     allies.Add(gameObject);
     alliesNames.Add(name);
     collectedAllies.Add(name);
     collectedAlliesCurrent.Add(name);
     spawnPositions.Add(transform.position);
     //gScript.rb.bodyType = RigidbodyType2D.Static;
     block = true;
     Physics2D.autoSimulation = false;
 }
Exemple #14
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        //Falls Verbündet, dann gebe das Signal zu folgen
        GroupScript groupScript = other.GetComponent <GroupScript>();

        //wenn der Char der Gruppe schon angehört, dann ignorieren:
        if (groupScript.inGroup)
        {
            return;
        }

        //weiße den Char, dem gefolgt werden soll, zu:
        groupScript.groupNumber = PlayerScript.allies.Count;
        if (PlayerScript.allies.Count == 0)
        {
            groupScript.charToFollow = transform.parent.gameObject;
        }
        else
        {
            groupScript.charToFollow = PlayerScript.allies[PlayerScript.allies.Count - 1];
        }

        other.name = other.GetComponent <SpriteRenderer>().sprite.name;
        PlayerScript.allies.Add(other.gameObject);
        PlayerScript.alliesNames.Add(other.name);
        PlayerScript.collectedAlliesCurrent.Add(other.name);
        PlayerScript.spawnPositions.Add(other.transform.position);
        other.GetComponent <GroupScript>().properties = PlayerScript.allies[0].GetComponent <GroupScript>().properties;//shallow, mehr aber auch nicht vonöten

        //Überschreibe wert mit defaultwert:
        DefaultStats.SetDefaultCharValueByName(other.name);

        //folge dem Char:
        groupScript.inGroup = true;
        groupScript.bottom  = true;
        return;
    }
    public void formacionAtaque(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));
        }
    }
    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);
            }
        }
    }
    /// <summary>
    /// Hebt die Einheiten hervor, schiebt sie anschließend zusammen und löscht sie danach
    /// </summary>
    /// <param name="obj"></param>
    /// <param name="endPos"></param>
    /// <returns></returns>
    IEnumerator Merge(int index, Vector2 endPos, float idPos)
    {
        GameObject obj = allies[index];

        //Schritt 1: Auffächern:
        int     steps     = 60;
        Vector3 realPos   = obj.transform.position;
        Vector3 posStep   = (endPos + new Vector2(idPos, 1) - (Vector2)obj.transform.position) / steps;
        Vector3 angleStep = -obj.transform.eulerAngles / steps;

        float b = -steps / 2f;
        float a = -4f / (steps * steps);
        float factor;

        for (int i = 0; i <= steps; i++)
        {
            realPos += posStep;

            factor = a * (i + b) * (i + b) + 1;
            obj.transform.position     = realPos + Vector3.up * factor;
            obj.transform.eulerAngles += angleStep;

            yield return(new WaitForEndOfFrame());

            if (stop)
            {
                yield break;
            }
        }

        yield return(new WaitForSeconds(1));

        if (stop)
        {
            yield break;
        }

        //Schritt 2: Zusammenziehen:
        steps   = 30;
        posStep = new Vector3(-idPos / steps, 0);
        Color colorStep = new Color(0, 0, 0, -0.01f);

        for (int i = 0; i < steps; i++)
        {
            obj.transform.position += posStep;
            obj.GetComponent <SpriteRenderer>().color += colorStep;
            yield return(new WaitForEndOfFrame());

            if (stop)
            {
                yield break;
            }
        }

        allies.RemoveAt(index);
        alliesNames.RemoveAt(index);
        if (index == 0)
        {
            GroupScript gScript = allies[0].GetComponent <GroupScript>();
            gScript.tag = "Player";
            gScript.gameObject.layer = 18;//mainGhost
            gScript.charToFollow     = null;
            gScript.inGroup          = false;
            gScript.rb.bodyType      = RigidbodyType2D.Static;
            gScript.rb.constraints   = RigidbodyConstraints2D.FreezeRotation;
        }

        Destroy(obj);
        yield break;
    }
    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);
    }
Exemple #19
0
    private void FollowByList()
    {
        rb.bodyType      = RigidbodyType2D.Kinematic;
        rb.constraints   = RigidbodyConstraints2D.FreezeAll;
        gameObject.layer = 16;//DefaultOnly

        if (moveCount >= 0)
        {
            moveCount--; return;
        }

        //bei nähe nicht bewegen
        GroupScript gScript = charToFollow.GetComponent <GroupScript>();

        if (Mathf.Abs((transform.position - charToFollow.transform.position).magnitude) < 0.5f * (moving ? 1.75f : 2) && bottom)
        {
            moving = false; transform.localScale = Vector2.one * properties.size; return;
        }
        //Debug.Log(name + ": " + bottom);

        if (gScript.pastPositions.Count == 0)
        {
            return;
        }
        TransformSaved t;// = gScript.pastPositions[0];

        if (moving)
        {
            t = gScript.pastPositions[0];
        }
        else//restart
        {
            //suche ersten wert, dessen position zwischen char und charToFollow liegt
            moveCount = 0;
            foreach (TransformSaved position in gScript.pastPositions)
            {
                Vector2 diff_1 = charToFollow.transform.position - transform.position;
                Vector2 diff_2 = position.position - (Vector2)transform.position;
                //wenn               abstand zwischen charToFollow und char      größer als         abstand zwischen pastPosition und char       dann break
                if (diff_1.magnitude > diff_2.magnitude &&
                    Mathf.Sign(diff_1.x) == Mathf.Sign(diff_2.x) &&
                    Mathf.Sign(diff_1.y) == Mathf.Sign(diff_2.y))
                {
                    break;
                }
                moveCount++;
            }

            if (moveCount > 0)
            {
                moveCount--; return;
            }
            //Debug.Log(name + " restarts at: " + moveCount);
            t = gScript.pastPositions[moveCount];
        }

        transform.position   = t.position;
        transform.rotation   = t.rotation;
        transform.localScale = t.scale;
        moving = true;
    }
 protected void Start()
 {
     menuController = GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayerMenuController>();
     playerGroup    = this.GetComponent <GroupScript>();
 }
Exemple #21
0
 void Awake()
 {
     instance = this;
 }
    /// <summary>
    /// Positioniert die Einheiten bei "gegeben" neu und ordnet die zu folgenden Einheiten neu zu. Zudem aktualisiert diese Methode die Allies-Listen
    /// </summary>
    private void RepositionUnits(GameObject unit, bool moveAnim = true)
    {
        Debug.Log("positioniere neu.");

        List <GameObject> objects = PlayerScript.allies;
        List <string>     names   = PlayerScript.alliesNames;
        int ptr = objects.IndexOf(unit);

        if (ptr < 0)//Hinzufügen:
        {
            objects.Add(unit);
            names.Add(unit.name);


            GroupScript gScript = unit.GetComponent <GroupScript>();
            gScript.groupNumber = objects.Count - 1;
            gScript.inGroup     = true;
            if (objects.Count > 1)
            {
                gScript.charToFollow = objects[objects.Count - 2];
                unit.GetComponent <PlayerScript>().enabled = false;
                gScript.enabled = true;
                unit.layer      = 16;//defaultOnly
            }
            else
            {
                unit.GetComponent <PlayerScript>().enabled = true;
                gScript.enabled = false;
                unit.layer      = 8;//character
            }
        }
        else//Abziehen:
        {
            if (objects.Count == 1)
            {
                objects.RemoveAt(0); names.Clear(); return;
            }

            if (ptr == 0)//Einheit, die vom Spieler gesteuert wird
            {
                objects[0].GetComponent <PlayerScript>().enabled = false;
                objects[0].GetComponent <GroupScript>().enabled  = true;
                objects[0].layer = 16;//defaultOnly
                objects[1].GetComponent <PlayerScript>().enabled = true;
                objects[1].GetComponent <GroupScript>().enabled  = false;
                objects[1].layer = 8;//character
                pScript          = objects[1].GetComponent <PlayerScript>();
            }

            objects.RemoveAt(ptr);
            for (int i = ptr; i < objects.Count; i++)
            {
                objects[i].GetComponent <GroupScript>().groupNumber--;
                if (i > 0)
                {
                    objects[i].GetComponent <GroupScript>().charToFollow = objects[i - 1];
                }
            }
        }

        names.Clear();
        int count = 0;

        foreach (GameObject obj in objects)
        {
            names.Add(obj.name);
            //Bewege Einheiten zu der neuen Position:
            if (!moveAnim ||
                (ptr >= 0 && count < ptr) ||//wegnehmen
                (ptr < 0 && count < objects.Count - 1)) //anhängen
            {
                count++;
                continue;
            }
            obj.GetComponent <GroupScript>().MoveToNewPosition(transform);
        }
    }
    IEnumerator RunSchummelScript(int ptr)
    {
        Debug.Log("Starte SchummelScript");
        int        steps = 30;
        Color      stepColor;
        GameObject obj;

        SchummelScript.SchummelEvent sEvent;
        GroupScript gScript = allies[0].GetComponent <GroupScript>();

        while (ptr < sEvents.Count)
        {
            sEvent = sEvents[ptr];

            gScript.rb.bodyType = RigidbodyType2D.Static;
            if (ptr > 0)
            {
                if (sScript.events[ptr].eventType != SchummelScript.EventType.add &&
                    sScript.events[ptr].eventType != SchummelScript.EventType.move)
                {
                    gScript.rb.velocity = Vector2.zero;
                }
            }

            //Warte auf Trigger:
            switch (sEvent.trigger)
            {
            case SchummelScript.TriggerType.none:

                break;

            case SchummelScript.TriggerType.time:
                if (sEvent.triggerTime > 0)
                {
                    yield return(new WaitForSeconds(sEvent.triggerTime));
                }
                break;
            }
            if (stop)
            {
                yield break;
            }


            //Ausführung der Aktion:
            MovementScript mScript;
            bool           goRight, changeObj;
            int            arrayPos;
            Debug.Log("active Event: " + sEvent.title);
            switch (sEvent.eventType)
            {
            case SchummelScript.EventType.spawn:
                //spawne ein SpielObjekt in der Geisterwelt:
                Debug.Log("Spawn Object");
                obj       = Resources.Load <GameObject>("Prefabs/Objects/" + sEvent.focus[0]);
                obj       = Instantiate(obj, sEvent.endPosition, Quaternion.identity);
                obj.layer = 19;    //Geisterobjekt
                obj.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0);
                activeObjects.Add(obj);
                Debug.Log(obj);

                StartCoroutine(FadeIn(obj));
                yield return(new WaitForSeconds(3));

                break;



            case SchummelScript.EventType.despawn:
                //despawne ein Objekt in der Geisterwelt
                if (!int.TryParse(sEvent.focus[0], out arrayPos))
                {
                    break;
                }
                obj = activeObjects[arrayPos];

                steps     = 30;
                stepColor = new Color(0, 0, 0, -0.01f);
                for (int i = 0; i < steps; i++)
                {
                    obj.GetComponent <SpriteRenderer>().color += stepColor;
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }
                activeObjects.RemoveAt(arrayPos);
                Destroy(obj);
                break;



            case SchummelScript.EventType.wait:
                //Warte auf Event (noch nicht implementiert)

                break;



            case SchummelScript.EventType.add:
                //füge Einheit zur Gruppe hinzu, wie move, bloß mit gespawnter Einheit

                //spawne Einheit:
                obj = Resources.Load <GameObject>("Units/" + sEvent.focus[0]);
                obj = Instantiate(obj, sEvent.endPosition, Quaternion.identity);
                obj.transform.GetChild(2).gameObject.layer = 17;    //Ghost-Layer für Trigger
                allies.Add(obj);
                alliesNames.Add(obj.GetComponent <SpriteRenderer>().sprite.name);
                obj.tag   = "Ghost";
                obj.layer = 18;                                                    //mainGhost, bleibt auf Boden stehen
                obj.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0); //unsichtbar
                StartCoroutine(FadeIn(obj));

                //move zur Einheit:
                gScript.rb.bodyType = RigidbodyType2D.Dynamic;
                goRight             = (sEvent.endPosition - (Vector2)gScript.transform.position).x > 0;
                while (((sEvent.endPosition - (Vector2)gScript.transform.position).x > 0) == goRight)
                {
                    gScript.ExecuteInput(!goRight, goRight, false, gScript.properties);
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                //Einheit hinzufügen:
                obj.GetComponent <GroupScript>().charToFollow = allies[allies.Count - 2];
                obj.GetComponent <GroupScript>().inGroup      = true;
                obj.layer = 17;    //Ghost
                break;



            case SchummelScript.EventType.combine:
                //vereinige Einheiten zu einer neuen Einheit

                //Einheiten die vereinigt werden sollen springen hoch, treffen sich in der Luft und werden gelöscht:
                int   count  = 0;
                float number = sEvent.focus.Length;
                foreach (string unitName in sEvent.focus)
                {
                    if (count++ == 0)
                    {
                        continue;
                    }

                    StartCoroutine(Merge(alliesNames.IndexOf(unitName), sEvent.endPosition, (count / number - 0.5f) * 3));
                }
                yield return(new WaitForSeconds(2f));

                if (stop)
                {
                    yield break;
                }

                //spawne Einheit:
                obj = Resources.Load <GameObject>("Units/" + sEvent.focus[0]);
                obj = Instantiate(obj, sEvent.endPosition + Vector2.up, Quaternion.identity);
                obj.transform.GetChild(2).gameObject.layer = 17;    //Ghost-Layer für Trigger
                allies.Add(obj);
                alliesNames.Add(obj.GetComponent <SpriteRenderer>().sprite.name);
                obj.tag   = "Ghost";
                obj.layer = 17;                                                    //Ghost
                obj.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static;
                obj.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0); //unsichtbar
                obj.GetComponent <GroupScript>().enabled  = false;

                //Erscheinen:
                steps     = 30;
                stepColor = new Color(0, 0, 0, 0.01f);
                for (int i = 0; i < steps; i++)
                {
                    obj.GetComponent <SpriteRenderer>().color += stepColor;
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                //Auf Boden Gleiten
                steps = 30;
                Vector3 stepPos = ((Vector3)sEvent.endPosition - obj.transform.position) / steps;
                for (int i = 0; i < steps; i++)
                {
                    obj.transform.position += stepPos;
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                //Einheit hinzufügen:
                obj.GetComponent <GroupScript>().enabled      = true;
                obj.GetComponent <GroupScript>().charToFollow = allies[allies.Count - 2];
                obj.GetComponent <GroupScript>().inGroup      = true;
                break;



            case SchummelScript.EventType.move:
                //bewege Einheiten (ohne zu springen)
                gScript.rb.bodyType = RigidbodyType2D.Dynamic;
                goRight             = (sEvent.endPosition - (Vector2)allies[0].transform.position).x > 0;
                while (((sEvent.endPosition - (Vector2)allies[0].transform.position).x > 0) == goRight)
                {
                    Debug.Log("moving");
                    gScript.ExecuteInput(!goRight, goRight, false, gScript.properties);
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }
                break;



            case SchummelScript.EventType.jump:
                //bewege Einheiten mit Springanimation über eine Dauer von ValueSet

                if (!gScript)
                {
                    yield break;
                }
                gScript.enabled = false;    //gScript updates squish (scale) -> deactivation

                steps = 30;
                Vector3 realPos   = gScript.transform.position;
                Vector3 realScale = Vector2.one * gScript.properties.size;
                Vector3 posStep   = (sEvent.endPosition - (Vector2)gScript.transform.position) / sEvent.valueSet;
                Vector3 angleStep = -gScript.transform.eulerAngles / steps;

                float b = -steps / 2f;
                float a = -8f / (steps * steps);
                float factor;

                for (int i = 0; i <= steps; i++)
                {
                    realPos += posStep;

                    factor = a * (i + b) * (i + b) + 2;
                    gScript.transform.position     = realPos + Vector3.up * factor;
                    gScript.transform.localScale   = realScale + (Vector3) new Vector2(-0.1f, 0.05f) * factor;
                    gScript.transform.eulerAngles += angleStep;

                    gScript.UpdatePastPos();
                    yield return(new WaitForEndOfFrame());

                    if (stop)
                    {
                        yield break;
                    }
                }

                gScript.enabled = true;
                break;



            case SchummelScript.EventType.set_Mass:
                changeObj = int.TryParse(sEvent.focus[0], out arrayPos);
                obj       = changeObj ? activeObjects[arrayPos] : gScript.gameObject;
                mScript   = obj.GetComponent <MovementScript>();

                mScript.rb.mass = sEvent.valueSet;
                break;



            case SchummelScript.EventType.set_Size:

                changeObj = int.TryParse(sEvent.focus[0], out arrayPos);
                obj       = changeObj ? activeObjects[arrayPos] : gScript.gameObject;
                mScript   = obj.GetComponent <MovementScript>();

                float diff = sEvent.valueSet - obj.transform.localScale.x;
                obj.transform.localScale = Vector2.one * sEvent.valueSet;
                mScript.properties.size  = obj.transform.localScale.x;

                obj.transform.position += Vector3.up * diff / 2;
                break;



            case SchummelScript.EventType.change_mass:

                break;



            case SchummelScript.EventType.change_size:

                changeObj = int.TryParse(sEvent.focus[0], out arrayPos);
                obj       = changeObj ? activeObjects[arrayPos] : gScript.gameObject;
                mScript   = obj.GetComponent <MovementScript>();

                bool add = sEvent.valueSet > gScript.properties.size;
                while (Mathf.Abs(sEvent.valueSet - mScript.properties.size) > 0.15f)
                {
                    //Debug.Log(Mathf.Abs(sEvent.valueSet - gScript.properties.size));
                    yield return(new WaitForSeconds(0.5f));

                    if (stop)
                    {
                        yield break;
                    }

                    obj = activeObjects[arrayPos];
                    obj.transform.localScale += (Vector3)Vector2.one * (add ? 0.1f : -0.1f);
                    obj.GetComponent <ObjectScript>().properties.size = obj.transform.localScale.x;

                    obj.transform.position += Vector3.up * (add ? 0.05f : -0.05f);
                }
                yield return(new WaitForSeconds(0.5f));

                break;


            case SchummelScript.EventType.change_vel:

                break;


            case SchummelScript.EventType.change_puls:

                break;


            case SchummelScript.EventType.change_force:

                break;


            case SchummelScript.EventType.change_energy:

                break;
            }

            ptr++;
        }

        //despawne Einheiten
        steps     = 100;
        stepColor = new Color(0, 0, 0, -0.01f);
        for (int i = 0; i < steps; i++)
        {
            foreach (GameObject unit in allies)
            {
                unit.GetComponent <SpriteRenderer>().color += stepColor;
            }
            yield return(new WaitForEndOfFrame());

            if (stop)
            {
                yield break;
            }
        }
        foreach (GameObject unit in allies)
        {
            Destroy(unit);
        }
        foreach (GameObject active_obj in activeObjects)
        {
            Destroy(active_obj);
        }
        stop = true;
        GetComponent <CoreScript>().SetPeeking(false);
        yield break;
    }