Beispiel #1
0
        private void TriggerAlarm(DndAlarm alarm, Creature player = null, TurnSpecifier turnSpecifier = TurnSpecifier.None)
        {
            if (turnSpecifier != alarm.TurnSpecifier)
            {
                return;
            }

            if (Time == alarm.TriggerTime && alarm.TurnSpecifier != TurnSpecifier.None)
            {
                if (player != alarm.Creature)
                {
                    return;
                }
            }

            if (alarm.TriggerTime > Time)
            {
                Time = alarm.TriggerTime;                  // Update clock time to match alarm's time.
            }
            try
            {
                alarm.FireAlarm(this);
            }
            catch             //(Exception ex)
            {
                // TODO: Fire an OnException event handler....
            }
            alarmsToRemove.Add(alarm);
        }
Beispiel #2
0
        private void TriggerAlarm(DndAlarm alarm, Character player = null, RoundSpecifier roundSpecifier = RoundSpecifier.None)
        {
            if (roundSpecifier != alarm.RoundSpecifier)
            {
                return;
            }

            if (Time == alarm.TriggerTime && alarm.RoundSpecifier != RoundSpecifier.None)
            {
                if (player != alarm.Player)
                {
                    return;
                }
            }

            if (alarm.TriggerTime > Time)
            {
                Time = alarm.TriggerTime;                  // Update clock time to match alarm's time.
            }
            try
            {
                alarm.FireAlarm(this);
            }
            catch (Exception ex)
            {
                // TODO: Fire an OnException event handler....
            }
            alarmsToRemove.Add(alarm);
        }
Beispiel #3
0
        public DndAlarm GetAlarm(string alarmName)
        {
            DndAlarm first = alarms.FirstOrDefault(x => x.Name == alarmName);

            if (first != null)
            {
                return(first);
            }
            return(dailyAlarms.FirstOrDefault(x => x.Name == alarmName));
        }
Beispiel #4
0
        private void TriggerAlarm(DndAlarm alarm)
        {
            if (alarm.TriggerTime <= Time)
            {
                return;
            }

            Time = alarm.TriggerTime;
            alarm.FireAlarm(this);
            alarmsToRemove.Add(alarm);
        }
Beispiel #5
0
        public DndAlarm CreateAlarm(TimeSpan fromNow, string name, Character player = null, object data = null)
        {
            if (fromNow.TotalSeconds <= 0)
            {
                return(null);
            }

            DndAlarm dndAlarm = new DndAlarm(this, Time + fromNow, name, player, data);

            alarms.Add(dndAlarm);
            alarms.Sort((x, y) => x.TriggerTime.CompareTo(y.TriggerTime));
            return(dndAlarm);
        }
Beispiel #6
0
        public DndAlarm CreateAlarm(TimeSpan fromNow, string name)
        {
            if (fromNow.TotalSeconds <= 0)
            {
                return(null);
            }

            DndAlarm dndAlarm = new DndAlarm(this, Time + fromNow, name);

            alarms.Add(dndAlarm);
            alarms.Sort((x, y) => x.TriggerTime.CompareTo(y.TriggerTime));
            return(dndAlarm);
        }
Beispiel #7
0
        public DndAlarm CreateAlarm(TimeSpan fromNow, string name, Creature player = null, object data = null, int turnIndex = -1)
        {
            if (fromNow.TotalSeconds <= 0)
            {
                return(null);
            }

            DndAlarm dndAlarm = new DndAlarm(this, Time + fromNow, name, turnIndex, player, data);

            alarms.Add(dndAlarm);
            alarms = alarms.OrderBy(x => x.TriggerTime).ThenBy(x => x.TurnIndex).ToList();
            //alarms.Sort((x, y) => x.TriggerTime.CompareTo(y.TriggerTime));
            return(dndAlarm);
        }
