Exemplo n.º 1
0
 public override void Update(GameTime gameTime, BipedWeapon weapon, WeaponFunctions input)
 {
     if (input == WeaponFunctions.TriggerPulled)
     {
         Actor          owner = GameResources.ActorManager.GetActorById(weapon.OwnerActorId);
         WeaponResource wr    = owner.GetBehavior <WeaponResource>();
         if (wr.Value >= weapon.ResourceCostToUse)
         {
             weapon.Fire();
             weapon.CurrentState = BlasterRifleSkill.FiringState;
         }
         else
         {
             weapon.DryFire();
             weapon.CurrentState = BlasterRifleSkill.DryFireState;
         }
     }
 }
Exemplo n.º 2
0
        public override void Fire()
        {
            // Play 'pop' sound
            Actor          owner = GameResources.ActorManager.GetActorById(OwnerActorId);
            WeaponResource wr    = owner.GetBehavior <WeaponResource>();

            wr.Value -= ResourceCostToUse;
            BipedControllerComponent bipedControl = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);
            Vector3 aim = (bipedControl.WorldAim.HasValue ? bipedControl.WorldAim.Value :
                           BepuConverter.Convert(bipedControl.Controller.ViewDirection));
            Matrix muzzleTransform = Matrix.CreateTranslation(MuzzleOffset) * Matrix.CreateWorld(BepuConverter.Convert(
                                                                                                     bipedControl.Controller.Body.Position), aim, Vector3.Up);
            BepuRay       shootRay = new BepuRay(BepuConverter.Convert(muzzleTransform.Translation), BepuConverter.Convert(muzzleTransform.Forward));
            RayCastResult result;

            GameResources.ActorManager.SimSpace.RayCast(shootRay, 500.0f, out result);

            EntityCollidable otherEntityCollidable = result.HitObject as EntityCollidable;
            Terrain          otherTerrain          = result.HitObject as Terrain;

            if (otherEntityCollidable != null &&
                otherEntityCollidable.Entity != null &&
                otherEntityCollidable.Entity.Tag != null)
            {
                Actor      actorHit = GameResources.ActorManager.GetActorById((int)(otherEntityCollidable.Entity.Tag));
                IDamagable damage   = actorHit.GetBehaviorThatImplementsType <IDamagable>();
                if (damage != null)
                {
                    damage.TakeDamage(Damage);
                    // TODO: P2: Query hit actor for appropiate damage effect e.g. blood and create it;
                }
                HitSparks(result.HitData.Location);
            }
            else if (otherTerrain != null)
            {
                HitSparks(result.HitData.Location);
            }
        }