protected override void TakeDamage_RPC(string weaponDetailsJson) { Weapon.WeaponDamageDetails weaponDamageDetails = JsonUtility.FromJson <Weapon.WeaponDamageDetails>(weaponDetailsJson); lastHitDetails = weaponDamageDetails; float amount = weaponDamageDetails.damage; if (health > 0 && weaponDamageDetails.sourceTeamId != npv.teamId) { health -= amount; if (health > maxHealth) { health = maxHealth; } SetSmoke(); if (health <= 0 && !isDead && myPhotonView.IsMine) { // die is only called once, by the driver isDead = true; Die(true, true); // do death effects for all other players // TODO- update to take damage type parameter myPhotonView.RPC(nameof(PlayDeathEffects_RPC), RpcTarget.All); } } }
public virtual void TakeDamage(Weapon.WeaponDamageDetails hitDetails) { // call take damage on everyone else's instance of the game string hitDetailsJson = JsonUtility.ToJson(hitDetails); myPhotonView.RPC(nameof(TakeDamage_RPC), RpcTarget.All, hitDetailsJson); }
protected void ChargeDriverAbility(Weapon.WeaponDamageDetails hitDetails) { int sourceTeamId = hitDetails.sourceTeamId; Transform sourceTransform = playerTransformTracker.GetVehicleTransformFromTeamId(sourceTeamId); // now add damage dealt back to the source transform driver ability manager GunnerWeaponManager gunnerWeaponManager = sourceTransform.GetComponentInChildren <GunnerWeaponManager>(); // adjust damage dealth modifier gunnerWeaponManager.UpdateDamageDealt(hitDetails); }
public void UpdateDamageDealt(Weapon.WeaponDamageDetails hitDetails) { // only let the gunner update this if (hitDetails.sourcePlayerId == gunnerId) { gunnerDamageDealt += hitDetails.damage; // Debug.Log("update damage dealt"); } }
protected virtual void TakeDamage_RPC(string weaponDetailsJson) { Weapon.WeaponDamageDetails weaponDamageDetails = JsonUtility.FromJson <Weapon.WeaponDamageDetails>(weaponDetailsJson); lastHitDetails = weaponDamageDetails; float amount = weaponDamageDetails.damage; if (health > 0) { health -= amount; if (health <= 0 && !isDead && myPhotonView.IsMine) { // die is only called once, by the driver Die(); } } }
public void SetupVehicleManager() { // Debug.LogWarning("Vehicle Health Manager has not been fully ported to the new PhysX system"); gamestateTracker = FindObjectOfType <GamestateTracker>(); gamestateTrackerPhotonView = gamestateTracker.GetComponent <PhotonView>(); networkManager = FindObjectOfType <NetworkManager>(); maxHealth = health; rb = GetComponent <PhysXRigidBody>(); icd = GetComponent <InterfaceCarDrive>(); icd4 = GetComponent <InterfaceCarDrive4W>(); carDriver = icd.GetComponent <IDrivable>(); inputDriver = GetComponent <InputDriver>(); myPhotonView = GetComponent <PhotonView>(); npv = GetComponent <NetworkPlayerVehicle>(); announcerManager = FindObjectOfType <AnnouncerManager>(); _rammingDetails = new Weapon.WeaponDamageDetails(null, 0, 0, Weapon.DamageType.ramming, 0, Vector3.zero); for (int i = 0; i < collisionAreas.Count; i++) { CollisionArea collisionArea = collisionAreas[i]; collisionArea.rotation.eulerAngles = collisionArea.rotationEuler; collisionAreas[i] = collisionArea; } defaultDrag = rb.linearDamping; defaultAngularDrag = rb.angularDamping; playerTransformTracker = FindObjectOfType <PlayerTransformTracker>(); PlayerEntry player = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); if (player.teamId == teamId) { tutorials.SetActive(true); } else { tutorials.SetActive(false); } player.Release(); }
public void CollisionEnter(PhysXCollision collision) { // Debug.Log("crashed into: " + collision.gameObject); float dSpeed = myRb.velocity.magnitude; float impulse = collision.impulse.magnitude; if (collision.rigidBody != null) { dSpeed = (myRb.velocity - collision.rigidBody.velocity).magnitude; } if (myPhotonView.IsMine && collision.contactCount > 0 && dSpeed > 1.5 && collisionTimer < 0) { collisionTimer = maxCollisionRate; Vector3 collisionNormal = collision.GetContact(0).normal; Vector3 collisionForce = collision.impulse; if (Vector3.Dot(collisionForce, collisionNormal) < 0) { collisionForce = -collisionForce; } collisionForce /= Time.fixedDeltaTime; collisionForce = transform.InverseTransformDirection(collisionForce); VehicleHealthManager otherVehicleManager = collision.gameObject.GetComponent <VehicleHealthManager>(); Vector3 collisionPoint = Vector3.zero; for (int i = 0; i < collision.contactCount; i++) { collisionPoint += collision.GetContact(i).point; } collisionPoint /= collision.contactCount; Vector3 contactDirection = transform.InverseTransformPoint(collisionPoint); float damage = CalculateCollisionDamage(collisionForce, contactDirection, otherVehicleManager != null); // instantiate damage sound over network if ((damage > crashSoundsSmallDamageThreshold || (otherVehicleManager != null)) && timeSinceLastRam > 0.25f) { PlayDamageSoundNetwork(damage); } damage = damage / rammingDamageResistance; if (myPhotonView.IsMine && hasHotPotatoManager && otherVehicleManager != null && timeSinceLastRam > 0.25f) { if (collisionNpv.GetDriverID() == PhotonNetwork.LocalPlayer.ActorNumber || collisionNpv.GetGunnerID() == PhotonNetwork.LocalPlayer.ActorNumber) { // Debug.LogError("Slow down should happen"); hotPotatoManager.SlowedCollision(); } if (collisionSparks != null) { GameObject a = Instantiate(collisionSparks, collisionPoint, Quaternion.identity); a.transform.parent = transform; } if (collisionNpv != null && !collisionNpv.botDriver) { if (damage > 4) { driverCrashDetector.CrashCollisionCamera(collision, false); } else { driverCrashDetector.CrashCollisionCamera(collision, true); } } } if (damage > 5) { if (otherVehicleManager != null) { if (otherVehicleManager != null) { damage *= otherVehicleManager.rammingDamageMultiplier; } Weapon.WeaponDamageDetails rammingDetails = otherVehicleManager.rammingDetails; rammingDetails.damage = damage; if (markedByTeams.Contains(rammingDetails.sourceTeamId)) { rammingDetails.damage *= markedTeamDamageIncrease; } TakeDamage(rammingDetails); } else { TakeDamage(damage); } } } if (collision.rigidBody != null) { timeSinceLastRam = 0f; } }
public void SetWeaponDamageDetails(Weapon.WeaponDamageDetails wdd) { weaponDamageDetails = wdd; }