public static Vector2 MuzzlePosition(Vector2 sourceLoc, Verb_LaunchProjectileCE instance) { // Log.Message("MuzzlePosition CE"); Vector2 result = sourceLoc; // Log.Message("MuzzlePosition CE sourceLoc: " + sourceLoc); string msg = "CE MuzzlePosition {0}: {1}, aimAngle: {2}"; float aimAngle = 0f; if (instance.EquipmentSource is Thing equipment) { // Log.Message("MuzzlePosition CE EquipmentSource: " + equipment); Thing launcher = instance.Shooter; Vector3 origin = new Vector3(sourceLoc.x, 0, sourceLoc.y); Vector3 destination = instance.CurrentTarget.Cell.ToVector3Shifted(); if ((destination - origin).MagnitudeHorizontalSquared() > 0.001f) { aimAngle = (destination - origin).AngleFlat(); } IDrawnWeaponWithRotation rotation = equipment as IDrawnWeaponWithRotation; if (rotation != null) { // Log.Message(rotation + " is IDrawnWeaponWithRotation with RotationOffset: " + rotation.RotationOffset); aimAngle += rotation.RotationOffset; } Log.Message(string.Format(msg, "Original", sourceLoc, aimAngle)); GunDrawExtension gunDrawExtension = equipment.def.GetModExtensionFast <GunDrawExtension>(); if (gunDrawExtension != null) { Log.Message("gunDrawExtension"); } else 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; OgsCompOversizedWeapon.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); origin += vector; } } origin = equipment.MuzzlePositionFor(origin, aimAngle); result = new Vector2(origin.x, origin.z); } Log.Message(string.Format(msg, "result", result, aimAngle)); return(result); }
///// <summary> ///// Prevents the user from having damage with the verb. ///// </summary> ///// <param name="__instance"></param> ///// <param name="__result"></param> ///// <param name="pawn"></param> //public static void GetDamageFactorForPostFix(Verb __instance, ref float __result, Pawn pawn) //{ // Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment; // if (pawn_EquipmentTracker != null) // { // //Log.Message("2"); // ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); // if (thingWithComps != null) // { // //Log.Message("3"); // CompActivatableEffect compActivatableEffect = thingWithComps.GetComp<CompActivatableEffect>(); // if (compActivatableEffect != null) // { // if (compActivatableEffect.CurrentState != CompActivatableEffect.State.Activated) // { // //Messages.Message("DeactivatedWarning".Translate(), MessageSound.RejectInput); // __result = 0f; // } // } // } // } //} /// <summary> /// Adds another "layer" to the equipment aiming if they have a /// weapon with a CompActivatableEffect. /// </summary> public static void DrawMeshModified(Mesh mesh, Matrix4x4 matrix, Material mat, int layer, Thing eq, Pawn pawn, Vector3 position, Quaternion rotation) { // Log.Message("DrawMeshModified"); ThingWithComps thingWithComps = eq as ThingWithComps; CompEquippable equippable = eq.TryGetComp <CompEquippable>(); OgsCompOversizedWeapon.CompOversizedWeapon compOversized = thingWithComps.TryGetComp <OgsCompOversizedWeapon.CompOversizedWeapon>(); var compActivatableEffect = thingWithComps?.GetComp <CompActivatableEffect>(); if (compActivatableEffect?.Graphic == null) { return; } if (!compActivatableEffect.IsActiveNow) { return; } var matSingle = compActivatableEffect.Graphic.MatSingle; Vector3 s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y); if (compOversized != null) { if (pawn.RaceProps.Humanlike) { if (HarmonyCompActivatableEffect.enabled_AlienRaces) { Vector2 v = AlienRaceUtility.AlienRacesPatch(pawn, eq); float f = Mathf.Max(v.x, v.y); s = new Vector3(eq.def.graphicData.drawSize.x * f, 1f, eq.def.graphicData.drawSize.y * f); } else { s = new Vector3(eq.def.graphicData.drawSize.x, 1f, eq.def.graphicData.drawSize.y); } } else { Vector2 v = pawn.ageTracker.CurKindLifeStage.bodyGraphicData.drawSize; s = new Vector3(eq.def.graphicData.drawSize.x + v.x / 10, 1f, eq.def.graphicData.drawSize.y + v.y / 10); } // Log.Message("DrawEquipmentAimingPostFix compOversized offset: "+ offset + " Rotation: "+rotation + " size: " + s); } Vector3 vector3 = position; vector3.y -= 0.0005f; matrix.SetTRS(vector3, rotation, s); Graphics.DrawMesh(mesh, matrix, matSingle, 0); }
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; OgsCompOversizedWeapon.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, ThingDef 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) { ThingDef 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 <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; OgsCompOversizedWeapon.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; } AdeptusMoteMaker.MakeStaticMote(origin, map, mote, scale); return; } } { AdeptusMoteMaker.MakeStaticMote(cell.ToVector3Shifted(), map, moteDef, scale); } }