[Fix] Refactor project

This commit is contained in:
2026-03-02 12:49:12 +07:00
parent f65976796d
commit f52131f755
44 changed files with 449 additions and 404 deletions
@@ -18,10 +18,10 @@ namespace YachtDice.Modifiers.Conditions
{
if (context.DiceValues == null) return false;
int count = 0;
for (int i = 0; i < context.DiceValues.Length; i++)
var count = 0;
foreach (var t in context.DiceValues)
{
if (targetValue == 0 || context.DiceValues[i] == targetValue)
if (targetValue == 0 || t == targetValue)
count++;
}
return count >= minCount;
@@ -15,10 +15,10 @@ namespace YachtDice.Modifiers.Conditions
{
if (context.DiceValues == null) return false;
int count = 0;
for (int i = 0; i < context.DiceValues.Length; i++)
var count = 0;
foreach (var t in context.DiceValues)
{
if (context.DiceValues[i] == targetValue)
if (t == targetValue)
count++;
}
return count >= minCount;
@@ -15,13 +15,19 @@ namespace YachtDice.Modifiers.Core
public float Multiplier = 1f;
public float PostMultiplier = 1f;
/// <summary>Абстрактные дайсы (основной API).</summary>
/// <summary>
/// Абстрактные дайсы (основной API).
/// </summary>
public IReadOnlyList<IDice> Dice;
/// <summary>Значения дайсов (обратная совместимость с существующими модификаторами).</summary>
/// <summary>
/// Значения дайсов (обратная совместимость с существующими модификаторами).
/// </summary>
public int[] DiceValues;
/// <summary>Категория, в которую записывается результат.</summary>
/// <summary>
/// Категория, в которую записывается результат.
/// </summary>
public CategoryDefinition Category;
// Game state (read-only snapshot)
@@ -2,9 +2,9 @@ namespace YachtDice.Modifiers.Core
{
public enum ModifierRarity
{
Common,
Uncommon,
Rare,
Epic,
Common = 1,
Uncommon = 2,
Rare = 3,
Epic = 4,
}
}
@@ -17,11 +17,12 @@ namespace YachtDice.Modifiers.Definition
public bool EvaluateConditions(ModifierContext context, ModifierInstance instance)
{
for (int i = 0; i < conditions.Count; i++)
foreach (var t in conditions)
{
if (conditions[i] != null && !conditions[i].Evaluate(context, instance))
if (t != null && !t.Evaluate(context, instance))
return false;
}
return true;
}
@@ -12,11 +12,12 @@ namespace YachtDice.Modifiers.Definition
public ModifierDefinition FindById(string id)
{
for (int i = 0; i < modifiers.Count; i++)
foreach (var t in modifiers)
{
if (modifiers[i] != null && modifiers[i].Id == id)
return modifiers[i];
if (t != null && t.Id == id)
return t;
}
return null;
}
}
@@ -19,13 +19,13 @@ namespace YachtDice.Modifiers.Editor
return;
}
int errorCount = 0;
int warnCount = 0;
var errorCount = 0;
var warnCount = 0;
var usedIds = new Dictionary<string, string>(); // id -> asset path
for (int i = 0; i < guids.Length; i++)
foreach (var t in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
var path = AssetDatabase.GUIDToAssetPath(t);
var def = AssetDatabase.LoadAssetAtPath<ModifierDefinition>(path);
if (def == null)
@@ -19,10 +19,10 @@ namespace YachtDice.Modifiers.Effects
{
if (context.DiceValues == null) return UniTask.CompletedTask;
int count = 0;
for (int i = 0; i < context.DiceValues.Length; i++)
var count = 0;
foreach (var t in context.DiceValues)
{
if (targetDiceValue == 0 || context.DiceValues[i] == targetDiceValue)
if (targetDiceValue == 0 || t == targetDiceValue)
count++;
}
@@ -19,9 +19,9 @@ namespace YachtDice.Modifiers.Effects
{
if (context.DiceValues == null) return UniTask.CompletedTask;
for (int i = 0; i < context.DiceValues.Length; i++)
foreach (var t in context.DiceValues)
{
if (targetDiceValue == 0 || context.DiceValues[i] == targetDiceValue)
if (targetDiceValue == 0 || t == targetDiceValue)
context.Multiplier *= multiplierPerDice;
}
@@ -17,7 +17,7 @@ namespace YachtDice.Modifiers.Pipeline
public int Compare(EffectEntry a, EffectEntry b)
{
int cmp = a.Effect.Phase.CompareTo(b.Effect.Phase);
var cmp = a.Effect.Phase.CompareTo(b.Effect.Phase);
if (cmp != 0) return cmp;
cmp = a.Effect.Priority.CompareTo(b.Effect.Priority);
@@ -56,14 +56,12 @@ namespace YachtDice.Modifiers.Pipeline
var activeSnapshot = _registry.Active;
// Gather eligible effects
for (int i = 0; i < activeSnapshot.Count; i++)
foreach (var inst in activeSnapshot)
{
var inst = activeSnapshot[i];
var behaviors = inst.Definition.Behaviors;
for (int b = 0; b < behaviors.Count; b++)
foreach (var behavior in behaviors)
{
var behavior = behaviors[b];
if (behavior == null) continue;
if (behavior.Trigger != trigger) continue;
@@ -45,9 +45,8 @@ namespace YachtDice.Modifiers.Pipeline
{
var sb = new StringBuilder();
sb.AppendLine($"[ModifierPipeline] Trigger: {Trigger}");
for (int i = 0; i < Entries.Count; i++)
foreach (var e in Entries)
{
var e = Entries[i];
if (e.EffectApplied != null)
{
sb.AppendLine($" EFFECT [{e.Phase}] {e.ModifierId} -> {e.EffectApplied}");
@@ -38,8 +38,9 @@ namespace YachtDice.Modifiers.Runtime
get
{
int count = 0;
for (int i = 0; i < _instances.Count; i++)
if (_instances[i].IsActive) count++;
foreach (var t in _instances)
if (t.IsActive) count++;
return count;
}
}
@@ -62,7 +63,7 @@ namespace YachtDice.Modifiers.Runtime
{
if (!_instances.Contains(instance)) return;
bool wasActive = instance.IsActive;
var wasActive = instance.IsActive;
instance.IsActive = false;
_instances.Remove(instance);
_activeCacheDirty = true;
@@ -98,9 +99,9 @@ namespace YachtDice.Modifiers.Runtime
public void ConsumeChargesOnActive()
{
bool changed = false;
var changed = false;
for (int i = _instances.Count - 1; i >= 0; i--)
for (var i = _instances.Count - 1; i >= 0; i--)
{
var inst = _instances[i];
if (!inst.IsActive) continue;
@@ -115,20 +116,18 @@ namespace YachtDice.Modifiers.Runtime
}
}
if (changed)
{
_activeCacheDirty = true;
OnActiveModifiersChanged?.Invoke(Active);
OnChanged?.Invoke();
}
if (!changed) return;
_activeCacheDirty = true;
OnActiveModifiersChanged?.Invoke(Active);
OnChanged?.Invoke();
}
public List<ModifierSaveEntry> GetSaveData()
{
var entries = new List<ModifierSaveEntry>();
for (int i = 0; i < _instances.Count; i++)
foreach (var inst in _instances)
{
var inst = _instances[i];
var entry = new ModifierSaveEntry
{
modifierId = inst.Definition.Id,
@@ -158,9 +157,8 @@ namespace YachtDice.Modifiers.Runtime
if (entries == null) return;
for (int i = 0; i < entries.Count; i++)
foreach (var entry in entries)
{
var entry = entries[i];
var definition = catalog.FindById(entry.modifierId);
if (definition == null)