public void ApplyGameplayEffect(int index, EntityCommandBuffer.Concurrent Ecb, AttributesComponent attributesComponent, float WorldTime) { var attributeModData = new AttributeModificationComponent() { Add = 0, Multiply = 0, Divide = 0, Change = 0, Source = Source, Target = Target }; var attributeModEntity = Ecb.CreateEntity(index); var gameplayEffectData = new GameplayEffectDurationComponent() { WorldStartTime = WorldTime, Duration = Duration, Effect = EGameplayEffect.GlobalCooldown }; var cooldownEffectComponent = new CooldownEffectComponent() { Caster = Source }; Ecb.AddComponent(index, attributeModEntity, new NullAttributeModifier()); Ecb.AddComponent(index, attributeModEntity, new TemporaryAttributeModification()); Ecb.AddComponent(index, attributeModEntity, gameplayEffectData); Ecb.AddComponent(index, attributeModEntity, attributeModData); Ecb.AddComponent(index, attributeModEntity, cooldownEffectComponent); Ecb.AddComponent(index, attributeModEntity, new GlobalCooldownTagComponent()); }
public Entity Instantiate(int jobIndex, EntityCommandBuffer.Concurrent Ecb, Entity actorEntity, float duration) { var entity = Ecb.CreateEntity(jobIndex); Ecb.AddComponent <GameplayEffectDurationComponent>(jobIndex, entity, GameplayEffectDurationComponent.Initialise(DURATION, 0f)); Ecb.AddComponent <GameplayEffectTargetComponent>(jobIndex, entity, actorEntity); Ecb.AddComponent(jobIndex, entity, this.GetType()); new PermanentAttributeModifierTag() { }.CreateAttributeModifier <HealthAttributeComponent, Add>(jobIndex, Ecb, actorEntity, Damage); return(entity); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var CooldownDurationComponents = GetComponentDataFromEntity <GameplayEffectDurationComponent>(); var Cooldown1TagComponents = GetComponentDataFromEntity <GlobalCooldownGameplayEffectComponent>(); var Cooldown2TagComponents = GetComponentDataFromEntity <Fire1CooldownGameplayEffectComponent>(); var AbilityTagComponents = GetComponentDataFromEntity <Fire1AbilityTag>(); var AbilityCooldownComponents = GetComponentDataFromEntity <AbilityCooldownComponent>(); // Set the cooldown of the ability for each actor inputDeps = Entities.ForEach((Entity entity, int entityInQueryIndex, in DynamicBuffer <GameplayEffectBufferElement> gameplayEffectBuffer, in DynamicBuffer <GrantedAbilityBufferElement> grantedAbilityBuffer) => { // The outer foreach loops through all actors var abilityCooldownDuration = new GameplayEffectDurationComponent(); for (var i = 0; i < gameplayEffectBuffer.Length; i++) { // The inner loop is iterating through all active GE on a single actor var gameplayEffectEntity = gameplayEffectBuffer[i].Value; // Check if entity has any of the cooldown components int cooldownDurationComponentThatHas = 0; cooldownDurationComponentThatHas = math.select(1, cooldownDurationComponentThatHas, Cooldown1TagComponents.HasComponent(gameplayEffectEntity)); cooldownDurationComponentThatHas = math.select(2, cooldownDurationComponentThatHas, Cooldown2TagComponents.HasComponent(gameplayEffectEntity)); if (cooldownDurationComponentThatHas > 0) { if (!CooldownDurationComponents.HasComponent(gameplayEffectEntity)) { continue; } var durationComponent = CooldownDurationComponents[gameplayEffectEntity]; // Cooldown selection logic: // 1. Effect with the longest remaining duration is always the ability's cooldown remaining duration // 2. If two effects have the same remaining duration, then the effect with the longest period is the ability's cooldown duration bool thisEffectIsLongest = durationComponent.Value > abilityCooldownDuration.Value; abilityCooldownDuration.Value.RemainingTime = math.select(abilityCooldownDuration.Value.RemainingTime, durationComponent.Value.RemainingTime, thisEffectIsLongest); abilityCooldownDuration.Value.NominalDuration = math.select(abilityCooldownDuration.Value.NominalDuration, durationComponent.Value.NominalDuration, thisEffectIsLongest); abilityCooldownDuration.Value.WorldStartTime = math.select(abilityCooldownDuration.Value.WorldStartTime, durationComponent.Value.WorldStartTime, thisEffectIsLongest); } } for (var i = 0; i < grantedAbilityBuffer.Length; i++) { if (AbilityTagComponents.HasComponent(grantedAbilityBuffer[i])) { AbilityCooldownComponents[grantedAbilityBuffer[i]] = new AbilityCooldownComponent { Value = abilityCooldownDuration }; break; } } })
public Entity Instantiate(EntityManager dstManager, Entity actorEntity, float duration) { var archetype = dstManager.CreateArchetype( typeof(GameplayEffectDurationComponent), typeof(GameplayEffectTargetComponent), typeof(GameplayEffectBuffIndex), this.GetType()); var entity = dstManager.CreateEntity(archetype); dstManager.SetComponentData <GameplayEffectTargetComponent>(entity, actorEntity); dstManager.SetComponentData <GameplayEffectBuffIndex>(entity, BuffIndex); dstManager.SetComponentData <GameplayEffectDurationComponent>(entity, GameplayEffectDurationComponent.Initialise(duration, UnityEngine.Time.time)); return(entity); }
public Entity Instantiate(EntityManager dstManager, Entity actorEntity, float duration) { var archetype = dstManager.CreateArchetype( typeof(GameplayEffectDurationComponent), typeof(GameplayEffectTargetComponent), this.GetType()); var entity = dstManager.CreateEntity(archetype); dstManager.SetComponentData <GameplayEffectTargetComponent>(entity, actorEntity); dstManager.SetComponentData <GameplayEffectDurationComponent>(entity, GameplayEffectDurationComponent.Initialise(DURATION, UnityEngine.Time.time)); new PermanentAttributeModifierTag() { }.CreateAttributeModifier <HealthAttributeComponent, Add>(dstManager, actorEntity, Damage); return(entity); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var Cooldown1DurationComponents = GetComponentDataFromEntity <GameplayEffectDurationComponent>(); var Cooldown1TagComponents = GetComponentDataFromEntity <GlobalCooldownGameplayEffectComponent>(); var AbilityTagComponents = GetComponentDataFromEntity <DefaultAttackAbilityTag>(); var AbilityCooldownComponents = GetComponentDataFromEntity <AbilityCooldownComponent>(); // NativeHashMap<Entity, GameplayEffectDurationComponent> AbilityCooldownDurations = new NativeHashMap<Entity, GameplayEffectDurationComponent>(m_GEQuery.CalculateEntityCount(), Allocator.TempJob); inputDeps = Entities.ForEach((Entity entity, int entityInQueryIndex, in DynamicBuffer <GameplayEffectBufferElement> gameplayEffectBuffer, in DynamicBuffer <GrantedAbilityBufferElement> grantedAbilityBuffer) => { // The outer foreach loops through all actors var abilityCooldownDuration = new GameplayEffectDurationComponent(); for (var i = 0; i < gameplayEffectBuffer.Length; i++) { // The inner loop is iterating through all active GE on a single actor var gameplayEffectEntity = gameplayEffectBuffer[i].Value; // Check if entity has any of the cooldown components if (Cooldown1DurationComponents.HasComponent(gameplayEffectEntity) && Cooldown1TagComponents.HasComponent(gameplayEffectEntity)) { var durationComponent = Cooldown1DurationComponents[gameplayEffectEntity]; bool thisEffectIsLongest = durationComponent.Value > abilityCooldownDuration.Value; abilityCooldownDuration.Value.RemainingTime = math.select(abilityCooldownDuration.Value.RemainingTime, durationComponent.Value.RemainingTime, thisEffectIsLongest); abilityCooldownDuration.Value.NominalDuration = math.select(abilityCooldownDuration.Value.NominalDuration, durationComponent.Value.NominalDuration, thisEffectIsLongest); abilityCooldownDuration.Value.WorldStartTime = math.select(abilityCooldownDuration.Value.WorldStartTime, durationComponent.Value.WorldStartTime, thisEffectIsLongest); } } for (var i = 0; i < grantedAbilityBuffer.Length; i++) { if (AbilityTagComponents.HasComponent(grantedAbilityBuffer[i])) { AbilityCooldownComponents[grantedAbilityBuffer[i]] = new AbilityCooldownComponent { Value = abilityCooldownDuration }; break; } } })
/// <summary> /// For testing cooldowns /// </summary> /// <param name="dstManager"></param> /// <param name="abilitySystemEntity"></param> private void TestAbilitySystemCooldown(EntityManager dstManager, Entity abilitySystemEntity) { var cooldownArchetype = dstManager.CreateArchetype( typeof(GameplayEffectDurationComponent), typeof(GameplayEffectTargetComponent), typeof(GlobalCooldownGameplayEffectComponent)); var cooldownEntity = dstManager.CreateEntity(cooldownArchetype); dstManager.SetComponentData <GameplayEffectTargetComponent>(cooldownEntity, abilitySystemEntity); dstManager.SetComponentData <GameplayEffectDurationComponent>(cooldownEntity, GameplayEffectDurationComponent.Initialise(10, 1)); var cooldownEntity2 = dstManager.CreateEntity(cooldownArchetype); dstManager.SetComponentData <GameplayEffectTargetComponent>(cooldownEntity2, abilitySystemEntity); dstManager.SetComponentData <GameplayEffectDurationComponent>(cooldownEntity2, GameplayEffectDurationComponent.Initialise(5, 1)); }
public void Execute(Entity entity, int index, ref T abilityDurationComponent) { GameplayEffectDurations.Add(entity, GameplayEffectDurationComponent.Initialise(0, 0)); }