using System.Collections.Generic;
using CoreGame;
using Entitas;
using GAS.Runtime;
namespace CoreGame.Render
{
///
/// 刷新可刷新的护盾
///
public class RefreshableHpShieldReloadSystem : IExecuteSystem
{
readonly IGroup m_Group;
public static Dictionary s_Element2Res = new()
{
{(int)ElementType.None, "Assets/GAS_Setting/Config/GameplayAbilityLib/temp/GE_HpShield_BossNone.asset"},
{(int)ElementType.Fire, "Assets/GAS_Setting/Config/GameplayAbilityLib/temp/GE_HpShield_BossFire.asset"},
{(int)ElementType.Toxic, "Assets/GAS_Setting/Config/GameplayAbilityLib/temp/GE_HpShield_BossToxic.asset"},
{(int)ElementType.Thunder, "Assets/GAS_Setting/Config/GameplayAbilityLib/temp/GE_HpShield_BossThunder.asset"},
};
public RefreshableHpShieldReloadSystem(CombatContext contexts)
{
var gunReloadMatcher =
(Matcher)Matcher.AllOf(CombatComponentsLookup.RefreshableHpShield,
CombatComponentsLookup.Reload);
m_Group = contexts.GetGroup(gunReloadMatcher);
}
public void Execute(float dt)
{
m_Group.GetEntities(Contexts.s_CacheEntities);
if (Contexts.s_CacheEntities.Count == 0)
return;
var entities = Contexts.s_CacheEntities;
for (int i = 0; i < entities.Count; i++)
{
var entity = entities[i];
var reload = entity.reload;
reload.cdAcc += dt;
if (reload.cdAcc < reload.cdTotal || entity.isMainAssetLoaded == false)
continue;
// 刷新护盾
entity.RemoveReload();
s_Element2Res.TryGetValue((int)entity.refreshableHpShield.elementType, out var res);
var gameplayEffect = AbilitySrv.GetGameplayEffect(res);
if (gameplayEffect != null)
{
var effectParams = new GameplayEffectParams();
var abilitySystem = entity.abilitySystem;
effectParams.level = 1;
effectParams.source = abilitySystem;
effectParams.owner = abilitySystem;
abilitySystem.ApplyGameplayEffectTo_WithParams(gameplayEffect, effectParams);
}
}
}
}
}