/// <summary> /// Sends a story communicator window to the <see cref="Player"/>. /// </summary> public void SendStoryCommunicator(uint textId, uint creatureId, Player player, uint durationMs = 10000, StoryPanelType storyPanelType = StoryPanelType.Default, WindowType windowTypeId = WindowType.LeftAligned, uint soundEventId = 0, byte priority = 0) { if (textId == 0) { throw new ArgumentOutOfRangeException(nameof(textId)); } var storyMessage = new StoryMessage { MsgId = textId }; storyMessage.AddCreature(creatureId); storyMessage.AddPlayer(player); player.Session.EnqueueMessageEncrypted(new ServerStoryCommunicatorShow { StoryMessage = storyMessage, SoundEventId = soundEventId > 0 ? soundEventId : creatureId, DurationMs = durationMs, StoryPanelType = storyPanelType, WindowTypeId = windowTypeId, Priority = priority }); }
} // 3 public void Write(GamePacketWriter writer) { StoryMessage.Write(writer); writer.Write(SoundEventId, 18u); writer.Write(DurationMs); writer.Write(WindowTypeId, 2u); writer.Write(StoryPanelType, 2u); writer.Write(Priority, 3u); }
/// <summary> /// Sends a story panel to the <see cref="Player"/> based on the provided <see cref="StoryPanelEntry"/>. /// </summary> public void SendStoryPanel(StoryPanelEntry entry, Player player) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } var storyMessage = new StoryMessage { MsgId = entry.Id, GeneralVoId = entry.SoundEventId }; storyMessage.AddPlayer(player); player.Session.EnqueueMessageEncrypted(new ServerStoryPanelHide()); player.Session.EnqueueMessageEncrypted(new ServerStoryPanelShow { StoryMessage = storyMessage }); }
public async void Simulate(string path) { _InterruptSimulation = false; //Get devices List <IoTDevice> iotDevices = await _iotDeviceHelper.GetAllInputDevices(); if (iotDevices == null || iotDevices.Count == 0) { ConsoleHelper.WriteWarning($"No devices found! Make sure to run '1. Setup list of devices' first."); _InterruptSimulation = true; return; } //Get story messages and validation List <StoryMessage> storyMessages = GetSimulationStory(path); if (storyMessages == null || storyMessages.Count == 0) { ConsoleHelper.WriteWarning($"No story message found! Choose a valid csv file."); _InterruptSimulation = true; return; } List <string> deviceIds = storyMessages.GroupBy(p => p.DeviceId).Select(p => p.Key).ToList(); if (deviceIds.Intersect(iotDevices.Select(p => p.DeviceId)).Count() != deviceIds.Count()) { ConsoleHelper.WriteWarning($"Some devices in the story aren't properly set in IoT Hub. Please run the sensors csv file."); _InterruptSimulation = true; return; } int elapsedTime = 0; IoTDevice device = null; StoryMessage storyLog = null; for (int i = 0; i < storyMessages.Count; i++) { StoryMessage storyMessage = storyMessages[i]; if (_InterruptSimulation) { return; } if (storyMessage.Timestamp - elapsedTime > 0) { await Task.Delay(storyMessage.Timestamp - elapsedTime); elapsedTime += storyMessage.Timestamp - elapsedTime; } if (_InterruptSimulation) { return; } device = iotDevices.Find(p => p.DeviceId == storyMessage.DeviceId); object messageObj = new ButtonSensorMessage(); if (device.DeviceType == "SoundSensor") { messageObj = new SoundSensorMessage() { Decibel = GetSoundMetadata() }; } await _iotDeviceHelper.SendMessage(device, storyMessage.EventType, messageObj); i++; int start = i > (SIMULATION_WINDOW_SIZE - 1) ? i - (SIMULATION_WINDOW_SIZE - 1) : 0; ConsoleHelper.ClearConsole(); ConsoleHelper.WriteInfo("Press Escape when you want to end the simulation."); ConsoleHelper.WriteInfo(""); ConsoleHelper.WriteHighlight($"{i} messages sent from {(deviceIds.Count)} demo device(s)."); ConsoleHelper.WriteInfo(""); ConsoleHelper.WriteInfo($"================================="); for (int j = start; j < start + SIMULATION_WINDOW_SIZE; j++) { storyLog = storyMessages[j]; if (j < i) { ConsoleHelper.WriteInfo($"--{storyLog.Timestamp}-{storyLog.DeviceId}"); } else if (j > i) { ConsoleHelper.WriteInfo($""); } else { ConsoleHelper.WriteHighlight($"--{storyLog.Timestamp}-{storyLog.DeviceId}"); } } ConsoleHelper.WriteInfo($"================================="); } ConsoleHelper.WriteInfo(""); ConsoleHelper.WriteHighlight("Done!"); await Task.Delay(5000); }
public async Task Notifications() { if (Request.Body.CanSeek) { Request.Body.Position = 0; } var input = await new StreamReader(Request.Body).ReadToEndAsync(); StoryMessage storyMessage = JsonConvert.DeserializeObject <StoryMessage>(input); if (storyMessage.TableId != 44) { return; } if (!(storyMessage.EventId == 1 || storyMessage.EventId == 2 || storyMessage.EventId == 3)) { return; } if (storyMessage.Data is JArray) { JArray messages = storyMessage.Data as JArray; if (messages == null) { throw new InvalidOperationException("Content error"); } List <Contact> contacts = messages.ToObject <List <Contact> >(); switch (storyMessage.EventId) { case 1: { await InsertContacts(contacts); return; } case 2: { await UpdateContacts(contacts); return; } case 3: { await DeleteContacts(contacts); return; } default: return; } } else if (storyMessage.Data is JObject) { JObject message = storyMessage.Data as JObject; if (message == null) { throw new InvalidOperationException("Content error"); } Contact contact = message.ToObject <Contact>(); switch (storyMessage.EventId) { case 1: { await InsertContact(contact); return; } case 2: { await UpdateContact(contact); return; } case 3: { await DeleteContact(contact); return; } default: return; } } }