void OnMobDies(GameObject killer, GameObject hitter = null) { if (isDead == true) { return; } //Debug.Log ("Mob has died!"); if (this.GetComponent <PlayerControlScript>() != null) { //Only act if we're the owner if (this.GetComponent <PlayerControlScript>().GetOwner() == Network.player) { //Object is a player, apply special rules Debug.Log("[HealthScript]: Player has died!"); Debug.Log("[HealthScript]: Alerting GameController..."); GameObject.FindGameObjectWithTag("GameController").GetComponent <GameStateController>().NotifyLocalPlayerHasDied(this.gameObject); //networkView.RPC ("PropagatePlayerDeath", RPCMode.Others); Debug.Log("[HealthScript]: Destroying object..."); networkView.RPC("PropagateEntityDied", RPCMode.All); //Use this to fix crashes //this.gameObject.SetActive(false); } else { //Tell the client that it's dead networkView.RPC("PropagatePlayerHasJustDied", this.GetComponent <PlayerControlScript>().GetOwner()); networkView.RPC("PropagateEntityDied", RPCMode.All); } } else if (this.tag == "Capital") { //Capital ship has been destroyed, game over //m_GameStateController.GetComponent<GameStateController>().CapitalShipHasBeenDestroyed(); if (Network.isServer) { m_GameStateController.GetComponent <GameStateController>().TellAllClientsCapitalShipHasBeenDestroyed(); //Network.Destroy(this.gameObject); } //Animate destruction, pause game, splash text? //TODO: Zoom to capital, long death animation, sounds + then overlay, nauts style } else if (this.tag == "Enemy") { //If this mob isn't a player, apply bounty to killer (if pc) and destroy mob if (killer && killer.transform.root.GetComponent <PlayerControlScript>() != null) { killer.transform.root.GetComponent <PlayerControlScript>().AddSpaceBucks(this.GetComponent <EnemyScript>().GetBounty()); } if (Network.isServer) { networkView.RPC("PropagateEntityDied", RPCMode.All); } if (m_DeathObjectRef != null) { Network.Instantiate(m_DeathObjectRef, this.transform.position, this.transform.rotation, 0); } } else if (this.tag == "Asteroid") { if (hitter) { BeamBulletScript beam = hitter.GetComponent <BeamBulletScript>(); if (beam) { GetComponent <AsteroidScript>().SplitAsteroid(beam.beamHit.point); } else { GetComponent <AsteroidScript>().SplitAsteroid(hitter.transform); } } else { GetComponent <AsteroidScript>().SplitAsteroid(transform); } } else if (this.tag == "Bullet") { //Tell the bullet to explode if it has AoE this.GetComponent <BasicBulletScript>().DetonateBullet(); } }
public void DamageMob(int damage, GameObject firer, GameObject hitter = null) { //Debug.Log ("Damaging mob: " + this.name + "."); if (!m_isInvincible) { if (m_currentShield > 0) { //If shields are up, apply damage to the shield m_currentShield -= damage; if (m_currentShield <= 0) { ShieldOnOff(false); //if the shield gives out before all the damage is dealt, apply the remainder to the hull m_currentHealth += m_currentShield; if (m_currentHealth <= 0) { //Mob is dead :( OnMobDies(firer, hitter); } m_currentShield = 0; } if (hitter) { BeamBulletScript beam = hitter.GetComponent <BeamBulletScript>(); Vector3 position = beam ? beam.beamHit.point : hitter.transform.position; int dType = beam ? (int)beam.m_damageType : (int)hitter.GetComponent <BasicBulletScript>().m_damageType; float magnitude = beam ? beam.GetDamage() : hitter.GetComponent <BasicBulletScript>().GetDamage(); networkView.RPC("PropagateShieldWibble", RPCMode.All, position, dType, magnitude); } } else { //If no shields, apply damage directly to hull m_currentHealth -= damage; if (m_currentHealth <= 0) { //Mob is dead :( OnMobDies(firer, hitter); } } if (Network.isServer) { //If we're host, propagate the damage to the rest of the clients try { networkView.RPC("PropagateDamage", RPCMode.Others, m_currentHealth, m_currentShield); } catch (UnityException e) {} //Tell gamecontroller the capital ship is under attack if (this.tag == "Capital") { if (firer != null && firer.tag != "Asteroid") { m_GameStateController.GetComponent <GameStateController>().CapitalShipHasTakenDamage(); } } if (this.tag == "Enemy") { if (firer != null && firer.tag != "Asteroid") { if (GetHPPercentage() < 0.3f) { //Alert enemy it's dying and should kamikaze //Debug.Log("Enemy: " + this.name + " is enraged!"); this.GetComponent <EnemyScript>().AlertLowHP(firer); } else if (!hasBeenHitAlready) { hasBeenHitAlready = true; this.GetComponent <EnemyScript>().AlertFirstHit(firer); } else { this.GetComponent <EnemyScript>().NotifyEnemyUnderFire(firer); } } } } //Whatever happens, reset the shield cooldown ResetShieldRecharge(); } }