public static Vector3 MuzzlePosition(Vector3 DrawPos, Verb_LaunchProjectile instance, Thing equipment, Thing launcher) { Vector3 result = DrawPos; if (equipment == null || !AMAMod.settings.AllowMuzzlePosition) { return(result); } Vector3 destination = instance.CurrentTarget.Cell.ToVector3Shifted(); float aimAngle = 0f; if ((destination - result).MagnitudeHorizontalSquared() > 0.001f) { aimAngle = (destination - result).AngleFlat(); } IDrawnWeaponWithRotation rotation = equipment as IDrawnWeaponWithRotation; if (rotation != null) { // Log.Message(gunOG + " is IDrawnWeaponWithRotation with RotationOffset: "+ gunOG.RotationOffset); aimAngle += rotation.RotationOffset; } if (equipment.def.HasComp(typeof(OgsCompOversizedWeapon.CompOversizedWeapon))) { OgsCompOversizedWeapon.CompOversizedWeapon compOversized = equipment.TryGetCompFast <OgsCompOversizedWeapon.CompOversizedWeapon>(); if (compOversized != null) { bool DualWeapon = compOversized.Props != null && compOversized.Props.isDualWeapon; Vector3 offsetMainHand = default(Vector3); Vector3 offsetOffHand = default(Vector3); float offHandAngle = aimAngle; float mainHandAngle = aimAngle; OversizedUtil.SetAnglesAndOffsets(equipment, equipment as ThingWithComps, aimAngle, launcher, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, true, DualWeapon && !compOversized.FirstAttack); Vector3 vector = DualWeapon && !compOversized.FirstAttack ? offsetOffHand : offsetMainHand; // Vector3 vector = compOversized.AdjustRenderOffsetFromDir(equippable.PrimaryVerb.CasterPawn, !compOversized.FirstAttack); result += vector; } } result = equipment.MuzzlePositionFor(result, aimAngle); return(result); }
public static void ThrowMuzzleFlash(IntVec3 cell, Map map, FleckDef moteDef, float scale, Verb verb) { bool skip = false; if (!AMAMod.settings.AllowMuzzlePosition) { skip = true; } if (verb.GetProjectile() != null) { if (verb.GetProjectile() as Lasers.LaserBeamDef != null) { skip = true; } if (verb.GetProjectile().GetType().ToString().Contains("Lasers.LaserBeamDef")) { skip = true; } } if (verb.EquipmentSource != null && !skip) { if (verb.verbProps.range > 1.48f) { FleckDef mote = moteDef; CompEquippable equippable = verb.EquipmentCompSource; Vector3 origin = verb.CasterIsPawn ? verb.CasterPawn.Drawer.DrawPos : verb.Caster.DrawPos; Vector3 a = verb.CurrentTarget.CenterVector3; float aimAngle = 0f; if ((a - origin).MagnitudeHorizontalSquared() > 0.001f) { aimAngle = (a - origin).AngleFlat(); } if (verb.Caster is Building_TurretGun _TurretGun) { origin += new Vector3(_TurretGun.def.building.turretTopOffset.x, 0, _TurretGun.def.building.turretTopOffset.y); } else { OgsCompOversizedWeapon.CompOversizedWeapon compOversized = verb.EquipmentSource.TryGetCompFast <CompOversizedWeapon>(); if (compOversized != null) { bool DualWeapon = compOversized.Props != null && compOversized.Props.isDualWeapon; Vector3 offsetMainHand = default(Vector3); Vector3 offsetOffHand = default(Vector3); float offHandAngle = aimAngle; float mainHandAngle = aimAngle; OversizedUtil.SetAnglesAndOffsets(compOversized.parent, compOversized.parent, aimAngle, verb.Caster, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, true, DualWeapon && !compOversized.FirstAttack); // if (DualWeapon && AMAMod.Dev) Log.Message("Throwing flash for " + compOversized.parent.LabelCap + " offsetMainHand: " + offsetMainHand + " offsetOffHand: " + offsetOffHand + " Using " + (!compOversized.FirstAttack ? "OffHand" : "MainHand") + " FirstAttack: " + compOversized.FirstAttack); origin += DualWeapon && !compOversized.FirstAttack ? offsetOffHand : offsetMainHand; // origin += compOversized.AdjustRenderOffsetFromDir(equippable.PrimaryVerb.CasterPawn, !compOversized.FirstAttack); if (compOversized.Props.isDualWeapon) { compOversized.FirstAttack = !compOversized.FirstAttack; } } } origin = verb.MuzzlePositionFor(aimAngle, true); if (verb.GetProjectile() != null) { origin.y = verb.GetProjectile().Altitude; } AdeptusFleckMaker.Static(origin, map, mote, scale); return; } } { AdeptusFleckMaker.Static(cell.ToVector3Shifted(), map, moteDef, scale); } }