public override void Start()
        {
            base.Start();
            if (Camera == null)
            {
                throw new ArgumentException("The camera is not set");
            }
            if (AnimationComponent == null)
            {
                throw new ArgumentException("The animation component is not set");
            }
            if (SoldierController == null)
            {
                throw new ArgumentException("SoldierController is not set");
            }

            InitializeLowerStateMachine();
            InitializeUpperStateMachine();

            SoldierController.OnDamageTaken += (soldier, damage) =>
            {
                if (dead)
                {
                    return;
                }
                if (soldier.IsDead)
                {
                    dead = true;
                    AnimationComponent.PlayingAnimations.ForEach(x => { x.WeightTarget = 0.0f; x.CrossfadeRemainingTime = TimeSpan.FromSeconds(0.2); });
                    var death = NewAnimation(AnimKeys.Death);
                    AddLowerAnimation(death);
                    lowerStateMachine?.Exit();
                    upperStateMachine?.Exit();
                }
                else
                {
                    for (var i = AnimationComponent.PlayingAnimations.Count - 1; i >= 0; i--)
                    {
                        if (AnimationComponent.PlayingAnimations[i].Name == AnimKeys.TakeDamage)
                        {
                            AnimationComponent.PlayingAnimations.RemoveAt(i);
                        }
                    }
                    AnimationComponent.PlayingAnimations.Add(NewAnimation(AnimKeys.TakeDamage, true));
                }
            };

            soldierWeapon           = SoldierController.Entity.Get <SoldierWeapon>();
            soldierWeapon.OnReload += weapon =>
            {
                if (!dead)
                {
                    Script.AddTask(() => AddAdditiveAnimation(AnimKeys.ReloadWeapon));
                }
            };
        }
Exemple #2
0
        public override void Start()
        {
            if (ShootSource == null)
            {
                throw new ArgumentException("ShootSource not set");
            }
            if (ShootTarget == null)
            {
                throw new ArgumentException("ShootTarget not set");
            }
            if (Light == null)
            {
                throw new ArgumentException("Light not set");
            }
            if (ShootTrail == null)
            {
                throw new ArgumentException("ShootTrail not set");
            }
            if (ShootImpact == null)
            {
                throw new ArgumentException("ShootImpact not set");
            }
            if (BulletHole == null)
            {
                throw new ArgumentException("BulletHole not set");
            }

            var muzzleFlashEntity = ShootSource.FindChild("MuzzleFlash");

            muzzleFlashParticles = muzzleFlashEntity?.Get <ParticleSystemComponent>()?.ParticleSystem;
            muzzleFlashParticles?.Stop();

            laserEffect = ShootTrail.ParticleSystem;
            laserEffect.Stop();
            laserImpact = ShootImpact.ParticleSystem;
            laserImpact.Stop();


            BulletHole.ParticleSystem.Enabled = true;
            BulletHole.ParticleSystem.Stop();

            Light.Enabled = false;

            AudioEmitterComponent shootEmitter       = Entity.FindChild("ShootSource").Get <AudioEmitterComponent>();
            AudioEmitterComponent shootTargetEmitter = ShootTarget.Get <AudioEmitterComponent>();

            // Load different shoot sound effects
            shootSounds = new AudioEmitterSoundController[4];
            for (int i = 0; i < shootSounds.Length; i++)
            {
                shootSounds[i] = shootEmitter["Shoot" + i];
            }

            // Load different impact sound effects
            impactSounds = new AudioEmitterSoundController[4];
            for (int i = 0; i < impactSounds.Length; i++)
            {
                impactSounds[i] = shootTargetEmitter["Impact" + i];
            }

            SoldierWeapon weapon = Entity.Get <SoldierWeapon>();

            weapon.OnShotFired += (soldierWeapon, result) =>
            {
                Script.AddTask(async() => await FireWeapon(result));
            };
        }