/// applying impact damage from the explosion to enemies private void ApplyDamage() { List <PhotonPlayer> playersInRange = this.GetPlayersInRange(); foreach (PhotonPlayer player in playersInRange) { GameObject p = FindPhotonPlayer(player); if (p != null) { bl_PlayerDamageManager pdm = p.transform.root.GetComponent <bl_PlayerDamageManager>(); bl_OnDamageInfo odi = new bl_OnDamageInfo(); odi.mDamage = CalculatePlayerDamage(player); odi.mDirection = this.transform.position; odi.mFrom = PhotonNetwork.player.name; odi.mHeatShot = false; odi.mWeapon = WeaponName; odi.mWeaponID = WeaponID; odi.mActor = PhotonNetwork.player; pdm.GetDamage(odi); } else { Debug.LogError("This Player " + player.name + " is not found"); } } }
/// <summary> /// /// </summary> private void OnTriggerEnter(Collider other) { if (other.transform.CompareTag(bl_PlayerSettings.LocalTag)) { bl_PlayerDamageManager pdm = other.transform.GetComponent <bl_PlayerDamageManager>(); if (pdm != null) { if (m_Type == AreaType.Repeting) { if (isPlayerCaused) { cacheInformation.Direction = transform.position; int gi = bl_GameData.Instance.GetWeaponID("Molotov"); if (gi > 0) { cacheInformation.GunID = gi; } pdm.DoRepetingDamage(Damage, 1, cacheInformation); AllHitted.Add(pdm); } else { pdm.DoRepetingDamage(Damage, 1); } } else if (m_Type == AreaType.OneTime) { DamageData info = new DamageData(); info.Damage = Damage; info.Direction = transform.position; info.Cause = DamageCause.Fire; pdm.GetDamage(info); } } } else if (other.transform.CompareTag("AI") && !isNetwork) { if (isPlayerCaused) { bl_AIShooterHealth ash = other.transform.root.GetComponent <bl_AIShooterHealth>(); if (ash != null) { if (!AIHitted.Contains(ash)) { cacheInformation.Direction = transform.position; int gi = bl_GameData.Instance.GetWeaponID("Molotov"); if (gi > 0) { cacheInformation.GunID = gi; } ash.DoRepetingDamage(Damage, 1, cacheInformation); AIHitted.Add(ash); } } } } }
/// <summary> /// Use this for receive damage local and sync for all other /// </summary> public void GetDamage(float damage, string t_from, DamageCause cause, Vector3 direction, int weapon_ID = 0) { float m_TotalDamage = damage + multiplier; DamageData e = new DamageData(); e.Damage = m_TotalDamage; e.Direction = direction; e.Cause = cause; e.isHeadShot = TakeHeatShot; e.GunID = weapon_ID; e.From = t_from; if (HealtScript != null) { HealtScript.GetDamage(e); } }
public bool TakeHeatShot = false; // Is it the head? /// Use this for recive damage local and sync for all other public void GetDamage(float t_damage, string t_from, string t_weapon, Vector3 t_direction, int weapon_ID = 0) { float m_TotalDamage = t_damage + multiplier; bl_OnDamageInfo e = new bl_OnDamageInfo(); e.mDamage = m_TotalDamage; e.mDirection = t_direction; e.mWeapon = t_weapon; e.mHeatShot = TakeHeatShot; e.mWeaponID = weapon_ID; e.mFrom = t_from; if (HealtScript != null) { HealtScript.GetDamage(e); } }
/// <summary> /// /// </summary> void Attack() { if (Time.time > attackTime) { bl_PlayerDamageManager pdm = Target.root.GetComponent <bl_PlayerDamageManager>(); if (pdm != null) { bl_OnDamageInfo di = new bl_OnDamageInfo(); di.mActor = null; di.mDamage = Damage; di.mDirection = this.transform.position; di.mFrom = "AI"; pdm.GetDamage(di); attackTime = Time.time + AttackRate; Debug.Log("Send Damage!"); } else { Debug.Log("Can't found pdm in: " + Target.gameObject.name); } } }
/// <summary> /// applying impact damage from the explosion to enemies /// </summary> private void DoDamage() { if (m_Type == ExplosionType.Shake || !bl_GameData.Instance.ArriveKitsCauseDamage) { return; } List <Player> playersInRange = this.GetPlayersInRange(); if (playersInRange != null && playersInRange.Count > 0) { foreach (Player player in playersInRange) { if (player != null) { GameObject p = FindPhotonPlayer(player); if (p != null) { bl_PlayerDamageManager pdm = p.transform.root.GetComponent <bl_PlayerDamageManager>(); DamageData odi = new DamageData(); odi.Damage = CalculatePlayerDamage(p.transform, player); odi.Direction = transform.position; odi.From = (isFromBot) ? BotName : PhotonNetwork.LocalPlayer.NickName; odi.isHeadShot = false; odi.Cause = (isFromBot) ? DamageCause.Bot : DamageCause.Explosion; odi.GunID = WeaponID; odi.Actor = PhotonNetwork.LocalPlayer; pdm.GetDamage(odi); } else { Debug.LogError("This Player " + player.NickName + " is not found"); } } } } Collider[] colls = Physics.OverlapSphere(transform.position, explosionRadius); List <string> Hited = new List <string>(); foreach (Collider c in colls) { if (c.CompareTag("AI")) { if (Hited.Contains(c.transform.root.name)) { continue; } int damage = CalculatePlayerDamage(c.transform.root, null); Hited.Add(c.transform.root.name); Team t = (isFromBot) ? AITeam : PhotonNetwork.LocalPlayer.GetPlayerTeam(); if (c.GetComponent <bl_AIShooterHealth>() != null && !isNetwork) { c.GetComponent <bl_AIShooterHealth>().DoDamage(damage, "[Explode]", transform.position, AIViewID, isFromBot, t, false); } else if (c.GetComponent <bl_AIHitBox>() != null && !isNetwork) { c.GetComponent <bl_AIHitBox>().DoDamage(damage, "[Explode]", transform.position, AIViewID, isFromBot, t); } } } }
void OnHit(RaycastHit hit) { GameObject go = null; Ray mRay = new Ray(transform.position, transform.forward); if (!isNetwork) { if (hit.rigidbody != null && !hit.rigidbody.isKinematic) // if we hit a rigi body... apply a force { float mAdjust = 1.0f / (Time.timeScale * (0.02f / Time.fixedDeltaTime)); hit.rigidbody.AddForceAtPosition(((mRay.direction * impactForce) / Time.timeScale) / mAdjust, hit.point); } } switch (hit.transform.tag) // decide what the bullet collided with and what to do with it { case "Projectile": // do nothing if 2 bullets collide break; case "BodyPart": //Send Damage for other players if (hit.transform.GetComponent <bl_BodyPart>() != null && !isNetwork) { hit.transform.GetComponent <bl_BodyPart>().GetDamage(damage, PhotonNetwork.NickName, DamageCause.Player, DirectionFrom, OwnGunID); } if (bl_GameData.Instance.ShowBlood) { go = bl_ObjectPooling.Instance.Instantiate("blood", hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); go.transform.parent = hit.transform; } Disable(); break; case "AI": //Send Damage for other players bool bot = !string.IsNullOrEmpty(AIFrom); Team t = (bot) ? AITeam : PhotonNetwork.LocalPlayer.GetPlayerTeam(); if (!string.IsNullOrEmpty(AIFrom) && AIFrom == hit.transform.root.name) { return; } if (hit.transform.GetComponent <bl_AIShooterHealth>() != null && !isNetwork) { hit.transform.GetComponent <bl_AIShooterHealth>().DoDamage((int)damage, GunName, DirectionFrom, AIViewID, bot, t, false); } else if (hit.transform.GetComponent <bl_AIHitBox>() != null && !isNetwork) { hit.transform.GetComponent <bl_AIHitBox>().DoDamage((int)damage, GunName, DirectionFrom, AIViewID, bot, t); } go = bl_ObjectPooling.Instance.Instantiate("blood", hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); go.transform.parent = hit.transform; Disable(); break; case "Player": bl_PlayerDamageManager pdm = hit.transform.GetComponent <bl_PlayerDamageManager>(); if (pdm != null && !isNetwork && !string.IsNullOrEmpty(AIFrom)) { if (!isOneTeamMode) { if (pdm.GetComponent <bl_PlayerSettings>().m_Team == AITeam) //if hit a team mate player { Disable(); return; } } DamageData info = new DamageData(); info.Actor = null; info.Damage = damage; info.Direction = DirectionFrom; info.From = AIFrom; info.Cause = DamageCause.Bot; info.GunID = OwnGunID; pdm.GetDamage(info); Disable(); } break; case "Wood": hitCount++; // add another hit to counter go = bl_ObjectPooling.Instance.Instantiate("decalw", hit.point, Quaternion.LookRotation(hit.normal)); go.transform.parent = hit.transform; break; case "Concrete": hitCount += 2; // add 2 hits to counter... concrete is hard go = bl_ObjectPooling.Instance.Instantiate("decalc", hit.point, Quaternion.LookRotation(hit.normal)); go.transform.parent = hit.transform; break; case "Metal": hitCount += 3; // metal slows bullets alot go = bl_ObjectPooling.Instance.Instantiate("decalm", hit.point, Quaternion.LookRotation(hit.normal)); go.transform.parent = hit.transform; break; case "Dirt": hasHit = true; // ground kills bullet go = bl_ObjectPooling.Instance.Instantiate("decals", hit.point, Quaternion.LookRotation(hit.normal)); go.transform.parent = hit.transform; break; case "Water": hasHit = true; // water kills bullet go = bl_ObjectPooling.Instance.Instantiate("decalwt", hit.point, Quaternion.LookRotation(hit.normal)); go.transform.parent = hit.transform; break; default: hitCount++; // add a hit go = bl_ObjectPooling.Instance.Instantiate("decal", hit.point, Quaternion.LookRotation(hit.normal)); go.transform.parent = hit.transform; break; } Disable(); }