protected override void OnCreate()
        {
            m_EndSimulationEcbSystem = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();
            ScheduledTicks           = new NativeQueue <Entity>(Allocator.Persistent);
            var entity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(typeof(TimeDurationComponent));

            SetComponent(entity, TimeDurationComponent.New(1f, 20f));
        }
        public void ApplyDamage(DamageMessage data)
        {
            if (currentHitPoints <= 0)
            {//ignore damage if already dead. TODO : may have to change that if we want to detect hit on death...
                return;
            }

            if (isInvulnerable)
            {
                OnHitWhileInvulnerable.Invoke();
                return;
            }

            Vector3 forward = transform.forward;
            forward = Quaternion.AngleAxis(hitForwardRotation, transform.up) * forward;

            //we project the direction to damager to the plane formed by the direction of damage
            Vector3 positionToDamager = data.damageSource - transform.position;
            positionToDamager -= transform.up * Vector3.Dot(transform.up, positionToDamager);

            if (Vector3.Angle(forward, positionToDamager) > hitAngle * 0.5f)
                return;

            isInvulnerable = true;
            MyInstantAttributeUpdateSystem.CreateAttributeModifier(dstManager, new MyInstantGameplayAttributeModifier()
            {
                Attribute = EMyPlayerAttribute.Health,
                Operator = EMyAttributeModifierOperator.Add,
                Value = (half)(-data.amount)
            }, new GameplayAbilitySystem.AttributeSystem.Components.GameplayEffectContextComponent()
            {
                Source = Entity.Null,
                Target = this.attributeEntity
            });

            // Create a poison effect, that does 1 damage every 1s tick
            var poisonEntity = dstManager.CreateEntity(typeof(DotGameplayEffect), typeof(DurationStateComponent), typeof(TimeDurationComponent), typeof(GameplayEffectContextComponent));
            dstManager.SetComponentData(poisonEntity, new DotGameplayEffect()
            {
                DamagePerTick = 1f
            });

            dstManager.SetComponentData(poisonEntity, new GameplayEffectContextComponent()
            {
                Target = this.attributeEntity,
                Source = Entity.Null
            });

            dstManager.SetComponentData(poisonEntity, TimeDurationComponent.New(1f, 10f));

            damageMessagesToAction.Add(data);
        }
Exemplo n.º 3
0
        public override Entity CreateEffectEntity(EntityManager dstManager, GameplayEffectSpec GameplayEffectSpec)
        {
            // Create a poison effect, that does 1 damage every 1s tick
            var dotEntity = dstManager.CreateEntity(typeof(DotGameplayEffect), typeof(DurationStateComponent), typeof(TimeDurationComponent), typeof(GameplayEffectContextComponent));

            dstManager.SetComponentData(dotEntity, new DotGameplayEffect()
            {
                DamagePerTick = GameplayEffectSpec.Damage
            });

            dstManager.SetComponentData(dotEntity, new GameplayEffectContextComponent()
            {
                Target = GameplayEffectSpec.GameplayEffectContextComponent.Target,
                Source = GameplayEffectSpec.GameplayEffectContextComponent.Source
            });

            dstManager.SetComponentData(dotEntity, TimeDurationComponent.New(GameplayEffectSpec.TickPeriod, GameplayEffectSpec.Duration));
            return(dotEntity);
        }