static bool Prefix(TurretTop __instance, Vector3 recoilDrawOffset, float recoilAngleOffset, float ___curRotationInt, Building_Turret ___parentTurret) { Building_LaserGun turret = ___parentTurret as Building_LaserGun; if (turret == null) { return(true); } float rotation = ___curRotationInt; if (turret.TargetCurrentlyAimingAt.HasThing) { rotation = (turret.TargetCurrentlyAimingAt.CenterVector3 - turret.TrueCenter()).AngleFlat(); } IDrawnWeaponWithRotation gunRotation = turret.gun as IDrawnWeaponWithRotation; if (gunRotation != null) { rotation += gunRotation.RotationOffset; } Material material = ___parentTurret.def.building.turretTopMat; SpinningLaserGunTurret spinningGun = turret.gun as SpinningLaserGunTurret; if (spinningGun != null) { spinningGun.turret = turret; material = spinningGun.Graphic.MatSingle; } Vector3 offset = new Vector3(___parentTurret.def.building.turretTopOffset.x, 0f, ___parentTurret.def.building.turretTopOffset.y).RotatedBy(___curRotationInt); float scale = ___parentTurret.def.building.turretTopDrawSize; offset = offset.RotatedBy(recoilAngleOffset); offset += recoilDrawOffset; Matrix4x4 Matrix = default(Matrix4x4); Matrix.SetTRS(___parentTurret.DrawPos + Altitudes.AltIncVect + offset, (___curRotationInt + (float)TurretTop.ArtworkRotation).ToQuat(), new Vector3(scale, 1f, scale)); Graphics.DrawMesh(MeshPool.plane10, Matrix, material, 0); return(false); }
static bool Prefix(TurretTop __instance) { Building_LaserGun turret = parentTurretField.GetValue(__instance) as Building_LaserGun; if (turret == null) { return(true); } float rotation = (float)curRotationIntField.GetValue(__instance); if (turret.TargetCurrentlyAimingAt.HasThing) { rotation = (turret.TargetCurrentlyAimingAt.CenterVector3 - turret.TrueCenter()).AngleFlat(); } IDrawnWeaponWithRotation gunRotation = turret.gun as IDrawnWeaponWithRotation; if (gunRotation != null) { rotation += gunRotation.RotationOffset; } Material material = turret.def.building.turretTopMat; SpinningLaserGunTurret spinningGun = turret.gun as SpinningLaserGunTurret; if (spinningGun != null) { spinningGun.turret = turret; material = spinningGun.Graphic.MatSingle; } Vector3 b = new Vector3(turret.def.building.turretTopOffset.x, 0f, turret.def.building.turretTopOffset.y); float turretTopDrawSize = turret.def.building.turretTopDrawSize; Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(turret.DrawPos + Altitudes.AltIncVect + b, rotation.ToQuat(), new Vector3(turretTopDrawSize, 1f, turretTopDrawSize)); Graphics.DrawMesh(MeshPool.plane10, matrix, material, 0); return(false); }
protected override void Impact(Thing hitThing) { bool shielded = hitThing.IsShielded() && def.IsWeakToShields; LaserGunDef defWeapon = equipmentDef as LaserGunDef; Vector3 dir = (destination - origin).normalized; dir.y = 0; Vector3 a = origin + dir * (defWeapon == null ? 0.9f : defWeapon.barrelLength); Vector3 b = shielded ? hitThing.TrueCenter() - dir.RotatedBy(Rand.Range(-22.5f, 22.5f)) * 0.8f : destination; a.y = b.y = def.Altitude; SpawnBeam(a, b); bool createsExplosion = this.def.projectile.explosionRadius > 0f; if (createsExplosion) { this.Explode(hitThing, false); GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, this.def.projectile.damageDef, this.launcher.Faction); } Pawn pawn = launcher as Pawn; IDrawnWeaponWithRotation weapon = null; if (pawn != null && pawn.equipment != null) { weapon = pawn.equipment.Primary as IDrawnWeaponWithRotation; } if (weapon == null) { Building_LaserGun turret = launcher as Building_LaserGun; if (turret != null) { weapon = turret.gun as IDrawnWeaponWithRotation; } } if (weapon != null) { float angle = (b - a).AngleFlat() - (intendedTarget.CenterVector3 - a).AngleFlat(); weapon.RotationOffset = (angle + 180) % 360 - 180; } if (hitThing == null) { TriggerEffect(def.explosionEffect, destination); bool flag2 = this.def.causefireChance > 0f && Rand.Chance(this.def.causefireChance); if (flag2) { FireUtility.TryStartFireIn(destination.ToIntVec3(), pawn.Map, 0.05f); } } else { if (hitThing is Pawn) { Pawn hitPawn = hitThing as Pawn; if (shielded) { weaponDamageMultiplier *= def.shieldDamageMultiplier; SpawnBeamReflections(a, b, 5); } } bool flag2 = this.def.causefireChance > 0f && Rand.Range(0f, 1f) > this.def.causefireChance; if (flag2) { hitThing.TryAttachFire(0.05f); } TriggerEffect(def.explosionEffect, ExactPosition); } if (def.HediffToAdd != null) { AddedEffect(hitThing); } Map map = base.Map; base.Impact(hitThing); BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef); Find.BattleLog.Add(battleLogEntry_RangedImpact); if (hitThing != null) { DamageDef damageDef = this.def.projectile.damageDef; float amount = DamageAmount; float armorPenetration = ArmorPenetration; float y = this.ExactRotation.eulerAngles.y; Thing launcher = this.launcher; ThingDef equipmentDef = this.equipmentDef; DamageInfo dinfo = new DamageInfo(damageDef, amount, armorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing); hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact); Pawn hitPawn = hitThing as Pawn; if (hitPawn != null && hitPawn.stances != null && hitPawn.BodySize <= this.def.projectile.StoppingPower + 0.001f) { hitPawn.stances.StaggerFor(95); } } else { SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false)); MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f); if (base.Position.GetTerrain(map).takeSplashes) { MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f); } } }