public override void InflictDamage(DamageZone damageZone, Projectiles.Projectile projectile, DamageParams param = default) { GunTurret turret = ((GameObject)param.oparam[0]).GetComponent <GunTurret>(); if (PenetrationCheck(projectile, turret.TurretArmor, Vector3.Angle(damageZone.Ship.transform.forward, projectile.transform.forward))) { // Penetration effects EffectManager.InitProjectilePenEffect(projectile); damageZone.Ship.Rigidbody.AddForceAtPosition(projectile.Velocity * projectile.FromTurret.GunsCaliber * damageZone.Ship.Armament.GunTurrets[0].ShipRecoil, projectile.GetPreviousPosition(), ForceMode.Impulse); // Destroy Turret turret.Disable(); } else { // Bounce effects EffectManager.InitProjectileBounceEffect(projectile); } }
public void SyncGames(MTSyncGame sync) { // Sync projectiles for (int i = 0; i < sync.NumProjectiles; i++) { Projectile p = FindProjectileByID(sync.ProjectileIDs[i]); if (p) { p.transform.position += (sync.ProjectilePositions[i] - p.transform.position) * 0.5f; p.transform.rotation = Quaternion.Lerp(p.transform.rotation, Quaternion.Euler(sync.ProjectileRotations[i]), 0.5f); p.Velocity = Vector3.Lerp(p.Velocity, sync.ProjectileVelocities[i], 0.5f); } else { Debug.LogWarning("Sync projectile: could not find id " + sync.ProjectileIDs[i]); } } // Sync ships uint waterIngressSectionsCounter = 0; uint gunTurretsCounter = 0; uint damageZoneCounter = 0; uint damageZoneDamagesCounter = 0; for (int i = 0; i < sync.NumShips; i++) { Ship s = FindShipByID(sync.ShipIDs[i]); bool counterUpdated = false; if (s != null && !s.Equals(null)) { if (sync.ShipsHitpoints[i] <= 0 && !s.Destroyed) { s.DamageHull(float.MaxValue); } else if (!s.Destroyed) { s.HullHitpoints = Mathf.Lerp(s.HullHitpoints, sync.ShipsHitpoints[i], 0.5f); s.transform.position += (sync.ShipPositions[i] - s.transform.position) * 0.5f; s.transform.rotation = Quaternion.Lerp(s.transform.rotation, Quaternion.Euler(sync.ShipRotations[i]), 0.5f); s.Velocity = Vector3.Lerp(s.Velocity, sync.ShipVelocities[i], 0.5f); for (byte waterIngressSectionIndex = 0; waterIngressSectionIndex < sync.ShipsNumWaterIngressSections[i]; waterIngressSectionIndex++) { Ship.WaterIngressSection section = s.WaterIngressSections.Find(wis => wis.sectionID == sync.WaterIngressSectionsIDs[waterIngressSectionsCounter]); section.numHoles = Mathf.CeilToInt(Mathf.Lerp(section.numHoles, sync.WaterIngressNumHoles[waterIngressSectionsCounter], 0.5f)); section.waterLevel = Mathf.Lerp(section.waterLevel, sync.WaterIngressWaterLevels[waterIngressSectionsCounter++], 0.5f); } if (s.PlayerTag != thisPlayerTag) { s.Autopilot.Chadburn = sync.ShipChadburnSettings[i]; s.Autopilot.Course = sync.ShipCourses[i]; if (sync.ShipsHasTarget[i]) { s.Targeting.Target = FindShipByID(sync.ShipsTargetShipID[i]); } else { s.Targeting.Target = null; } } for (byte gunTurretIndex = 0; gunTurretIndex < sync.ShipsNumGunTurrets[i]; gunTurretIndex++) { GunTurret t = s.Armament.GunTurrets.Find(gt => gt.ID == sync.GunTurretIDs[gunTurretsCounter]); if (sync.GunTurretsDisabled[gunTurretsCounter]) { t.Disable(); } t.ReloadProgress = Mathf.Lerp(t.ReloadProgress, sync.GunTurretsReloadProgress[gunTurretsCounter], 0.5f); t.TurretRotation = Mathf.Lerp(t.TurretRotation, sync.GunTurretsRotation[gunTurretsCounter], 0.5f); t.TargetTurretRotation = Mathf.Lerp(t.TargetTurretRotation, sync.GunTurretsTargetRotation[gunTurretsCounter], 0.5f); t.GunsElevation = Mathf.Lerp(t.GunsElevation, sync.GunTurretsElevation[gunTurretsCounter], 0.5f); t.TargetGunsElevation = Mathf.Lerp(t.TargetGunsElevation, sync.GunTurretsTargetElevation[gunTurretsCounter], 0.5f); t.StabilizationAngle = Mathf.Lerp(t.StabilizationAngle, sync.GunTurretsStabilizationAngle[gunTurretsCounter++], 0.5f); } for (byte damageZoneIndex = 0; damageZoneIndex < sync.ShipNumDamageZones[i]; damageZoneIndex++) { DamageZone dz = s.DamageZones.Find(sdz => sdz.ID == sync.ShipDamageZoneIDs[damageZoneCounter]); for (byte damageIndex = 0; damageIndex < sync.DamageZoneNumDamages[damageZoneCounter]; damageIndex++) { DamageType dt = sync.DamageZoneDamages[damageZoneDamagesCounter++]; if (!dz.Damages.Contains(dt)) { dz.Damages.Add(dt); } } damageZoneCounter++; } counterUpdated = true; } } else { Debug.LogWarning("Sync ship: could not find id " + sync.ShipIDs[i]); } // Update counter in case they did not get updated inside the ifs if (!counterUpdated) { waterIngressSectionsCounter += sync.ShipsNumWaterIngressSections[i]; gunTurretsCounter += sync.ShipsNumGunTurrets[i]; for (int k = 0; k < sync.ShipNumDamageZones[i]; k++) { damageZoneDamagesCounter += sync.DamageZoneNumDamages[damageZoneCounter]; damageZoneCounter++; } } } }