/// <summary> /// The method to call to start a shoot attack with the weapon. /// </summary> public override void Shoot() { lock (this) { if (!CurrentWeaponConditionState.CanBeUsed || LastShot.AddSeconds((double)ShotRate) >= DateTime.UtcNow) { return; } LastShot = DateTime.UtcNow; var bulletsForAttack = Math.Min(IsBurstFireEngaged ? 3 : 1, AmmunitionContainer.AmmunitionCount); AmmunitionContainer.AmmunitionCount -= bulletsForAttack; switch (bulletsForAttack) { case 3: // Command would create gun fire sound, // bullets and sound, etc. These // could be done asynchronously. // Would prob be best to have M16 burst // fire shoot commands vs. single fire, etc. // for animation purposes instead of calling // ShootCommand 3 times here. ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); break; case 2: ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); break; case 1: ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); break; default: EmptyGunFireCommand.Execute(); break; } } }
/// <summary> /// The method to call to start a melee atack with the weapon. /// </summary> public override void Melee() { lock (this) { if (!CurrentWeaponConditionState.CanBeUsed || LastMelee.AddSeconds((double)MeleeRate) >= DateTime.UtcNow) { return; } LastMelee = DateTime.UtcNow; MeleeCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); } }