mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2026-01-19 14:08:22 +00:00
标准化 Inquiry 询问事件和钩子
This commit is contained in:
parent
310f672ed4
commit
d72ccb2dd3
@ -890,10 +890,9 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// 在角色取得询问反应的答复时触发
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="topic"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="response"></param>
|
||||
public virtual void OnCharacterInquiry(Character character, string topic, Dictionary<string, object> args, Dictionary<string, object> response)
|
||||
public virtual void OnCharacterInquiry(Character character, InquiryOptions options, InquiryResponse response)
|
||||
{
|
||||
|
||||
}
|
||||
@ -1206,12 +1205,11 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// 向角色发起询问反应事件 [ 尽可能的调用此方法而不是自己实现 ]
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="topic"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, object> Inquiry(Character character, string topic, Dictionary<string, object> args)
|
||||
public InquiryResponse Inquiry(Character character, InquiryOptions options)
|
||||
{
|
||||
return GamingQueue?.Inquiry(character, topic, args) ?? [];
|
||||
return GamingQueue?.Inquiry(character, options) ?? new(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -301,9 +301,8 @@ namespace Milimoe.FunGame.Core.Interface.Base
|
||||
/// 向角色(或控制该角色的玩家)进行询问并取得答复
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="topic"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, object> Inquiry(Character character, string topic, Dictionary<string, object> args);
|
||||
public InquiryResponse Inquiry(Character character, InquiryOptions options);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1107,4 +1107,15 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
||||
/// </summary>
|
||||
Sector
|
||||
}
|
||||
|
||||
public enum InquiryType
|
||||
{
|
||||
None,
|
||||
Choice,
|
||||
MultipleChoice,
|
||||
BinaryChoice,
|
||||
TextInput,
|
||||
NumberInput,
|
||||
Custom
|
||||
}
|
||||
}
|
||||
|
||||
@ -4059,21 +4059,20 @@ namespace Milimoe.FunGame.Core.Model
|
||||
/// 向角色(或控制该角色的玩家)进行询问并取得答复
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="topic"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, object> Inquiry(Character character, string topic, Dictionary<string, object> args)
|
||||
public InquiryResponse Inquiry(Character character, InquiryOptions options)
|
||||
{
|
||||
if (!_decisionPoints.TryGetValue(character, out DecisionPoints? dp) || dp is null)
|
||||
{
|
||||
dp = new();
|
||||
_decisionPoints[character] = dp;
|
||||
}
|
||||
Dictionary<string, object> response = OnCharacterInquiryEvent(character, dp, topic, args);
|
||||
InquiryResponse response = OnCharacterInquiryEvent(character, dp, options);
|
||||
Effect[] effects = [.. character.Effects.Where(e => e.IsInEffect)];
|
||||
foreach (Effect effect in effects)
|
||||
{
|
||||
effect.OnCharacterInquiry(character, topic, args, response);
|
||||
effect.OnCharacterInquiry(character, options, response);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@ -4597,7 +4596,7 @@ namespace Milimoe.FunGame.Core.Model
|
||||
CharacterDecisionCompletedEvent?.Invoke(this, actor, dp, record);
|
||||
}
|
||||
|
||||
public delegate Dictionary<string, object> CharacterInquiryEventHandler(GamingQueue character, Character actor, DecisionPoints dp, string topic, Dictionary<string, object> args);
|
||||
public delegate InquiryResponse CharacterInquiryEventHandler(GamingQueue character, Character actor, DecisionPoints dp, InquiryOptions options);
|
||||
/// <summary>
|
||||
/// 角色询问反应事件
|
||||
/// </summary>
|
||||
@ -4607,12 +4606,11 @@ namespace Milimoe.FunGame.Core.Model
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="dp"></param>
|
||||
/// <param name="topic"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
protected Dictionary<string, object> OnCharacterInquiryEvent(Character character, DecisionPoints dp, string topic, Dictionary<string, object> args)
|
||||
protected InquiryResponse OnCharacterInquiryEvent(Character character, DecisionPoints dp, InquiryOptions options)
|
||||
{
|
||||
return CharacterInquiryEvent?.Invoke(this, character, dp, topic, args) ?? [];
|
||||
return CharacterInquiryEvent?.Invoke(this, character, dp, options) ?? new(options);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
29
Model/InquiryOptions.cs
Normal file
29
Model/InquiryOptions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class InquiryOptions
|
||||
{
|
||||
public InquiryType InquiryType { get; } = InquiryType.None;
|
||||
public string Topic { get; set; } = "";
|
||||
public string Description { get; set; } = "";
|
||||
public Dictionary<string, string> Choices { get; set; } = [];
|
||||
public string DefaultChoice { get; set; } = "";
|
||||
public double MinNumberValue { get; set; } = 0;
|
||||
public double MaxNumberValue { get; set; } = 0;
|
||||
public double DefaultNumberValue { get; set; } = 0;
|
||||
public Dictionary<string, object> CustomArgs { get; set; } = [];
|
||||
|
||||
public InquiryOptions(InquiryType type, string topic)
|
||||
{
|
||||
InquiryType = type;
|
||||
Topic = topic;
|
||||
if (type == InquiryType.BinaryChoice)
|
||||
{
|
||||
Choices.Add("是", "");
|
||||
Choices.Add("否", "");
|
||||
DefaultChoice = "否";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Model/InquiryResponse.cs
Normal file
49
Model/InquiryResponse.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class InquiryResponse
|
||||
{
|
||||
public InquiryType InquiryType { get; } = InquiryType.None;
|
||||
public string Topic { get; set; } = "";
|
||||
public List<string> Choices { get; set; } = [];
|
||||
public string TextResult { get; set; } = "";
|
||||
public double NumberResult { get; set; } = 0;
|
||||
public Dictionary<string, object> CustomResponse { get; set; } = [];
|
||||
|
||||
public InquiryResponse(InquiryType type, string topic)
|
||||
{
|
||||
InquiryType = type;
|
||||
Topic = topic;
|
||||
}
|
||||
|
||||
public InquiryResponse(InquiryOptions options)
|
||||
{
|
||||
InquiryType = options.InquiryType;
|
||||
Topic = options.Topic;
|
||||
switch (options.InquiryType)
|
||||
{
|
||||
case InquiryType.Choice:
|
||||
case InquiryType.MultipleChoice:
|
||||
case InquiryType.BinaryChoice:
|
||||
if (options.DefaultChoice != "")
|
||||
{
|
||||
Choices.Add(options.DefaultChoice);
|
||||
}
|
||||
else if (options.Choices.Count > 0)
|
||||
{
|
||||
Choices.Add(options.Choices.Keys.First());
|
||||
}
|
||||
break;
|
||||
case InquiryType.TextInput:
|
||||
TextResult = "";
|
||||
break;
|
||||
case InquiryType.NumberInput:
|
||||
NumberResult = options.DefaultNumberValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user