Beispiel #8
0
        void TriggerAlarms(DateTime futureTime, int currentTurnIndex, Character player = null, TurnSpecifier turnSpecifier = TurnSpecifier.None)
        {
            triggeringAlarms = true;
            try
            {
                for (int i = 0; i < alarms.Count; i++)
                {
                    DndAlarm alarm = alarms[i];
                    if (alarm.TriggerTime > futureTime)
                    {
                        break;
                    }

                    if (futureTime - alarm.TriggerTime < TimeSpan.FromSeconds(6))
                    {
                        if (alarm.TurnIndex >= 0 && alarm.TurnIndex > currentTurnIndex)
                        {
                            break;
                        }
                    }

                    TriggerAlarm(alarm, player, turnSpecifier);
                }

                for (int i = 0; i < dailyAlarms.Count; i++)
                {
                    DndDailyAlarm dailyAlarm  = dailyAlarms[i];
                    int           daysFromNow = (futureTime - dailyAlarm.TriggerTime).Days;
                    if (daysFromNow != 0)
                    {
                        dailyAlarm.TriggerTime = dailyAlarm.TriggerTime.AddDays(daysFromNow);
                    }
                    if (dailyAlarm.TriggerTime > futureTime || dailyAlarm.DayOfYearLastTriggered == dailyAlarm.TriggerTime.DayOfYear)
                    {
                        break;
                    }
                    dailyAlarm.DayOfYearLastTriggered = dailyAlarm.TriggerTime.DayOfYear;
                    TriggerAlarm(dailyAlarm);
                }
            }
            finally
            {
                triggeringAlarms = false;
            }

            RemoveExpiredAlarms();
        }
Beispiel #9
0
        private void TriggerAlarm(DndAlarm alarm)
        {
            if (alarm.TriggerTime <= Time)
            {
                return;
            }

            Time = alarm.TriggerTime;
            try
            {
                alarm.FireAlarm(this);
            }
            catch (Exception ex)
            {
                // TODO: Fire an OnException event handler....
            }
            alarmsToRemove.Add(alarm);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 3);
            string timerName       = Expressions.GetStr(args[0], player, target, spell);
            int    durationSeconds = Expressions.GetInt(args[1], player, target, spell);
            string functionToCall  = Expressions.GetStr(args[2], player, target, spell);

            if (player == null)
            {
                return(null);
            }
            if (player.Game == null)
            {
                return(null);
            }
            DndAlarm dndAlarm = player.Game.Clock.CreateAlarm(TimeSpan.FromSeconds(durationSeconds), timerName, player, functionToCall);

            dndAlarm.AlarmFired += DndAlarm_AlarmFired;
            return(null);
        }
Beispiel #11
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature creature, Target target, CastedSpell spell, RollResults dice = null)
        {
            ExpectingArguments(args, 3);
            string timerName       = Expressions.GetStr(args[0], creature, target, spell);
            int    durationSeconds = Expressions.GetInt(args[1], creature, target, spell);
            string functionToCall  = Expressions.GetStr(args[2], creature, target, spell);

            if (creature == null)
            {
                return(null);
            }
            if (creature.Game == null)
            {
                return(null);
            }
            DndAlarm dndAlarm = creature.Game.Clock.CreateAlarm(TimeSpan.FromSeconds(durationSeconds), timerName, creature, functionToCall);

            dndAlarm.AlarmFired += DndAlarm_AlarmFired;
            return(null);
        }
Beispiel #12
0
        void TriggerAlarms(DateTime futureTime)
        {
            triggeringAlarms = true;
            try
            {
                for (int i = 0; i < alarms.Count; i++)
                {
                    DndAlarm alarm = alarms[i];
                    if (alarm.TriggerTime > futureTime)
                    {
                        break;
                    }

                    TriggerAlarm(alarm);
                }

                for (int i = 0; i < dailyAlarms.Count; i++)
                {
                    DndDailyAlarm dailyAlarm  = dailyAlarms[i];
                    int           daysFromNow = (futureTime - dailyAlarm.TriggerTime).Days;
                    if (daysFromNow != 0)
                    {
                        dailyAlarm.TriggerTime = dailyAlarm.TriggerTime.AddDays(daysFromNow);
                    }
                    if (dailyAlarm.TriggerTime > futureTime || dailyAlarm.DayOfYearLastTriggered == dailyAlarm.TriggerTime.DayOfYear)
                    {
                        break;
                    }
                    dailyAlarm.DayOfYearLastTriggered = dailyAlarm.TriggerTime.DayOfYear;
                    TriggerAlarm(dailyAlarm);
                }
            }
            finally
            {
                triggeringAlarms = false;
            }

            RemoveExpiredAlarms();
        }
 public DndTimeEventArgs(DndTimeClock timeClock, DndAlarm alarm)
 {
     TimeClock = timeClock;
     Alarm     = alarm;
 }