예제 #1
0
    public Habits.Habit RandomHabit(Habits.Layer layer)
    {
        Habits.Habit        newHabit       = new Habits.Habit();
        List <Habits.Habit> matchingHabits = new List <Habits.Habit>();

        foreach (Habits.Habit eachHabit in Habits.habits)
        {
            // If this habit matches the randomly picked habit
            if (eachHabit.layer == layer)
            {
                //Debug.Log("randomizing list includes " + eachHabit.name);
                matchingHabits.Add(eachHabit);
            }
        }
        if (matchingHabits.Count <= 0)
        {
            Debug.LogWarning("No matching random habits found for that layer " + layer.ToString() + ".");
        }
        newHabit = matchingHabits[UnityEngine.Random.Range(0, matchingHabits.Count - 1)];

        return(newHabit);
    }
예제 #2
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;
    }