public void ServerSpawnWeapon(Server server, WeaponSpawnerState weaponSpawnerState) { if (weaponSpawnerState.TimeUntilNextSpawn > 0) { return; } var weaponDefinition = WeaponSystem.Instance.GetWeaponDefinitionByType(weaponSpawnerState.Type); var bulletsLeft = weaponDefinition.MaxAmmo / 2; var bulletsLeftInMagazine = Mathf.Min(weaponDefinition.BulletsPerMagazine, bulletsLeft); var weaponSpawnerComponent = FindWeaponSpawnerComponent(weaponSpawnerState.Id); var weaponObjectState = new WeaponObjectState { Id = server.GenerateNetworkId(), Type = weaponSpawnerState.Type, BulletsLeftInMagazine = (ushort)bulletsLeftInMagazine, BulletsLeftOutOfMagazine = (ushort)(bulletsLeft - bulletsLeftInMagazine), RigidBodyState = new RigidBodyState { Position = weaponSpawnerComponent.transform.position, EulerAngles = weaponSpawnerComponent.transform.eulerAngles, Velocity = Vector3.zero, AngularVelocity = Vector3.zero }, WeaponSpawnerId = weaponSpawnerState.Id }; SpawnLocalWeaponObject(weaponObjectState); }
public void ServerPlayerDropWeapon(Server server, PlayerObjectComponent playerObjectComponent, int weaponIndex) { var playerWeapons = playerObjectComponent.State.Weapons; var equippedWeaponState = playerWeapons[weaponIndex]; if ((equippedWeaponState == null)) { return; } var weaponObjectState = new WeaponObjectState { Id = server.GenerateNetworkId(), Type = equippedWeaponState.Type, BulletsLeftInMagazine = equippedWeaponState.BulletsLeftInMagazine, BulletsLeftOutOfMagazine = equippedWeaponState.BulletsLeftOutOfMagazine, RigidBodyState = new RigidBodyState { Position = playerObjectComponent.HandsPointObject.transform.position, EulerAngles = Vector3.zero, Velocity = Vector3.zero, AngularVelocity = Vector3.zero } }; WeaponSpawnerSystem.Instance.SpawnLocalWeaponObject(weaponObjectState); playerObjectComponent.State.Weapons[weaponIndex] = null; }
private EquippedWeaponState ToEquippedWeaponState(WeaponObjectState weaponObjectState) { return(new EquippedWeaponState { Type = weaponObjectState.Type, BulletsLeftInMagazine = weaponObjectState.BulletsLeftInMagazine, BulletsLeftOutOfMagazine = weaponObjectState.BulletsLeftOutOfMagazine, TimeSinceLastShot = weaponObjectState.Definition.ShotInterval }); }
private void ApplyStateFromServer(object newState) { var newWeaponObjectState = (WeaponObjectState)newState; Client.ApplyRigidbodyState( newWeaponObjectState.RigidBodyState, State.RigidBodyState, Rigidbody, OsFps.Instance.Client.ClientPeer.RoundTripTimeInSeconds ?? 0 ); State = newWeaponObjectState; }
public void ServerRemoveBullets(WeaponObjectState weaponObjectState, int numBulletsToRemove) { var bulletsToRemoveFromMagazine = Mathf.Min(weaponObjectState.BulletsLeftInMagazine, numBulletsToRemove); weaponObjectState.BulletsLeftInMagazine -= (ushort)bulletsToRemoveFromMagazine; numBulletsToRemove -= bulletsToRemoveFromMagazine; if (numBulletsToRemove > 0) { weaponObjectState.BulletsLeftOutOfMagazine -= (ushort)Mathf.Min( weaponObjectState.BulletsLeftOutOfMagazine, numBulletsToRemove ); } }
public GameObject SpawnLocalWeaponObject(WeaponObjectState weaponObjectState) { var weaponPrefab = WeaponSystem.Instance.GetWeaponDefinitionByType(weaponObjectState.Type).Prefab; var weaponObject = GameObject.Instantiate( weaponPrefab, weaponObjectState.RigidBodyState.Position, Quaternion.Euler(weaponObjectState.RigidBodyState.EulerAngles) ); var weaponObjectComponent = weaponObject.GetComponent <WeaponComponent>(); weaponObjectComponent.State = weaponObjectState; var rigidbody = weaponObjectComponent.Rigidbody; rigidbody.velocity = weaponObjectState.RigidBodyState.Velocity; rigidbody.angularVelocity = weaponObjectState.RigidBodyState.AngularVelocity; return(weaponObject); }