Example #1
0
    public void ConusmeAllEffectOnTargetEntity()
    {
        // Arrange
        Entity caster = _entityManager.CreateEntity();
        Entity Target = _entityManager.CreateEntity();

        _entityManager.AddComponentData(Target, new TestResource()
        {
            Value = 100
        });

        _world.WithSystem <TestEffectConsumerSystem>();
        TestEffectConsumerSystem consumerSystem = _world.GetReference().GetExistingSystem <TestEffectConsumerSystem>();

        NativeStream.Writer effectWriter = consumerSystem.CreateConsumerWriter(2);
        effectWriter.BeginForEachIndex(0);
        effectWriter.Write(new TestEffectContext()
        {
            Target = Target, Effect = new TestEffect()
            {
                Value = 10
            }
        });
        effectWriter.Write(new TestEffectContext()
        {
            Target = Target, Effect = new TestEffect()
            {
                Value = 20
            }
        });
        effectWriter.EndForEachIndex();
        effectWriter.BeginForEachIndex(1);
        effectWriter.Write(new TestEffectContext()
        {
            Target = Target, Effect = new TestEffect()
            {
                Value = 5
            }
        });
        effectWriter.Write(new TestEffectContext()
        {
            Target = Target, Effect = new TestEffect()
            {
                Value = 15
            }
        });
        effectWriter.EndForEachIndex();


        // Act
        _world.UpdateSystem <TestEffectConsumerSystem>();
        _world.CompleteAllJobs();

        // Assert
        Assert.AreEqual(50, _entityManager.GetComponentData <TestResource>(Target).Value);
    }
        public void OnlyTriggerEffectOfActiveSkill([Values(AbilityState.CooledDown, AbilityState.CoolingDown, AbilityState.Casting)] AbilityState state)
        {
            // Arrange
            Entity caster = _entityManager.CreateEntity();

            _entityManager.AddComponentData(caster, new Target()
            {
                Value = Entity.Null
            });

            _entityManager.AddComponentData(caster, new TestResource()
            {
                Value = 20
            });

            Ability ability = new Ability(1, 1, new Range())
            {
                State = AbilityState.Active
            };

            DynamicBuffer <AbilityBuffer> abilityBuffer = _entityManager.AddBuffer <AbilityBuffer>(caster);

            abilityBuffer.Add(new AbilityBuffer()
            {
                Ability = ability
            });
            abilityBuffer.Add(new AbilityBuffer()
            {
                Ability = new Ability(1, 1, new Range())
                {
                    State = state
                }
            });

            DynamicBuffer <TestEffectBuffer> testEffectBuffer = _entityManager.AddBuffer <TestEffectBuffer>(caster);

            testEffectBuffer.Add(new TestEffectBuffer()
            {
                AbilityIndex = 0,
                Effect       = new TestEffect()
                {
                    Affects = EffectAffectType.Target,
                    Value   = 1
                }
            });
            testEffectBuffer.Add(new TestEffectBuffer()
            {
                AbilityIndex = 1,
                Effect       = new TestEffect()
                {
                    Affects = EffectAffectType.Target,
                    Value   = 1
                }
            });

            _world.WithSystem <TestEffectTriggerSystem>();

            //Act
            _world.UpdateSystem <TestEffectTriggerSystem>();
            _world.CompleteAllJobs();

            //Assert
            TestEffectConsumerSystem conusmerSystem = _world.GetReference().GetExistingSystem <TestEffectConsumerSystem>();

            NativeStream.Reader reader = conusmerSystem.GetEffectReader();
            Assert.AreEqual(1, conusmerSystem.GetEffectReader().ComputeItemCount());
            reader.BeginForEachIndex(0);
            TestEffectContext ctx = reader.Read <TestEffectContext>();

            Assert.AreEqual(Entity.Null, ctx.Target);
            Assert.AreEqual(EffectAffectType.Target, ctx.Effect.Affects);
            Assert.AreEqual(1, ctx.Effect.Value);
            Assert.AreEqual(20, ctx.testResourceValue);
            reader.EndForEachIndex();
        }