/// <summary> /// Open a NPC dialog box. /// </summary> /// <param name="player"></param> /// <param name="e"></param> private void OpenDialog(IPlayerEntity player, NpcDialogOpenEventArgs e) { var npcEntity = player.Context.FindEntity <INpcEntity>(e.NpcObjectId); if (npcEntity == null) { Logger.Error("DialogSystem: Cannot find NPC with id: {0}", e.NpcObjectId); return; } if (!npcEntity.Data.HasDialog) { Logger.Error("DialogSystem: NPC '{0}' doesn't have a dialog.", npcEntity.Object.Name); return; } string dialogText = npcEntity.Data.Dialog.IntroText; if (!string.IsNullOrEmpty(e.DialogKey)) { if (e.DialogKey == "BYE") { WorldPacketFactory.SendChatTo(npcEntity, player, npcEntity.Data.Dialog.ByeText); WorldPacketFactory.SendCloseDialog(player); return; } else { DialogLink dialogLink = npcEntity.Data.Dialog.Links?.FirstOrDefault(x => x.Id == e.DialogKey); if (dialogLink == null) { Logger.Error("DialogSystem: Cannot find dialog key: '{0}' for NPC '{1}'", e.DialogKey, npcEntity.Object.Name); return; } dialogText = dialogLink.Text; } } WorldPacketFactory.SendDialog(player, dialogText, npcEntity.Data.Dialog.Links); }
/// <summary> /// Update NPC oral text. /// </summary> /// <param name="npc">NPC Entity</param> private void UpdateOralText(INpcEntity npc) { if (npc.Timers.LastSpeakTime <= Time.TimeInSeconds()) { if (npc.Data != null && npc.Data.HasDialog && !string.IsNullOrEmpty(npc.Data.Dialog.OralText)) { IEnumerable <IPlayerEntity> playersArount = from x in npc.Object.Entities where x.Object.Position.IsInCircle(npc.Object.Position, OralTextRadius) && x is IPlayerEntity select x as IPlayerEntity; foreach (IPlayerEntity player in playersArount) { string text = npc.Data.Dialog.OralText.Replace(DialogVariables.PlayerNameText, player.Object.Name); WorldPacketFactory.SendChatTo(npc, player, text); } npc.Timers.LastSpeakTime = Time.TimeInSeconds() + RandomHelper.Random(10, 15); } } }