feat: Introduce new services and refactor existing code for better structure
- Added ISpriteCacheService, IStaticDataService, and ITextService interfaces for improved service management. - Implemented RunContracts for managing run states and node execution contexts. - Created EnemyTagStatusRuntime to handle enemy status effects and their application. - Refactored ShopPriceRuleService to utilize static data service for shop prices. - Enhanced InventoryTowerEnduranceUtility to manage tower endurance reduction. - Updated EventFormUseCase to work with new EventOptionExecutionContext. - Removed unused dictionary loading code from ProcedurePreload. - Cleaned up various utility classes and ensured consistent naming conventions. - Updated tests to reflect changes in context and service usage.
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity
|
||||
{
|
||||
public sealed class EnemyTagStatusRuntime
|
||||
{
|
||||
private readonly Dictionary<TagType, EnemyStatusTagStateBase> _statesByTag = new();
|
||||
private readonly List<TagType> _activeTags = new();
|
||||
|
||||
public bool HasStatus(TagType tagType)
|
||||
{
|
||||
return _statesByTag.ContainsKey(tagType);
|
||||
}
|
||||
|
||||
public TagType[] GetActiveTagSnapshot()
|
||||
{
|
||||
if (_activeTags.Count <= 0)
|
||||
{
|
||||
return Array.Empty<TagType>();
|
||||
}
|
||||
|
||||
return _activeTags.ToArray();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_statesByTag.Clear();
|
||||
_activeTags.Clear();
|
||||
}
|
||||
|
||||
public void Activate(TagType tagType)
|
||||
{
|
||||
if (_activeTags.Contains(tagType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_activeTags.Add(tagType);
|
||||
}
|
||||
|
||||
public TState GetState<TState>(TagType tagType) where TState : EnemyStatusTagStateBase
|
||||
{
|
||||
if (!_statesByTag.TryGetValue(tagType, out EnemyStatusTagStateBase state))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Debug.Assert(state is TState);
|
||||
return state as TState;
|
||||
}
|
||||
|
||||
public TState GetOrCreateState<TState>(TagType tagType) where TState : EnemyStatusTagStateBase, new()
|
||||
{
|
||||
if (_statesByTag.TryGetValue(tagType, out EnemyStatusTagStateBase existingState))
|
||||
{
|
||||
Debug.Assert(existingState is TState);
|
||||
return existingState as TState;
|
||||
}
|
||||
|
||||
TState state = new TState();
|
||||
_statesByTag[tagType] = state;
|
||||
return state;
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime, Action<int> applyDamage)
|
||||
{
|
||||
float resolvedDeltaTime = Mathf.Max(0f, deltaTime);
|
||||
if (resolvedDeltaTime <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = _activeTags.Count - 1; i >= 0; i--)
|
||||
{
|
||||
TagType tagType = _activeTags[i];
|
||||
Debug.Assert(EnemyStatusTagRegistry.TryGetEffect(tagType, out IEnemyStatusTagEffect effect));
|
||||
|
||||
if (effect.Tick(this, resolvedDeltaTime, applyDamage))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_statesByTag.Remove(tagType);
|
||||
_activeTags.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetMoveSpeedMultiplier()
|
||||
{
|
||||
float multiplier = 1f;
|
||||
for (int i = 0; i < _activeTags.Count; i++)
|
||||
{
|
||||
TagType tagType = _activeTags[i];
|
||||
Debug.Assert(EnemyStatusTagRegistry.TryGetEffect(tagType, out IEnemyStatusTagEffect effect));
|
||||
multiplier = Mathf.Min(multiplier, effect.GetMoveSpeedMultiplier(this));
|
||||
}
|
||||
|
||||
return multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe0965914fd71e34ea696bfd546efc66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user