Beispiel #1
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);
        }
    }
Beispiel #2
0
    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);
    }