public BotServiceTests() { _dbContextMock = new Mock <ChatNpgSQLContext>(); _botRepositoryMock = new Mock <IBotRepository>(); Profile myProfile = new ChatProfile(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(myProfile))); _service = new BotService(_dbContextMock.Object, _botRepositoryMock.Object, mapper); }
public DialogServiceTests() { _dbContextMock = new Mock <ChatNpgSQLContext>(); _dialogRepositoryMock = new Mock <IDialogRepository>(); _chatEventRepositoryMock = new Mock <IChatEventRepository>(); _botNotifierMock = new Mock <IBotNotifier>(); Profile myProfile = new ChatProfile(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(myProfile))); _service = new DialogService(_dbContextMock.Object, _dialogRepositoryMock.Object, mapper, _chatEventRepositoryMock.Object, _botNotifierMock.Object); }
private void Descriptions_FormClosing(object sender, FormClosingEventArgs e) { int i = 1; String newName = textBoxProfile.Text; ChatProfile curProfile = _settings.chatProfiles.Profiles.FirstOrDefault(p => p.Name.Equals(_settings.currentProfile)); if (curProfile == null) { return; } while (_settings.chatProfiles.Profiles.Any(p => !curProfile.Equals(p) && p.Name.Equals(newName, StringComparison.CurrentCultureIgnoreCase))) { newName = String.Format("{0} #{1}", textBoxProfile.Text, i++); } curProfile.Name = newName; _settings.currentProfile = newName; }
public void BroadcastRequest(ChatProfile chat) { string message = ""; string sound = ""; string avatar = ""; var broadcastType = BroadcastType.None; if (chat.ProcessChat(ref message, ref sound, ref broadcastType, ref avatar) == false) { Logger.MsgDebug(chat.ProfileSubtypeId + ": Process Chat Fail", DebugTypeEnum.Chat); return; } if (this.LastChatMessageSent == message || string.IsNullOrWhiteSpace(message) == true) { Logger.MsgDebug(chat.ProfileSubtypeId + ": Last Message Same", DebugTypeEnum.Chat); return; } if (chat.IgnoreAntennaRequirement || chat.SendToAllOnlinePlayers) { this.HighestRadius = chat.IgnoredAntennaRangeOverride; this.HighestAntennaRangeName = ""; this.AntennaCoords = this.RemoteControl.GetPosition(); } else { GetHighestAntennaRange(); if (this.HighestRadius == 0) { Logger.MsgDebug(chat.ProfileSubtypeId + ": No Valid Antenna", DebugTypeEnum.Chat); return; } } var playerList = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(playerList); Logger.MsgDebug(chat.ProfileSubtypeId + ": Sending Chat to all Players within distance: " + this.HighestRadius.ToString(), DebugTypeEnum.Chat); if (message.Contains("{AntennaName}")) { message = message.Replace("{AntennaName}", this.HighestAntennaRangeName); } if (this.RemoteControl?.SlimBlock?.CubeGrid?.CustomName != null && message.Contains("{GridName}")) { message = message.Replace("{GridName}", this.RemoteControl.SlimBlock.CubeGrid.CustomName); } if (chat.UseRandomNameGeneratorFromMES && MESApi.MESApiReady) { message = MESApi.ConvertRandomNamePatterns(message); } var authorName = chat.Author; if (authorName.Contains("{AntennaName}")) { authorName = authorName.Replace("{AntennaName}", this.HighestAntennaRangeName); } if (this.RemoteControl?.SlimBlock?.CubeGrid?.CustomName != null && authorName.Contains("{GridName}")) { authorName = authorName.Replace("{GridName}", this.RemoteControl.SlimBlock.CubeGrid.CustomName); } bool sentToAll = false; foreach (var player in playerList) { var playerId = chat.SendToAllOnlinePlayers ? 0 : player.IdentityId; var playerName = chat.SendToAllOnlinePlayers ? "Player" : player.DisplayName; if (!chat.SendToAllOnlinePlayers && (player.IsBot == true || player.Character == null)) { continue; } if (!chat.SendToAllOnlinePlayers && (Vector3D.Distance(player.GetPosition(), this.AntennaCoords) > this.HighestRadius)) { continue; //player too far } var modifiedMsg = message; if (modifiedMsg.Contains("{PlayerName}") == true) { modifiedMsg = modifiedMsg.Replace("{PlayerName}", playerName); } if (modifiedMsg.Contains("{PlayerFactionName}") == true) { var playerFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(player.IdentityId); if (playerFaction != null) { modifiedMsg = modifiedMsg.Replace("{PlayerFactionName}", playerFaction.Name); } else { modifiedMsg = modifiedMsg.Replace("{PlayerFactionName}", "Unaffiliated"); } } var authorColor = chat.Color; if (authorColor != "White" && authorColor != "Red" && authorColor != "Green" && authorColor != "Blue") { authorColor = "White"; } if (!sentToAll) { if (broadcastType == BroadcastType.Chat || broadcastType == BroadcastType.Both) { MyVisualScriptLogicProvider.SendChatMessage(modifiedMsg, authorName, playerId, authorColor); } if (broadcastType == BroadcastType.Notify || broadcastType == BroadcastType.Both) { if (playerId == 0) { MyVisualScriptLogicProvider.ShowNotificationToAll(modifiedMsg, 6000, authorColor); } else { MyVisualScriptLogicProvider.ShowNotification(modifiedMsg, 6000, authorColor, playerId); } } } if (string.IsNullOrWhiteSpace(sound) == false && sound != "None") { var effect = new Effects(); effect.Mode = EffectSyncMode.PlayerSound; effect.SoundId = sound; effect.AvatarId = avatar; var sync = new SyncContainer(effect); SyncManager.SendSyncMesage(sync, player.SteamUserId); } if (playerId == 0) { sentToAll = true; } } }
public static void Setup() { var definitionList = MyDefinitionManager.Static.GetEntityComponentDefinitions(); //Get All Chat, Spawner foreach (var def in definitionList) { try { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Chat]") == true && ChatObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var chatObject = new ChatProfile(); chatObject.InitTags(def.DescriptionText); chatObject.ProfileSubtypeId = def.Id.SubtypeName; var chatBytes = MyAPIGateway.Utilities.SerializeToBinary <ChatProfile>(chatObject); //Logger.WriteLog("Chat Profile Added: " + def.Id.SubtypeName); ChatObjectTemplates.Add(def.Id.SubtypeName, chatBytes); continue; } if (def.DescriptionText.Contains("[RivalAI Spawn]") == true && SpawnerObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var spawnerObject = new SpawnProfile(); spawnerObject.InitTags(def.DescriptionText); spawnerObject.ProfileSubtypeId = def.Id.SubtypeName; var spawnerBytes = MyAPIGateway.Utilities.SerializeToBinary <SpawnProfile>(spawnerObject); //Logger.WriteLog("Spawner Profile Added: " + def.Id.SubtypeName); SpawnerObjectTemplates.Add(def.Id.SubtypeName, spawnerBytes); continue; } } catch (Exception) { Logger.MsgDebug(string.Format("Caught Error While Processing Definition {0}", def.Id)); } } foreach (var def in definitionList) { try { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Action]") == true && ActionObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var actionObject = new ActionProfile(); actionObject.InitTags(def.DescriptionText); actionObject.ProfileSubtypeId = def.Id.SubtypeName; var targetBytes = MyAPIGateway.Utilities.SerializeToBinary <ActionProfile>(actionObject); //Logger.WriteLog("Action Profile Added: " + def.Id.SubtypeName); ActionObjectTemplates.Add(def.Id.SubtypeName, targetBytes); continue; } if (def.DescriptionText.Contains("[RivalAI Condition]") == true && ChatObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var conditionObject = new ConditionProfile(); conditionObject.InitTags(def.DescriptionText); conditionObject.ProfileSubtypeId = def.Id.SubtypeName; var conditionBytes = MyAPIGateway.Utilities.SerializeToBinary <ConditionProfile>(conditionObject); //Logger.WriteLog("Condition Profile Added: " + def.Id.SubtypeName); ConditionObjectTemplates.Add(def.Id.SubtypeName, conditionBytes); continue; } if (def.DescriptionText.Contains("[RivalAI Target]") == true && TargetObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var targetObject = new TargetProfile(); targetObject.InitTags(def.DescriptionText); targetObject.ProfileSubtypeId = def.Id.SubtypeName; var targetBytes = MyAPIGateway.Utilities.SerializeToBinary <TargetProfile>(targetObject); //Logger.WriteLog("Target Profile Added: " + def.Id.SubtypeName); TargetObjectTemplates.Add(def.Id.SubtypeName, targetBytes); continue; } } catch (Exception e) { Logger.WriteLog(string.Format("Caught Error While Processing Definition {0}", def.Id)); Logger.WriteLog(e.ToString()); } } //Get All Triggers - Build With Action, Chat and Spawner foreach (var def in definitionList) { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Trigger]") == true && TriggerObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var triggerObject = new TriggerProfile(); triggerObject.InitTags(def.DescriptionText); triggerObject.ProfileSubtypeId = def.Id.SubtypeName; var triggerBytes = MyAPIGateway.Utilities.SerializeToBinary <TriggerProfile>(triggerObject); //Logger.WriteLog("Trigger Profile Added: " + def.Id.SubtypeName); TriggerObjectTemplates.Add(def.Id.SubtypeName, triggerBytes); continue; } } //Get All TriggerGroups, Autopilot foreach (var def in definitionList) { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Autopilot]") == true && AutopilotObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var autopilotObject = new AutoPilotProfile(); autopilotObject.InitTags(def.DescriptionText); autopilotObject.ProfileSubtypeId = def.Id.SubtypeName; var autopilotBytes = MyAPIGateway.Utilities.SerializeToBinary <AutoPilotProfile>(autopilotObject); //Logger.WriteLog("Trigger Profile Added: " + def.Id.SubtypeName); AutopilotObjectTemplates.Add(def.Id.SubtypeName, autopilotBytes); continue; } if (def.DescriptionText.Contains("[RivalAI TriggerGroup]") == true && TriggerObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var triggerObject = new TriggerGroupProfile(); triggerObject.InitTags(def.DescriptionText); triggerObject.ProfileSubtypeId = def.Id.SubtypeName; var triggerBytes = MyAPIGateway.Utilities.SerializeToBinary <TriggerGroupProfile>(triggerObject); //Logger.WriteLog("Trigger Profile Added: " + def.Id.SubtypeName); TriggerGroupObjectTemplates.Add(def.Id.SubtypeName, triggerBytes); continue; } } //Get All Behavior foreach (var def in definitionList) { if (string.IsNullOrWhiteSpace(def.DescriptionText)) { continue; } if ((def.DescriptionText.Contains("[RivalAI Behavior]") || def.DescriptionText.Contains("[Rival AI Behavior]")) && BehaviorTemplates.ContainsKey(def.Id.SubtypeName) == false) { BehaviorTemplates.Add(def.Id.SubtypeName, def.DescriptionText); continue; } } //Print Profile Names To Log: BuildKeyListAndWriteToLog("Behavior", BehaviorTemplates.Keys); BuildKeyListAndWriteToLog("Autopilot", AutopilotObjectTemplates.Keys); BuildKeyListAndWriteToLog("Trigger", TriggerObjectTemplates.Keys); BuildKeyListAndWriteToLog("TriggerGroup", TriggerGroupObjectTemplates.Keys); BuildKeyListAndWriteToLog("Condition", ConditionObjectTemplates.Keys); BuildKeyListAndWriteToLog("Action", ActionObjectTemplates.Keys); BuildKeyListAndWriteToLog("Chat", ChatObjectTemplates.Keys); BuildKeyListAndWriteToLog("Spawn", SpawnerObjectTemplates.Keys); BuildKeyListAndWriteToLog("Target", TargetObjectTemplates.Keys); }