mirror of
https://github.com/waynebian01/Shigure.git
synced 2026-09-03 07:15:24 +08:00
- Removed the UnitSelector class from UI and added a new UnitSelector class in Modules. - Introduced RuntimeSessionCoordinator to manage runtime sessions, ensuring safe concurrent operations. - Created ShigureRuntimeFactory to handle the creation of ShigureRuntime instances. - Added WindowsTriggerKeyState and WindowsVirtualKeyMap for handling key states and virtual key mappings. - Implemented IKeymapResolver interface for key mapping resolution. - Established runtime dependencies with interfaces for screen scanning, state building, logic evaluation, and key output.
96 lines
2.9 KiB
C#
96 lines
2.9 KiB
C#
namespace Shigure;
|
|
|
|
public interface IClassLogic
|
|
{
|
|
LogicDecision Run(GameState state, string? specName);
|
|
}
|
|
|
|
public sealed class LogicRegistry : IRuntimeLogic
|
|
{
|
|
private readonly Dictionary<int, IClassLogic> _logicByClass;
|
|
private readonly IClassLogic _defaultLogic;
|
|
private readonly IKeymapResolver _keymap;
|
|
private readonly ModuleStore _moduleStore;
|
|
private readonly string? _selectedModuleId;
|
|
|
|
public LogicRegistry(
|
|
IKeymapResolver keymap,
|
|
ModuleStore moduleStore,
|
|
string? selectedModuleId,
|
|
IEnumerable<KeyValuePair<int, IClassLogic>>? classLogics = null)
|
|
{
|
|
_keymap = keymap;
|
|
_moduleStore = moduleStore;
|
|
_selectedModuleId = string.IsNullOrWhiteSpace(selectedModuleId) ? null : selectedModuleId.Trim();
|
|
_defaultLogic = new DefaultClassLogic(keymap);
|
|
_logicByClass = classLogics?.ToDictionary(pair => pair.Key, pair => pair.Value) ?? new();
|
|
}
|
|
|
|
public LogicEvaluation Evaluate(
|
|
int? classId,
|
|
int? specId,
|
|
string? specName,
|
|
GameState state,
|
|
bool runLogic)
|
|
{
|
|
_keymap.SelectForClass(classId, specId);
|
|
var module = FindModule(classId, specId, state);
|
|
if (module is not null)
|
|
{
|
|
ModuleLogic.ResolveDynamicFields(module, state);
|
|
return new LogicEvaluation(
|
|
module.Name,
|
|
runLogic ? ModuleLogic.Run(module, state, _keymap) : null);
|
|
}
|
|
|
|
if (!runLogic)
|
|
{
|
|
return new LogicEvaluation(null, null);
|
|
}
|
|
|
|
if (classId is not null && _logicByClass.TryGetValue(classId.Value, out var logic))
|
|
{
|
|
return new LogicEvaluation(null, logic.Run(state, specName));
|
|
}
|
|
|
|
return new LogicEvaluation(null, _defaultLogic.Run(state, specName));
|
|
}
|
|
|
|
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 IKeymapResolver _keymap;
|
|
|
|
public DefaultClassLogic(IKeymapResolver 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?>();
|
|
}
|