public static void SendStartAudioLoop(GameObject parent, string name, TankSoundKind tankSoundKind) { if (NetworkManager.singleton != null) { var msg = new SingedMessages.PlayAudioLoopMessage(); msg.parent = parent; msg.resourcePath = PrefabRegistry.GetResourceName <TankSoundKind>(tankSoundKind); msg.name = name; msg.start = true; NetworkManager.singleton.client.Send((short)SingedMessages.SingedMessageKind.playAudioLoop, msg); } }
private void PerformTerrainDeformation(GameObject terrain) { // perform terrain deformation (if terrain was hit) var terrainManager = terrain.GetComponent <TerrainDeformationManager>(); if (terrainManager != null) { var deformationPrefab = PrefabRegistry.singleton.GetPrefab <DeformationKind>(deformationKind); SingedMessages.SendPlayAudioClip( PrefabRegistry.GetResourceName <ProjectileSoundKind>(ProjectileSoundKind.projectile_explo)); //Debug.Log("CmdExplode instantiate deformation: " + deformationPrefab); GameObject deformation = Instantiate(deformationPrefab, gameObject.transform.position, Quaternion.identity) as GameObject; NetworkServer.Spawn(deformation); // determine deformation seed var seed = UnityEngine.Random.Range(1, 1 << 24); // execute terrain deformation on client terrainManager.RpcApplyDeform(deformation, seed); } }
public InputInstaller(PrefabRegistry prefabRegistry) => this.prefabRegistry = prefabRegistry;
public static void SendPlayAudioClip(TankSoundKind tankSoundKind) { SendPlayAudioClip(PrefabRegistry.GetResourceName <TankSoundKind>(tankSoundKind)); }
// ------------------------------------------------------ // SERVER-ONLY METHODS /// <summary> /// Generate explosion and apply damage for projectile /// </summary> void ServerExplode(Collision collision) { //Debug.Log("ServerExplode: " + this); // Get list of colliders in range of this explosion // FIXME: range of projectile shouldn't be hard-coded Collider[] flakReceivers = Physics.OverlapSphere(transform.position, effectRadius); // keep track of list of root objects already evaluated var hitList = new List <GameObject>(); foreach (Collider flakReceiver in flakReceivers) { var rootObject = flakReceiver.transform.root.gameObject; // has this object already been hit by this projectile? if (!hitList.Contains(rootObject)) { hitList.Add(rootObject); GameObject gameObjRef = flakReceiver.gameObject; //Debug.Log("hit gameObject: " + rootObject.name); // Debuff TankController tankObj = rootObject.GetComponent <TankController>(); if (tankObj != null) { tankObj.SetAreaOfEffect(areaOfEffect); } // potentially apply damage to any object that has health component var health = rootObject.GetComponent <Health>(); if (health != null) { //Debug.Log (rootObject.name + " received splash damage"); Vector3 cannonballCenterToTankCenter = transform.position - gameObjRef.transform.position; //Debug.Log (string.Format ("cannonball position: {0}, tank position: {1}", transform.position, gameObjRef.transform.position)); //Debug.Log (string.Format ("cannonballCenterToTankCenter: {0}", cannonballCenterToTankCenter)); // Some projectiles have AoE > 10, so damage radius needs to be clamped float hitDistToTankCenter = Mathf.Min(10f, cannonballCenterToTankCenter.magnitude); //Debug.Log ("Distance to tank center: " + hitDistToTankCenter); // NOTE: The damagePoints formula below is taken from an online quadratic regression calculator. The idea // was to plug in some values and come up with a damage computation formula. The above formula yields: // direct hit (dist = 0m): 100 hit points // Hit dist 5m: about 25 hit points // hit dist 10m: about 1 hit point // The formula is based on a max proximity damage distance of 10m int damagePoints = (int)(1.23f * hitDistToTankCenter * hitDistToTankCenter - 22.203f * hitDistToTankCenter + 100.012f); switch (myKind) { case ProjectileKind.cannonBall: damagePoints /= 2; break; case ProjectileKind.acorn: damagePoints = (int)(damagePoints * 1.5); break; case ProjectileKind.artilleryShell: if (tankObj != null && tankObj.hasVirus == false) { tankObj.InfectPlayer(rootObject); damagePoints = 20; } break; case ProjectileKind.mushboom: damagePoints += (int)(effectRadius * 0.5); break; } if (damagePoints > 0) { if (tankObj == null || !tankObj.hasControl) { health.TakeDamage(damagePoints, (shooter != null) ? shooter.gameObject : null); } else { health.RegisterDelayedDamage(damagePoints, (shooter != null) ? shooter.gameObject : null); } SingedMessages.SendPlayAudioClip( PrefabRegistry.GetResourceName <ProjectileSoundKind>(ProjectileSoundKind.tank_hit)); //Debug.Log ("Damage done to " + rootObject.name + ": " + damagePoints + ". Remaining: " + health.health); // Do shock displacement // if target has rigidbody, apply displacement force to rigidbody var rigidbody = rootObject.GetComponent <Rigidbody>(); if (rigidbody != null && rootObject.name != "mushMine(Clone)") { Vector3 displacementDirection = cannonballCenterToTankCenter.normalized; //Debug.Log (string.Format ("Displacement stats: direction={0}, magnitude={1}", displacementDirection, damagePoints)); rigidbody.AddForce(rigidbody.mass * (displacementDirection * damagePoints * 0.8f), ForceMode.Impulse); // Force = mass * accel } } } } } if (shooter != null) { shooter.GetComponent <Health>().TakeDelayedDamage(); } PerformTerrainDeformation(collision.gameObject); if (spawnMush) { LayMushMine(); } CreateExplosion(); }
public BulletInstaller(PrefabRegistry prefabRegistry) => bulletPrefab = prefabRegistry.bulletPrefab;