Exemplo n.º 1
0
    public void Click()
    {
        GameObject  playerGO     = GameObject.FindGameObjectWithTag("Player");
        MaslowMeter playerMaslow = playerGO.GetComponentInChildren <MaslowMeter>();

        if (clickToIncrease)
        {
            value += gainPerClick;
        }
        // If we click another maslow's habit to get it
        if (!maslow.isPlayer)
        {
            //then influence player
            playerMaslow.InfluenceMaslow(maslow, layer, maslow.happy, maslow.safety, maslow.safety);
        }
        // else we clicked the player's habits to influence our interactingWith partner
        else
        {
            if (maslow.interactingWith != null)
            {
                //Debug.Log("Interacting with " + maslow.interactingWith.happy);
                // If we clicked ourselves, we try to influence the other person we are meeting with.
                maslow.interactingWith.InfluenceMaslow(playerMaslow, layer, playerMaslow.happy, playerMaslow.safety, playerMaslow.safety);
            }
            else
            {
                //Debug.Log("Not interacting with anyone to send to.");
            }
        }
    }
Exemplo n.º 2
0
    private void OnTriggerEnter(Collider other)
    {
        if (tag == "Judge" && other.tag == "House")
        {
            vote = VoteForEarth();
            // Judges don't influence others, only the city hall
            var npc = GetComponent <NPCWithBoxes>();
            UnityEngine.Assertions.Assert.IsNotNull(npc);
            npc.Vote(vote);
            //Debug.Log("JUDGED!");
            return;
        }
        else if (other.tag == "Villager" || other.tag == "Judge" || other.tag == "PlayerBubble")
        {
            MaslowMeter otherMaslow = GetMaslowMeter(other.gameObject);
            if (other.tag == "Player")
            {
                //showTriangleDuration = showTriangleLength;
                ActivateTriangleUI(this);
            }
            if (tag == "Player" && otherMaslow != null)
            {
                //otherMaslow.showTriangleDuration = showTriangleLength;
                ActivateTriangleUI(otherMaslow);
            }
            if (otherMaslow != null)
            {
                interactingWith             = otherMaslow;
                otherMaslow.interactingWith = this;
                RestoreInteractingWithColor();
            }
            // If this is someone we haven't exchanged with before, we could meet with them
            if (!peopleThisPersonInfluenced.Contains(other.transform.parent))
            {
                if (departing || meeting)
                {
                    // TODO: What happens if you're already meeting or departing, like a "sorry not now" eye roll face?
                    // TODO: To avoid bulldozing, turn around and go opposite way
                    Depart(otherMaslow);
                }
                else
                {
                    Meet(otherMaslow);
                }
                peopleThisPersonInfluenced.Add(other.transform.parent);
                //Debug.Log( gameObject.name + "Influenced " + other.gameObject.name );

                //MaslowMeter otherMeter = other.gameObject.transform.parent.GetComponent<MaslowMeter>();
                //UnityEngine.Assertions.Assert.IsNotNull( otherMeter );
                //otherMeter.InfluenceMaslow( this, this.happy, safety, health );
                // TODO: Influence should happen during the meeting instead
            }
            // If not, just depart
            else
            {
                //Depart(GetMaslowMeter(other.gameObject));
            }
        }
    }
Exemplo n.º 3
0
 public void Departed(MaslowMeter departed)
 {
     meeting   = false;
     departing = true;
     // TODO: Look away from whoever you're departing
     characterMove.move.speed = originalSpeed;
     departTime = Time.time;
 }
