Exemple #1
0
    public static void Create(EntityCommandBuffer commandBuffer, HitscanEffectTypeDefinition definition, Vector3 startPos, Vector3 endPos)
    {
        var request = new HitscanEffectRequest();

        request.effectTypeRegistryId = definition.registryId;
        request.startPos             = startPos;
        request.endPos = endPos;

        commandBuffer.CreateEntity();
        commandBuffer.AddComponent(request);
    }
    void Update(GameTime time, TerraformerWeaponA weapon, Character character)
    {
        // Update using AutoRifle ability state
        var autoRifleAbility = character.FindAbilityWithComponent(EntityManager, typeof(Ability_AutoRifle.InterpolatedState));

        GameDebug.Assert(autoRifleAbility != Entity.Null, "AbilityController does not own a Ability_AutoRifle ability");
        var autoRifleInterpolatedState = EntityManager.GetComponentData <Ability_AutoRifle.InterpolatedState>(autoRifleAbility);

        if (weapon.primaryFireEvent.Update(time, autoRifleInterpolatedState.fireTick))
        {
            if (weapon.primaryFireSound != null)
            {
                if (weapon.primaryFireSoundHandle.IsValid() && weapon.primaryFireSoundHandle.emitter.playing)
                {
                    Game.SoundSystem.Stop(weapon.primaryFireSoundHandle, 0.05f);
                }
                weapon.primaryFireSoundHandle = Game.SoundSystem.Play(weapon.primaryFireSound, weapon.muzzle);
            }

            if (weapon.primaryFireEffect != null)
            {
                weapon.primaryFireEffect.Play();
            }

            if (weapon.hitscanEffect != null)
            {
                HitscanEffectRequest.Create(PostUpdateCommands, weapon.hitscanEffect, weapon.muzzle.position,
                                            autoRifleInterpolatedState.fireEndPos);
            }

            if (autoRifleInterpolatedState.impactType != Ability_AutoRifle.ImpactType.None)
            {
                var rotation = Quaternion.LookRotation(autoRifleInterpolatedState.impactNormal);
                if (autoRifleInterpolatedState.impactType == Ability_AutoRifle.ImpactType.Character)
                {
                    SpatialEffectRequest.Create(PostUpdateCommands, weapon.characterImpactEffect,
                                                autoRifleInterpolatedState.fireEndPos, rotation);
                }
                else
                {
                    SpatialEffectRequest.Create(PostUpdateCommands, weapon.environmentImpactEffect,
                                                autoRifleInterpolatedState.fireEndPos, rotation);
                }
            }
        }

        // Update using ProjectileLauncher ability state
        var rocketAbility = character.FindAbilityWithComponent(EntityManager, typeof(Ability_ProjectileLauncher.InterpolatedState));

        GameDebug.Assert(rocketAbility != Entity.Null, "AbilityController does not own a Ability_ProjectileLauncher ability");
        var rocketLaunchInterpolatedState = EntityManager.GetComponentData <Ability_ProjectileLauncher.InterpolatedState>(rocketAbility);

        if (weapon.secondaryFireEvent.Update(time, rocketLaunchInterpolatedState.fireTick))
        {
            if (weapon.secondaryFireSound != null)
            {
                Game.SoundSystem.Play(weapon.secondaryFireSound, weapon.muzzle);
            }

            if (weapon.secondaryFireEffect != null)
            {
                weapon.secondaryFireEffect.Play();
            }
        }

        // Update using Melee ability ability state
        var meleeAbility = character.FindAbilityWithComponent(EntityManager, typeof(Ability_Melee.InterpolatedState));

        GameDebug.Assert(meleeAbility != Entity.Null, "AbilityController does not own a Ability_Melee ability");
        var meleeInterpolatedState = EntityManager.GetComponentData <Ability_Melee.InterpolatedState>(meleeAbility);

        if (weapon.meleeImpactEvent.Update(time, meleeInterpolatedState.impactTick))
        {
            if (weapon.meleeImpactSound != null)
            {
                Game.SoundSystem.Play(weapon.meleeImpactSound, weapon.transform.position);
            }

            if (weapon.meleeImpactEffect != null)
            {
                weapon.meleeImpactEffect.Play();
            }
        }



        // Vents disabled vents until we find out what to do with them
        // Update vents
//            if (entity.vents != null)
//            {
//                for (int ventIndex = 0; ventIndex < entity.vents.Length; ventIndex++)
//                {
//                    if (entity.ventRotationSpeed[ventIndex] == 0)
//                        continue;
//
//                    // Rotate
//                    float deltaRot = entity.ventRotationSpeed[ventIndex] * m_world.frameDuration;
//                    Vector3 eulerRot = entity.vents[ventIndex].rotation.eulerAngles;
//                    eulerRot.z += deltaRot;
//                    entity.vents[ventIndex].rotation = Quaternion.Euler(eulerRot);
//
//                    // Damp speed
//                    float deltaSpeed = entity.ventDampSpeed * m_world.frameDuration;
//                    float absSpeed = Mathf.Abs(entity.ventRotationSpeed[ventIndex]);
//                    if (deltaSpeed >= absSpeed)
//                        entity.ventRotationSpeed[ventIndex] = 0;
//                    else
//                        entity.ventRotationSpeed[ventIndex] -= Mathf.Sign(entity.ventRotationSpeed[ventIndex]) * deltaSpeed;
//                }
//
//                Character.State.Action newAction = weapon.action;
//                if (newAction != entity.m_prevAction)
//                {
//                    if (newAction == Character.State.Action.PrimaryFire)
//                    {
//                        entity.ventRotationSpeed[entity.nextVentIndex] = entity.ventStartSpeed;
//                        entity.ventRotationSpeed[entity.nextVentIndex + 1] = -entity.ventStartSpeed;
//                        entity.nextVentIndex = (entity.nextVentIndex + 2) % entity.vents.Length;
//                    }
//                    if (newAction == Character.State.Action.SecondaryFire)
//                    {
//                        entity.timelineGrenadeRefill.time = 0;
//                        entity.timelineGrenadeRefill.Play();
//                    }
//
//                    entity.m_prevAction = newAction;
//                }
//            }


        // Velocity based ammo fuel angle
        if (weapon.grenadeFuelBase != null)
        {
            Vector3 basePos = weapon.grenadeFuelBase.position;
            Vector3 moveVec = basePos - weapon.m_lastGrenadeFuelWorldPos;
            weapon.m_lastGrenadeFuelWorldPos = basePos;

            Vector3    rotateAxis = Vector3.Cross(moveVec, Vector3.up).normalized;
            float      moveVel    = moveVec.magnitude / m_world.frameDuration;
            float      angle      = moveVel * 2;
            Quaternion targetRot  = Quaternion.AngleAxis(-angle, rotateAxis);

            weapon.grenadeFuelBase.rotation = Quaternion.Lerp(weapon.grenadeFuelBase.rotation, targetRot, 3 * m_world.frameDuration);
        }
    }