# имя: 'State simulator 2' # описание: cимулятор событий # тип триггера: 'EgsScheduled' # создан: 2017.10.03 14:22:07, Сельченков Н.Ю. # изменен: '2019.02.23 15.00.46', Сельченков Н.Ю. # подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/State_simulator_2 use System.Random use System.Math use typedef ` ` as Settings const settings = Settings(trigger.settings) use ("acuario2.types." + settings.type) as ItemType from acuario2.types once next_time = settings.time_start ?? DateTime.MinValue let allowed_state(state as string) = from settings.states any state like it let simulate(param as Param) = let states = from param.EnumNames where it is allowed_state to array if states isnt empty then let state = states[Random().Next(0, states.Length)] let time = DateTime.Now if settings.time_start isnt null then time = next_time let gain = settings.time_gain ?? TimeSpan.Zero if (settings.time_stop isnt null) and (trigger.repeat > 0) then settings.time_gain = TimeSpan.FromTicks((settings.time_stop - settings.time_start).Ticks / trigger.repeat) end next_time = time + gain let ms = settings.time_yaw?.TotalMilliseconds as int ms = Random().Next(-ms, ms) let span = TimeSpan.FromMilliseconds(ms) next_time = if ms < 0 then next_time - span else next_time + span trigger.enabled = (settings.time_stop is null) or (next_time < settings.time_stop) end param.Set(state, null, time) end end from graph.Values of type Item where it is ItemType select it["state"] where it isnt null order by it.DateTime group by it.Owner.ServerId select (from it try first) where it isnt null do simulate(it) now