Exemplo n.º 4
0
    private void UpdateMeetings()
    {
        if (interactingWith != null && highestLayer > interactingWith.highestLayer && (isPlayer || interactingWith.isPlayer))
        {
            blinkingLayer = interactingWith.highestLayer + 1;
            goodBlinking  = true;
            if (Time.time - goodBlinkLast > goodBlinkSpeed)
            {
                goodBlinkLast = Time.time;
                if (needs[blinkingLayer].ui.background.color == needs[highestLayer].color)
                {
                    needs[blinkingLayer].ui.background.color = blinkColorGood;
                }
                else
                {
                    needs[highestLayer].ui.background.color = needs[highestLayer].color;
                }
            }
        }
        else
        {
            goodBlinking = false;
        }

        if (interactingWith != null)
        {
            Vector3 delta    = interactingWith.transform.position - transform.position;
            Vector3 midpoint = transform.position + delta / 2;
            if (interactingWith.interactingWith != this)
            {
                //NS.Lines.MakeArrow(ref meeting_line, transform.position, midpoint, Color.red);
                if (meeting_line != null)
                {
                    meeting_line.SetActive(false);
                }
                RestoreInteractingWithColor();

                interactingWith = null;
                meeting         = false;
            }
            else
            {
                NS.Lines.MakeArrow(ref meeting_line, transform.position, midpoint, Color.black);
                meeting_line.SetActive(true);
                showTriangleDuration = showTriangleLength;
            }
        }
        if (meeting && Time.time - meetTime > meetLength)
        {
            Depart(interactingWith);
        }
        if (departing && Time.time - departTime > departLength)
        {
            departing = false;
        }
    }
Exemplo n.º 5
0
    public MaslowMeter GetMaslowMeter(GameObject other)
    {
        MaslowMeter mm = other.GetComponent <MaslowMeter>();

        if (mm == null)
        {
            mm = other.transform.parent.GetComponent <MaslowMeter>();
        }
        if (mm == null)
        {
            Debug.Log("CAN'T FIND MASLOWMETER FOR " + other);
        }
        return(mm);
    }
Exemplo n.º 6
0
    public void Met(MaslowMeter meeter)
    {
        // TODO: Look at whoever you met
        meeting   = true;
        departing = false;
        //       characterMove.move.speed = 0.05f;
//        RestoreInteractingWithColor();
        //interactingWith = meeter;
        //if (meeter.tag == "Player")
        //{
        //	triangle.SetShow(NeedsTriangle.Show.aboveHead);
        //}
        meetTime = Time.time;
    }
Exemplo n.º 7
0
    public void Meet(MaslowMeter metMaslow)
    {
        // TODO: Look at whoever you met
        meeting   = true;
        departing = false;
//        RestoreInteractingWithColor();
        //interactingWith = metMaslow;
        //if (metMaslow.tag == "Player")
        //{
        //	//Debug.LogError(name + " met Player "+triangle.triangleShow+" "+triangle.transform.parent.parent.parent);
        //}
//		characterMove.move.speed = 0.05f;
        metMaslow.Met(this);
        meetTime   = Time.time;
        meetLength = 5f + UnityEngine.Random.Range(0f, 5f);
    }
Exemplo n.º 8
0
 public void ConnectButtonsToNeeds()
 {
     if (triangleLayers == null || triangleLayers.Length == 0)
     {
         triangleLayers = GetComponentsInChildren <NeedUI>();
     }
     if (maslow == null)
     {
         Debug.LogError(transform.root.name + " does not have Maslow set");
         Transform t = transform;
         while (t != null)
         {
             Debug.Log(t.name);
             maslow = t.gameObject.GetComponent <MaslowMeter>();
             if (maslow != null)
             {
                 Debug.Log("found a MaslowMeter!");
                 break;
             }
             t = t.parent;
         }
     }
     if (maslow.needs.Length > triangleLayers.Length)
     {
         throw new System.Exception("need at least " + maslow.needs.Length + " layers in the pyramid");
     }
     for (int i = 0; i < maslow.needs.Length; ++i)
     {
         maslow.needs[i].Use(triangleLayers[i], i != 0? maslow.needs[i - 1] : null);
     }
     System.Array.ForEach(
         maslow.needs, (need) => {
         need.ui.button.onClick.AddListener(
             () =>
         {
             //Debug.Log("clicked " + need.name);
             need.Click();
         }
             );
     }
         );
 }
Exemplo n.º 9
0
 private static void ActivateTriangleUI(MaslowMeter mm)
 {
     mm.triangle.SetShow(NeedsTriangle.Show.aboveHead);
     mm.showTriangleDuration = showTriangleLength;
 }
