示例#1
0
 public GameTime(GameTime pGameTime)
 {
     days = pGameTime.days;
     hours = pGameTime.hours;
     minutes = pGameTime.hours;
     seconds = pGameTime.seconds;
 }
示例#2
0
 public void Tick()
 {
     GameTime gt = new GameTime(0f);
     gt.Tick(1f);
     Assert.AreEqual(1f, gt.totalSeconds);
     gt.Tick(1f);
     Assert.AreEqual(2f, gt.totalSeconds);
 }
示例#3
0
        void SecondsAddsUp(float pTotalSeconds, int pExpectedDays, int pExpectedHours, int pExpectedMinutes, float pExpectedSeconds)
        {
            GameTime gt = new GameTime(pTotalSeconds);

            Assert.AreEqual(gt.days, pExpectedDays);
            Assert.AreEqual(gt.hours, pExpectedHours);
            Assert.AreEqual(gt.minutes, pExpectedMinutes);
            Assert.AreEqual(gt.seconds, pExpectedSeconds, 0.05f);
        }
示例#4
0
 /// <summary>
 /// WARNING! Adding spans during runtime is not supported since they will not be saved in the database.
 /// This function is only used for testing.
 /// </summary>
 public void CreateTimetableSpanInternal(GameTime pStartTime, GameTime pEndTime, TimetableBehaviour pBehaviour)
 {
     TimetableSpan span = new TimetableSpan() {
         startTime = pStartTime,
         endTime = pEndTime,
         behaviour = pBehaviour
     };
     _timetableSpans.Add(span);
 }
示例#5
0
 public void Subtraction()
 {
     GameTime g1 = new GameTime(5, 4, 3, 2f);
     GameTime g2 = new GameTime(1, 1, 1, 1f);
     GameTime result = g1 - g2;
     Assert.AreEqual(4, result.days);
     Assert.AreEqual(3, result.hours);
     Assert.AreEqual(2, result.minutes);
     Assert.AreEqual(1f, result.seconds, 0.1f);
 }
示例#6
0
        public TimetableSpan GetCurrentSpan(GameTime pCurrentTime)
        {
            //return _timetableSpans.Find(span => span.IsTimeWithinBounds(pCurrentTime));

            foreach (var span in _timetableSpans) {
                if(span.IsTimeWithinBounds(pCurrentTime)) {
                    return span;
                }
            }

            return TimetableSpan.NULL;
        }
        public static void UpdateWorldUntilGameTime(World pWorld, GameTime pGameTime)
        {
            PreloadWorld(pWorld);

            const float stepSize = 1f;

            //Console.WriteLine("Total world time: " + pWorld.settings.gameTimeClock.totalSeconds);
            //Console.WriteLine("pGameTime.totalSeconds: " + pGameTime.totalSeconds);

            int i = 1000;

            while(pWorld.settings.gameTimeClock.totalSeconds < pGameTime.totalSeconds)
            {
                i--;
                //Console.WriteLine("Total world time: " + pWorld.settings.gameTimeClock.totalSeconds);
                pWorld.Update(stepSize);
            }
        }
示例#8
0
 public bool IsTimeWithinBounds(GameTime pTime)
 {
     //Console.WriteLine("Checking time table span " + startTime + " to " + endTime + " with pTime " + pTime);
     return pTime.IsWithinMinuteBounds(startTime, endTime);
 }
示例#9
0
        private TimetableSpan CreateTimetableSpan(int pStartHour, int pStartMinute, int pEndHour, int pEndMinute, string pName, string[] pTokens)
        {
            GameTime start = new GameTime(pStartHour, pStartMinute);
            GameTime end = new GameTime(pEndHour, pEndMinute);

            TimetableSpan span = new TimetableSpan();
            span.name = pName;
            span.startTime = start;
            span.endTime = end;
            span.behaviour = CreateBehaviourFromTokens(pTokens);

            //Console.WriteLine("Created span: " + span);

            return span;
        }
