mirror of
https://github.com/waynebian01/Shigure.git
synced 2026-09-03 07:15:24 +08:00
98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
namespace Shigure;
|
|
|
|
public sealed record LogicDecision(
|
|
string? Hotkey,
|
|
string Step,
|
|
IReadOnlyDictionary<string, object?> UnitInfo,
|
|
string? ModuleName = null,
|
|
int DelayMs = 0,
|
|
string? RateLimitKey = null,
|
|
int LogicDelayMs = 0);
|
|
|
|
public interface IClassLogic
|
|
{
|
|
LogicDecision Run(GameState state, string? specName);
|
|
}
|
|
|
|
public sealed class LogicRegistry
|
|
{
|
|
private readonly Dictionary<int, IClassLogic> _logicByClass = new();
|
|
private readonly IClassLogic _defaultLogic;
|
|
private readonly KeymapService _keymap;
|
|
private readonly ModuleStore _moduleStore;
|
|
private readonly string? _selectedModuleId;
|
|
|
|
public LogicRegistry(KeymapService keymap, ModuleStore moduleStore, string? selectedModuleId)
|
|
{
|
|
_keymap = keymap;
|
|
_moduleStore = moduleStore;
|
|
_selectedModuleId = string.IsNullOrWhiteSpace(selectedModuleId) ? null : selectedModuleId.Trim();
|
|
_defaultLogic = new DefaultClassLogic(keymap);
|
|
}
|
|
|
|
public LogicDecision Run(int? classId, int? specId, string? specName, GameState state)
|
|
{
|
|
var module = FindModule(classId, specId, state);
|
|
if (module is not null)
|
|
{
|
|
return ModuleLogic.Run(module, state, _keymap);
|
|
}
|
|
|
|
if (classId is not null && _logicByClass.TryGetValue(classId.Value, out var logic))
|
|
{
|
|
return logic.Run(state, specName);
|
|
}
|
|
|
|
return _defaultLogic.Run(state, specName);
|
|
}
|
|
|
|
public string? ResolveDynamicState(int? classId, int? specId, GameState state)
|
|
{
|
|
var module = FindModule(classId, specId, state);
|
|
if (module is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
ModuleLogic.ResolveDynamicFields(module, state);
|
|
return module.Name;
|
|
}
|
|
|
|
private ModuleDefinition? FindModule(int? classId, int? specId, GameState state)
|
|
{
|
|
return _moduleStore.FindSelectedOrBestMatch(
|
|
_selectedModuleId,
|
|
classId,
|
|
specId,
|
|
state.GetInt("队伍类型"),
|
|
state.GetInt("英雄天赋"));
|
|
}
|
|
}
|
|
|
|
public sealed class DefaultClassLogic : IClassLogic
|
|
{
|
|
private readonly KeymapService _keymap;
|
|
|
|
public DefaultClassLogic(KeymapService keymap)
|
|
{
|
|
_keymap = keymap;
|
|
}
|
|
|
|
public LogicDecision Run(GameState state, string? specName)
|
|
{
|
|
var oneKeyAssist = state.GetInt("一键辅助");
|
|
if (oneKeyAssist == 10)
|
|
{
|
|
var hotkey = _keymap.GetHotkey(0, "一键辅助");
|
|
if (!string.IsNullOrWhiteSpace(hotkey))
|
|
{
|
|
return new LogicDecision(hotkey, "施放 一键辅助", EmptyInfo);
|
|
}
|
|
}
|
|
|
|
return new LogicDecision(null, "C# 职业逻辑尚未迁移", EmptyInfo);
|
|
}
|
|
|
|
private static readonly IReadOnlyDictionary<string, object?> EmptyInfo = new Dictionary<string, object?>();
|
|
}
|