Exemplo n.º 10
0
    public void InfluenceMaslow(MaslowMeter influencer, Habits.Layer influenceLayer, float phappy, float psafety, float pfood)
    {
        if (phappy > 0)
        {
            Noisy.PlaySound("Mood Increased");
        }
        else if (phappy < 0)
        {
            Noisy.PlaySound("Mood Decreased");
        }

        // Assign the persons interacting with each other to facilitate animation during exchange
        influencer.RestoreInteractingWithColor();

        influencer.interactingWith = this;
        if (interactingWith != null)
        {
            interactingWith.RestoreInteractingWithColor();
        }

        interactingWith = influencer;

        Need receivedNeed   = needs[(int)influenceLayer];
        Need influencerNeed = influencer.needs[(int)influenceLayer];

        if ((int)influencerNeed.layer <= highestLayer + 1)
        {
            if (influencerNeed.habitPrimary != null)
            {
                // If we have no primary, get us started at max
                if (receivedNeed.habitPrimary == null)
                {
                    //Debug.Log("isPlayer:"+isPlayer);
                    //Debug.Log("highestLayer:"  + highestLayer);
                    highestLayer++;
                    happy += 2f;
                    interactingWith.happy += 2f;
                    //Debug.Log("highestLayer:"  + highestLayer);

                    // TODO: Make a way to share someone's secondary needs with yourself, otehrwise just always ask for their primary.
                    receivedNeed.habitPrimary      = influencerNeed.habitPrimary;
                    receivedNeed.habitPrimaryValue = MaslowMeter.maxHabitValue;
                    if (highestLayer + 1 == (int)receivedNeed.layer)
                    {
                        //highestLayer ++;
                    }
                }
                // otherwise check if its the primary we already have being boosted to max again
                else if (receivedNeed.habitPrimary.name != influencerNeed.habitPrimary.name)
                {
                    receivedNeed.habitSecondary    = influencerNeed.habitPrimary;
                    receivedNeed.habitPrimaryValue = MaslowMeter.maxHabitValue;
                }
                // or its our first secondary
                else if (receivedNeed.habitSecondary == null)
                {
                    receivedNeed.habitSecondary       = influencerNeed.habitPrimary;
                    receivedNeed.habitPrimaryValue   -= secondaryInfluenceAmount;
                    receivedNeed.habitSecondaryValue += secondaryInfluenceAmount;
                }
                // or a secondary we do have
                else if (receivedNeed.habitSecondary.name == influencerNeed.name)
                {
                    receivedNeed.habitSecondary    = influencerNeed.habitPrimary;
                    receivedNeed.habitPrimaryValue = MaslowMeter.maxHabitValue;
                }
                // or a secondary different from ours replaces our secondary
                else if (receivedNeed.habitSecondary.name != influencerNeed.habitPrimary.name)
                {
                    receivedNeed.habitSecondary       = influencerNeed.habitPrimary;
                    receivedNeed.habitPrimaryValue   -= secondaryInfluenceAmount;
                    receivedNeed.habitSecondaryValue += secondaryInfluenceAmount;
                }
                // or nothing is there to gain
                else
                {
                    UnityEngine.Debug.Log("Nothing to gain.");
                }
            }
            receivedNeed.Use(receivedNeed.ui, receivedNeed);

            // If our secondary beat our primary, bin the old and in with the new
            if (secondaryInfluenceAmount >= maxHabitValue)
            {
                receivedNeed.habitOld            = receivedNeed.habitPrimary;
                receivedNeed.habitPrimary        = receivedNeed.habitSecondary;
                receivedNeed.habitPrimaryValue   = maxHabitValue;
                receivedNeed.habitSecondaryValue = minHabitValue;
            }

            // else
            else
            {
            }

            /*
             * // Right now influence is always +/- 1 or 0
             * if ( Math.Abs( phappy ) >= 5 ) {
             *  happy += phappy / Math.Abs( phappy );
             *  happy = Mathf.Clamp( happy, -10, 10 );
             * }
             *
             * if ( Math.Abs( psafety ) >= 5 ) {
             *  safety += psafety / Math.Abs( psafety );
             *  safety = Mathf.Clamp( safety, -10, 10 );
             * }
             *
             * if ( Math.Abs( pfood ) >= 5 ) {
             *  health += pfood / Math.Abs( pfood );
             *  health = Mathf.Clamp( health, -10, 10 );
             * }*/
        } // end if not higher than next higher layer
        dirty = true;
    }