示例#10
0
        public void Update(float dt, GameTime pCurrentTime, Character pCharacter, MimanTingRunner pTingRunner, RoomRunner pRoomRunner, DialogueRunner pDialogueRunner, WorldSettings pWorldSettings)
        {
            TimetableSpan currentSpan = GetCurrentSpan(pCurrentTime);

            if(currentSpan != TimetableSpan.NULL) {

                if (pCharacter.isAvatar) {
                    return;
                }

                if(pCharacter.lastTimetableSpan != currentSpan) {
                    if(pCharacter.lastTimetableSpan != TimetableSpan.NULL) {
                        pCharacter.logger.Log(pCharacter.name + " ended span " + pCharacter.lastTimetableSpan.name);
                        pCharacter.lastTimetableSpan.behaviour.OnFinish(pCharacter, pTingRunner, pRoomRunner, pDialogueRunner);
                    } else {
                        pCharacter.logger.Log(pCharacter.name + " ended span NULL");
                    }
                }
                pCharacter.lastTimetableSpan = currentSpan;

                //pCharacter.logger.Log("Current timetable span to update: " + currentSpan.ToString());
                if(pCharacter.timetableTimer <= 0f) {
                    pCharacter.timetableTimer = currentSpan.behaviour.Execute(pCharacter, pTingRunner, pRoomRunner, pDialogueRunner, pWorldSettings);
                    //pCharacter.logger.Log(pCharacter.name + " executed " + currentSpan.behaviour + " and set timetableTimer to " + pCharacter.timetableTimer);
                } else {
                    pCharacter.timetableTimer -= dt;
                    //pCharacter.logger.Log(pCharacter.name + " timetableTimer = " + pCharacter.timetableTimer);
                }
            }
            else {
                D.Log("Found no matching time span in Timetable for character " + pCharacter.name + " at time " + pCurrentTime);
            }
        }
示例#11
0
        public void Sleep(GameTime pAlarmTime)
        {
            if(isAvatar) {
                D.Log("Sleep was called on avatar with alarm time: " + pAlarmTime);

                if(pAlarmTime.hours > 0 && pAlarmTime.hours < 8) {
                    pAlarmTime.hours = 8; // prevent avatar from waking up too early in the morning
                    pAlarmTime.minutes = Randomizer.GetIntValue(0, 60);
                    D.Log("Prevented avatar from waking up too early, set hours to " + pAlarmTime.hours);
                }
                else if(_tingRunner.gameClock.hours < 8 && pAlarmTime.hours > 11 && pAlarmTime.hours < 18) {
                    pAlarmTime.hours = Randomizer.GetIntValue(8, 11); // prevent avatar from waking up too late in the day
                    pAlarmTime.minutes = Randomizer.GetIntValue(0, 60);
                    D.Log("Prevented avatar from waking up too late, set hours to " + pAlarmTime.hours);
                }
            }

            //dialogueLine = "Zzzzz";
            alarmTime = pAlarmTime;
            #if LOG
            logger.Log(name + " fell asleep and will wake up at " + alarmTime);
            #endif
            StartAction("Sleeping", null, LONG_TIME, LONG_TIME);
            _dialogueRunner.EventHappened (name + "_fellAsleep");
        }
示例#12
0
 public GameTime Now()
 {
     GameTime n = new GameTime();
     n.days = this.days;
     n.hours = this.hours;
     n.minutes = this.minutes;
     n.seconds = this.seconds;
     return n;
 }
示例#13
0
        /// <summary>
        /// Ignores the day! Only checks hours and minutes.
        /// </summary>
        public bool IsWithinMinuteBounds(GameTime startTime, GameTime endTime)
        {
            GameTime startTimeIgnoreDay = new GameTime(startTime.hours, startTime.minutes);
            GameTime endTimeIgnoreDay = new GameTime(endTime.hours, endTime.minutes);
            GameTime thisTimeIgnoreDay = new GameTime(this.hours, this.minutes);

            if(startTimeIgnoreDay < endTimeIgnoreDay) {
                return  (startTimeIgnoreDay.totalSeconds <= thisTimeIgnoreDay.totalSeconds) &&
                        (thisTimeIgnoreDay.totalSeconds < endTimeIgnoreDay.totalSeconds);
            }
            else {
                // When the timespan wraps over midnight
                //Console.WriteLine("StartTime " + startTimeIgnoreDay.totalSeconds + " endTime " + endTimeIgnoreDay.totalSeconds + " thisTime " + thisTimeIgnoreDay.totalSeconds + " withinBounds " + withinBounds);
                bool inFirstHalf = thisTimeIgnoreDay.totalSeconds <= endTimeIgnoreDay.totalSeconds;
                bool inLastHalf = thisTimeIgnoreDay.totalSeconds >= startTimeIgnoreDay.totalSeconds;
                return inFirstHalf || inLastHalf;
            }
        }
示例#14
0
 public static GameTime operator -(GameTime g1, GameTime g2)
 {
     GameTime newTime = new GameTime();
     float s = g1.totalSeconds - g2.totalSeconds;
     newTime.totalSeconds = s;
     return newTime;
 }