引雷标记extender
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cielonos.MainGame.Characters;
|
||||
@@ -44,6 +45,9 @@ namespace Cielonos.MainGame.Inventory
|
||||
public FunctionData.FunctionUnit data;
|
||||
public float currentCooldown;
|
||||
public float maxCooldown;
|
||||
|
||||
private Dictionary<string, HashSet<string>> _runtimeTagsBySource;
|
||||
public event Action OnPresentationChanged;
|
||||
|
||||
public RuntimeFunctionUnit(FunctionSubmodule owner, FunctionData.FunctionUnit data) : base(owner)
|
||||
{
|
||||
@@ -51,6 +55,59 @@ namespace Cielonos.MainGame.Inventory
|
||||
maxCooldown = data.cooldown;
|
||||
currentCooldown = 0f;
|
||||
}
|
||||
|
||||
public bool HasTag(string tag)
|
||||
{
|
||||
// Runtime tag 只影响当前 FunctionUnit 实例,不修改共享的 FunctionData。
|
||||
if (data.tags != null && data.tags.Contains(tag)) return true;
|
||||
if (_runtimeTagsBySource == null) return false;
|
||||
|
||||
foreach (HashSet<string> tags in _runtimeTagsBySource.Values)
|
||||
{
|
||||
if (tags.Contains(tag)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetRuntimeTag(string sourceKey, string tag, bool enabled)
|
||||
{
|
||||
// sourceKey 让多个装备可以独立添加或撤销同名表现标签。
|
||||
bool changed = false;
|
||||
if (enabled)
|
||||
{
|
||||
_runtimeTagsBySource ??= new Dictionary<string, HashSet<string>>();
|
||||
if (!_runtimeTagsBySource.TryGetValue(sourceKey, out HashSet<string> tags))
|
||||
{
|
||||
tags = new HashSet<string>();
|
||||
_runtimeTagsBySource.Add(sourceKey, tags);
|
||||
}
|
||||
|
||||
changed = tags.Add(tag);
|
||||
}
|
||||
else if (_runtimeTagsBySource != null &&
|
||||
_runtimeTagsBySource.TryGetValue(sourceKey, out HashSet<string> tags))
|
||||
{
|
||||
changed = tags.Remove(tag);
|
||||
if (tags.Count == 0)
|
||||
{
|
||||
_runtimeTagsBySource.Remove(sourceKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
OnPresentationChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveRuntimeTags(string sourceKey)
|
||||
{
|
||||
if (_runtimeTagsBySource != null && _runtimeTagsBySource.Remove(sourceKey))
|
||||
{
|
||||
OnPresentationChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user