private void ApplyDamageStat(BaseStats bs, int dmg, float dist, float rad) { if (dmg <= 0 && !isEMP) { return; } PlayerVitals playerPV = bs.GetComponent <PlayerVitals>(); if (bs.isLocalPlayer && playerPV != null) { playerPV.HitIndicator(transform.position); if (isEMP) { playerPV.pe.StartPhase_EMP(); } else if (explosionCameraEffect) { playerPV.pe.ExplosionVisualEffect(1.05f - Mathf.Clamp01((dist * 1.35f) / rad)); } } bool showHitMarker = false; if (isPlayer && !bs.isLocalPlayer && wManager != null && bs.curHealth > 0) { showHitMarker = true; } if (Topan.Network.isConnected) { Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>(); if (damageView != null && !(isPlayer && bs.isLocalPlayer)) { bool canDamage = true; BotVitals hitBot = bs.GetComponent <BotVitals>(); byte ownerTeam = (isPlayer || botIndex <= -1) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team; byte targetTeam = /*(hitBot != null) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team :*/ (byte)damageView.owner.GetPlayerData("team", (byte)0); if (GeneralVariables.gameModeHasTeams) { if (targetTeam == ownerTeam) { canDamage = friendlyFire; showHitMarker = false; } } else { } /* * if((hitBot != null && botIndex > -1 && hitBot.bm.myIndex == botIndex)) { * canDamage = true; * }*/ if (canDamage) { damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)dmg, (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, GetTrueID(), (grenIndex > -1) ? (byte)255 : (byte)4); } if (isEMP && !hitBot) { damageView.RPC(Topan.RPCMode.Owner, "NetworkEMP"); } } else { bs.headshot = false; bs.ApplyDamageMain(dmg, true); } } else { bs.headshot = false; bs.ApplyDamageMain(dmg, true); } if (showHitMarker) { wManager.HitTarget(bs.curHealth <= 0); } }
private void OnHit(RaycastHit hit) { ricochetValue++; float limbForceMult = 1f; travelDist += hit.distance; bool ignoreBulletHole = false; if (!isVisuals) { bs = hit.collider.GetComponent <BaseStats>(); lb = hit.collider.GetComponent <Limb>(); damage = Mathf.RoundToInt(damage * dmgCurve.Evaluate(travelDist)); if (damage > 0) { if (bs != null) { bool hitMarkerEnabled = false; if (player && wManager != null && bs.curHealth > 0 && bs.hitIndication) { hitMarkerEnabled = true; } bool canDamage = true; bs.headshot = false; if (Topan.Network.isConnected) { Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>(); if (damageView != null && damage > 0) { BotVitals hitBot = bs.GetComponent <BotVitals>(); if (GeneralVariables.gameModeHasTeams) { byte ownerTeam = (player) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team; byte targetTeam = /* (hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0); if (targetTeam == ownerTeam) { if (!friendlyFire) { canDamage = false; } hitMarkerEnabled = false; } } else { } if (canDamage) { if (isServer && (damageView.ownerID == 0 || hitBot)) { bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)4); } else { damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)4); } } } else { bs.ApplyDamageMain(damage, true); } } else { bs.ApplyDamageMain(damage, true); } if (hitMarkerEnabled) { wManager.HitTarget(bs.curHealth <= 0); } if (canDamage) { PlayerVitals playerPV = bs.GetComponent <PlayerVitals>(); if (bs.isLocalPlayer && playerPV != null) { playerPV.HitIndicator(startPos); } } } else if (lb != null && lb.rootStats != null) { bs = lb.rootStats; lb.ragdollVelocity = tr.forward * force * limbForceMult; damage = Mathf.RoundToInt(damage * lb.realDmgMult); bool hitMarkerEnabled = false; if (player && wManager != null && bs.curHealth > 0 && bs.hitIndication) { hitMarkerEnabled = true; } bs.headshot = (lb.limbType == Limb.LimbType.Head); if (Topan.Network.isConnected) { Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>(); if (damageView != null) { BotVitals hitBot = bs.GetComponent <BotVitals>(); bool canDamage = true; if (GeneralVariables.gameModeHasTeams) { byte ownerTeam = (player || botIndex <= -1) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team; byte targetTeam = /*(hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0); if (targetTeam == ownerTeam) { if (!friendlyFire) { canDamage = false; } hitMarkerEnabled = false; } } else { } if (canDamage) { if (isServer && (damageView.ownerID == 0 || hitBot)) { bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)lb.limbType); } else { damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)lb.limbType); } } } else { bs.ApplyDamageMain(damage, true); } } else { bs.ApplyDamageMain(damage, true); } limbForceMult = 3f; if (hitMarkerEnabled) { wManager.HitTarget(bs.curHealth <= 0); } } } } bulletHoleIndex = 0; hitEffectIndex = 0; string hitTag = hit.collider.tag; if (hitTag == "Dirt") { hitEffectIndex = 1; } else if (hitTag == "Metal") { hitEffectIndex = 2; } else if (hitTag == "Wood") { hitEffectIndex = 3; } else if (hitTag == "Flesh" || hitTag == "Player - Flesh") { bulletHoleIndex = -1; hitEffectIndex = 4; } else if (hitTag == "Water") { bulletHoleIndex = -1; hitEffectIndex = 5; } Quaternion rot = Quaternion.LookRotation(hit.normal); if (bulletHoleIndex >= 0 && !ignoreBulletHole) { Transform hole = PoolManager.Instance.RequestInstantiate(bulletHoles[bulletHoleIndex], hit.point + (hit.normal * 0.01f), rot).transform; if (!hit.collider.gameObject.isStatic && hit.rigidbody) { hole.KeepUniformScale(hit.transform); } float randomSize = Random.Range(bulletDecalSize.x, bulletDecalSize.y); hole.localScale = new Vector3(randomSize, randomSize, 1f); Vector3 euler = hole.localEulerAngles; euler.z = Random.value * 360f; hole.localEulerAngles = euler; DecalObject dObj = hole.GetChild(0).GetComponent <DecalObject>(); dObj.targetObject = hit.collider.gameObject; dObj.UpdateDecalMesh(); } PoolManager.Instance.RequestParticleEmit(hitEffectIndex, hit.point + (hit.normal * 0.06f), rot); Rigidbody rigid = hit.rigidbody; if ((lb == null || (lb != null && (lb.rootStats == null || lb.rootStats.curHealth <= 0))) && rigid != null && !rigid.isKinematic) { rigid.AddForce(tr.forward * force * limbForceMult, ForceMode.Impulse); } if (ricochetAmount > 0 && ricochetValue <= ricochetAmount) { if (Vector3.Angle(dir, hit.normal) - 90f <= ricochetAngle) { tr.rotation = Quaternion.LookRotation(Vector3.Reflect(dir, hit.normal)); speed *= 0.75f; damage = Mathf.RoundToInt(damage * Random.Range(0.5f, 0.6f)); gravityVector *= 0.5f; tr.position += tr.forward * speed * Time.deltaTime; newPos = tr.position; } else { AddToPool(); } } if (smokeInstance != null) { smokeInstance.SetPosition(1, hit.point); smokeInstance = null; } if (currentWhiz != null) { currentWhiz.transform.parent = null; currentWhiz.transform.position = hit.point; currentWhiz = null; noWhizSound = false; } tracer.SetActive(false); glow.SetActive(false); AddToPool(); }