예제 #1
0
        public void Tick(VMAvatar avatar, VMContext context)
        {
            var roomScore = context.GetRoomScore(context.GetRoomAt(avatar.Position));

            avatar.SetMotiveData(VMMotive.Room, roomScore);
            var minutes = context.Clock.Minutes;

            if (minutes / 2 == LastMinute || avatar.GetValue(VMStackObjectVariable.Hidden) > 0)
            {
                return;
            }
            var hours = context.Clock.Hours;

            LastMinute = minutes / 2;
            var sleeping = (avatar.GetMotiveData(VMMotive.SleepState) != 0);
            int moodSum  = 0;

            for (int i = 0; i < 7; i++)
            {
                int frac = 0;
                var dm   = DecrementMotives[i];
                if (avatar.HasMotiveChange(dm) && dm != VMMotive.Energy)
                {
                    continue;
                }
                var motive   = avatar.GetMotiveData(dm);
                var r_Hunger = ToFixed1000(Constants[5]) * (100 + avatar.GetMotiveData(VMMotive.Hunger));
                switch (i)
                {
                case 0:
                    frac = r_Hunger; break;

                case 1:
                    var active = avatar.GetPersonData(VMPersonDataVariable.ActivePersonality);
                    if (active > 666)
                    {
                        frac = ToFixed1000(Constants[14]);
                    }
                    else if (active < 666)
                    {
                        frac = ToFixed1000(Constants[15]);
                    }
                    else
                    {
                        frac = ToFixed1000(Constants[16]);
                    }
                    break;

                case 2:
                    frac = ToFixed1000(Constants[sleeping ? 11 : 10]); break;

                case 3:
                    frac = ToFixed1000(Constants[sleeping ? 13 : 12]) + FracMul(r_Hunger, ToFixed1000(Constants[4])); break;

                case 4:
                    //try to wake the sim up if they're asleep on the wake hour, and they're well rested.
                    if (sleeping && hours == Constants[2] && motive >= Constants[0] - 100)
                    {
                        avatar.SetMotiveData(VMMotive.SleepState, 0);
                    }

                    if (sleeping)
                    {
                        if (avatar.GetMotiveData(VMMotive.SleepState) == -1)
                        {
                            frac = -643 * 2;
                        }
                        else
                        {
                            frac = (context.Clock.Hours >= Constants[2]) ? ToFixed1000(Constants[3]) : 0;
                        }
                    }
                    else
                    {
                        frac = (ToFixed1000(Constants[0]) / (30 * (int)Constants[1]));
                    }
                    //energy span over wake hours. small energy drift applied if asleep during the day.

                    break;

                case 5:
                    frac = (sleeping)?0:ToFixed1000(Constants[8]);
                    break;

                case 6:
                    frac = ToFixed1000(Constants[6]) +
                           ToFixed1000(Constants[7]) * avatar.GetPersonData(VMPersonDataVariable.OutgoingPersonality);
                    break;
                }

                MotiveFractions[i] += (short)frac;
                if (MotiveFractions[i] >= 1000)
                {
                    motive             -= (short)(MotiveFractions[i] / 1000);
                    MotiveFractions[i] %= 1000;
                    if (motive < -100)
                    {
                        motive = -100;
                    }
                    avatar.SetMotiveData(DecrementMotives[i], motive);
                }
                if (MotiveFractions[i] < 0)
                {
                    motive             += (short)(1 - MotiveFractions[i] / 1000);
                    MotiveFractions[i] += (short)((1 - MotiveFractions[i] / 1000) * 1000);
                    avatar.SetMotiveData(DecrementMotives[i], motive);
                }
                moodSum += motive;
            }
            moodSum += roomScore;

            avatar.SetMotiveData(VMMotive.Mood, (short)(moodSum / 8));
        }