整合SLSUtilities
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cielonos.MainGame.Characters;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,130 +9,41 @@ namespace Cielonos.MainGame.Inventory
|
||||
{
|
||||
public partial class ComboSubmodule : SubmoduleBase<ItemBase>
|
||||
{
|
||||
private IDisposable comboTimer;
|
||||
private IDisposable suspender;
|
||||
private float defaultDisappearTime;
|
||||
|
||||
public ComboTree comboTree;
|
||||
public Dictionary<string, ComboTree> comboTrees;
|
||||
public ComboTree main => comboTrees["Main"];
|
||||
public ComboTree this[string name] => comboTrees[name];
|
||||
|
||||
public ComboSubmodule(ItemBase owner, ComboData asset) : base(owner)
|
||||
{
|
||||
this.defaultDisappearTime = asset.defaultDisappearTime;
|
||||
this.comboTree = asset.tree.ToRuntime();
|
||||
this.comboTree.Reset();
|
||||
}
|
||||
|
||||
public ComboSubmodule(ItemBase owner, float disappearTime) : base(owner)
|
||||
{
|
||||
this.defaultDisappearTime = disappearTime;
|
||||
this.comboTree = new ComboTree();
|
||||
this.comboTree.AddNode(0, "Root");
|
||||
this.comboTree.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置连击计时器,在指定时间后重置连击树
|
||||
/// </summary>
|
||||
/// <param name="disappearTime">连击计时器持续时间,若小于等于0则使用默认时间</param>
|
||||
public void Setup(float disappearTime = -1)
|
||||
{
|
||||
disappearTime = disappearTime <= 0 ? defaultDisappearTime : disappearTime;
|
||||
comboTimer = owner.player.selfTimeSm.AddLocalTimer(disappearTime, () => comboTree.Reset());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停连击计时器,在指定时间后继续重新设置连击计时器
|
||||
/// </summary>
|
||||
public void SuspendThenSetup(float duration)
|
||||
{
|
||||
comboTimer?.Dispose();
|
||||
suspender?.Dispose();
|
||||
suspender = owner.player.selfTimeSm.AddLocalTimer(duration, () => Setup());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前连招节点的引用名称
|
||||
/// </summary>
|
||||
public string GetCurrentNodeName()
|
||||
{
|
||||
return comboTree.currentNode.referenceName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据操作指令进入下一个连招节点
|
||||
/// </summary>
|
||||
/// <param name="operation">操作指令字符串,例如"L","R"</param>
|
||||
/// <param name="autoReset">若无法进入下一个节点,是否返回首个节点</param>
|
||||
/// <returns>是否成功进入下一个节点</returns>
|
||||
public bool NextCombo(string operation, bool autoReset = true)
|
||||
{
|
||||
if (comboTree.currentNode.branches.Count == 0)
|
||||
this.comboTrees = new Dictionary<string, ComboTree>();
|
||||
foreach (KeyValuePair<string, ComboTreeData> treeData in asset.comboTrees)
|
||||
{
|
||||
comboTree.Reset();
|
||||
comboTrees[treeData.Key] = treeData.Value.ToRuntime(this);
|
||||
comboTrees[treeData.Key].Reset();
|
||||
}
|
||||
|
||||
foreach (var branch in comboTree.currentNode.branches.Where(branch => branch.operation == operation))
|
||||
{
|
||||
comboTree.lastNode = comboTree.currentNode;
|
||||
comboTree.currentNode = comboTree.nodes[branch.nextNodeIndex];
|
||||
return true;
|
||||
}
|
||||
|
||||
if (autoReset)
|
||||
{
|
||||
comboTree.Reset();
|
||||
NextCombo(operation);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接设置连招节点
|
||||
/// </summary>
|
||||
/// <param name="index">节点索引</param>
|
||||
public void SetCombo(int index)
|
||||
{
|
||||
comboTree.lastNode = comboTree.currentNode;
|
||||
comboTree.currentNode = comboTree.nodes[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接设置连招节点
|
||||
/// </summary>
|
||||
/// <param name="refName">节点引用名称</param>
|
||||
public void SetCombo(string refName)
|
||||
{
|
||||
comboTree.lastNode = comboTree.currentNode;
|
||||
comboTree.currentNode = comboTree.nodes.Find(x => x.referenceName == refName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回退到上一个连招节点
|
||||
/// </summary>
|
||||
public void RevertCombo()
|
||||
{
|
||||
comboTree.currentNode = comboTree.lastNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置连招树到初始节点
|
||||
/// </summary>
|
||||
public void ResetCombo()
|
||||
{
|
||||
comboTree.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ComboSubmodule
|
||||
{
|
||||
[Serializable]
|
||||
public class ComboTree
|
||||
public partial class ComboTree : SubmoduleBase<ComboSubmodule>
|
||||
{
|
||||
public List<Node> nodes = new();
|
||||
private Player player => owner.owner.player;
|
||||
|
||||
private IDisposable comboTimer;
|
||||
private IDisposable suspender;
|
||||
private float resetTime;
|
||||
|
||||
public List<Node> nodes;
|
||||
public Node lastNode;
|
||||
public Node currentNode;
|
||||
|
||||
public ComboTree(ComboSubmodule owner, float resetTime) : base(owner)
|
||||
{
|
||||
this.resetTime = resetTime;
|
||||
this.nodes = new List<Node>();
|
||||
}
|
||||
|
||||
public void AddNode(int index, string referenceName)
|
||||
{
|
||||
nodes.Add(new Node(index, referenceName));
|
||||
@@ -152,7 +64,112 @@ namespace Cielonos.MainGame.Inventory
|
||||
{
|
||||
currentNode = nodes[0];
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ComboTree
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置连击计时器,在指定时间后重置连击树
|
||||
/// </summary>
|
||||
/// <param name="overrideResetTime">连击计时器持续时间,若小于等于0则使用默认时间</param>
|
||||
public void Setup(float overrideResetTime = -1)
|
||||
{
|
||||
overrideResetTime = overrideResetTime <= 0 ? resetTime : overrideResetTime;
|
||||
comboTimer = player.selfTimeSm.AddLocalTimer(overrideResetTime, Reset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停连击计时器,在指定时间后继续重新设置连击计时器
|
||||
/// </summary>
|
||||
public void SuspendThenSetup(float duration)
|
||||
{
|
||||
comboTimer?.Dispose();
|
||||
suspender?.Dispose();
|
||||
suspender = player.selfTimeSm.AddLocalTimer(duration, () => Setup());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前连招节点的引用名称
|
||||
/// </summary>
|
||||
public string GetCurrentNodeName()
|
||||
{
|
||||
return currentNode.referenceName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前连招节点的下一个节点的引用名称,如果没有符合条件的下一个节点,则返回首个节点的引用名称
|
||||
/// </summary>
|
||||
public string GetNextNodeName(string operation)
|
||||
{
|
||||
foreach (var branch in currentNode.branches.Where(branch => branch.operation == operation))
|
||||
{
|
||||
return nodes[branch.nextNodeIndex].referenceName;
|
||||
}
|
||||
|
||||
return nodes[0].branches.Where(branch => branch.operation == operation)
|
||||
.Select(branch => nodes[branch.nextNodeIndex].referenceName).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据操作指令进入下一个连招节点
|
||||
/// </summary>
|
||||
/// <param name="operation">操作指令字符串,例如"L","R"</param>
|
||||
/// <param name="autoReset">若无法进入下一个节点,是否返回首个节点</param>
|
||||
/// <returns>是否成功进入下一个节点</returns>
|
||||
public bool NextCombo(string operation, bool autoReset = true)
|
||||
{
|
||||
if (currentNode.branches.Count == 0)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
foreach (var branch in currentNode.branches.Where(branch => branch.operation == operation))
|
||||
{
|
||||
lastNode = currentNode;
|
||||
currentNode = nodes[branch.nextNodeIndex];
|
||||
return true;
|
||||
}
|
||||
|
||||
if (autoReset)
|
||||
{
|
||||
Reset();
|
||||
NextCombo(operation);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接设置连招节点
|
||||
/// </summary>
|
||||
/// <param name="index">节点索引</param>
|
||||
public void SetCombo(int index)
|
||||
{
|
||||
lastNode = currentNode;
|
||||
currentNode = nodes[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接设置连招节点
|
||||
/// </summary>
|
||||
/// <param name="refName">节点引用名称</param>
|
||||
public void SetCombo(string refName)
|
||||
{
|
||||
lastNode = currentNode;
|
||||
currentNode = nodes.Find(x => x.referenceName == refName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回退到上一个连招节点
|
||||
/// </summary>
|
||||
public void RevertCombo()
|
||||
{
|
||||
currentNode = lastNode;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ComboTree
|
||||
{
|
||||
[Serializable]
|
||||
public class Node
|
||||
{
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Cielonos.MainGame.Inventory
|
||||
private void ConsumeEnergy()
|
||||
{
|
||||
character.attributeSm["Energy"] -= data.energyCost;
|
||||
character.eventSm.onUseEnergy.Invoke(character, data.energyCost);
|
||||
character.eventSm.onEnergyChanged.Invoke(character, data.energyCost);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user