public static bool Prefix(ref TechVision __instance, ref int team, ref Visible __result) { OctantVision octantVision = __instance.GetComponent <OctantVision>(); if (octantVision) { __result = octantVision.GetFirstVisibleTechIsEnemy(team); return(false); } return(true); }
public static bool Prefix(ref TargetAimer __instance, ref float rotateSpeed) { TankBlock block = (TankBlock)m_Block.GetValue(__instance); // Has a target if (WeaponAimSettings.OctantAim && block && block.tank && __instance.HasTarget) { Tank tank = block.tank; bool enemyWeapon = !ManSpawn.IsPlayerTeam(tank.Team); if (enemyWeapon && WeaponAimSettings.EnemyLead || !enemyWeapon && WeaponAimSettings.PlayerLead) { Vector3 targetWorld = (Vector3)m_TargetPosition.GetValue(__instance); Func <Vector3, Vector3> aimDelegate = (Func <Vector3, Vector3>)AimDelegate.GetValue(__instance); if (__instance.HasTarget && aimDelegate != null) { targetWorld = aimDelegate(targetWorld); } // Check if we can aim List <GimbalAimer> gimbalAimers = (List <GimbalAimer>)m_GimbalAimers.GetValue(__instance); bool canAim = true; foreach (GimbalAimer aimer in gimbalAimers) { if (__instance.Target && canAim) { canAim = aimer.CanAim(targetWorld); if (!canAim) { break; } } } // If we can aim, is all good - continue as normal (will do aim calculation for gimbals twice) if (canAim) { return(true); } IModuleWeapon moduleWeapon = block.GetComponent <IModuleWeapon>(); OctantVision octantVision = tank.GetComponent <OctantVision>(); if (octantVision && gimbalAimers.Count > 0) { float[] XConstraints = new float[2]; float[] YConstraints = new float[2]; GimbalAimer XGimbal = null; GimbalAimer YGimbal = null; GimbalAimer FreeGimbal = null; bool free = false; foreach (GimbalAimer aimer in gimbalAimers) { if (aimer.rotationAxis == GimbalAimer.AxisConstraint.X) { XConstraints = aimer.rotationLimits; XGimbal = aimer; } else if (aimer.rotationAxis == GimbalAimer.AxisConstraint.Y) { YConstraints = aimer.rotationLimits; YGimbal = aimer; } else { FreeGimbal = aimer; free = true; break; } } int[] octants; if (free) { octants = new int[8] { 0, 1, 2, 3, 4, 5, 6, 7 }; OctantVision.Limits limits = new OctantVision.Limits { localToBlock = block.trans.InverseTransformPoint(FreeGimbal.transform.position), localToGimbal = Vector3.zero, localToBarrel = Vector3.zero, XConstraints = new float[2], YConstraints = new float[2] }; Visible betterTarget = octantVision.GetFirstVisibleTechIsEnemy(octants, limits, block, null, null, aimDelegate); if (betterTarget) { Target.SetValue(__instance, betterTarget); UpdateTarget.Invoke(__instance, null); } } else if (XGimbal || YGimbal) { if (moduleWeapon != null) { GimbalAimer parentGimbal = null; GimbalAimer childGimbal = null; if (XGimbal) { if (YGimbal) { if (YGimbal.transform.IsChildOf(XGimbal.transform)) { parentGimbal = XGimbal; childGimbal = YGimbal; } else { parentGimbal = YGimbal; childGimbal = XGimbal; } } else { parentGimbal = XGimbal; } } else { parentGimbal = YGimbal; } Vector3 gimbalBlockLocalPosition = block.trans.InverseTransformPoint(parentGimbal.transform.position); Vector3 gimbalLocalPosition = Vector3.zero; if (parentGimbal && childGimbal) { gimbalLocalPosition = parentGimbal.transform.InverseTransformPoint(childGimbal.transform.position); } Vector3 fireLocalPosition = Vector3.zero; GimbalAimer localChildGimbal = childGimbal ? childGimbal : parentGimbal; if (moduleWeapon is ModuleWeaponGun moduleWeaponGun) { CannonBarrel[] cannonBarrels = (CannonBarrel[])m_CannonBarrels.GetValue(moduleWeaponGun); foreach (CannonBarrel cannonBarrel in cannonBarrels) { fireLocalPosition += localChildGimbal.transform.InverseTransformPoint(cannonBarrel.projectileSpawnPoint.position); } fireLocalPosition /= cannonBarrels.Length; } else if (moduleWeapon is ModuleWeaponFlamethrower moduleWeaponFlamethrower) { fireLocalPosition = localChildGimbal.transform.InverseTransformPoint(moduleWeaponFlamethrower.GetFireTransform().position); } OctantVision.Limits limits = new OctantVision.Limits { localToBlock = gimbalBlockLocalPosition, localToGimbal = gimbalLocalPosition, localToBarrel = fireLocalPosition, XConstraints = XConstraints, YConstraints = YConstraints }; octants = OctantVision.GetOctants(limits, parentGimbal, block); Visible betterTarget = octantVision.GetFirstVisibleTechIsEnemy(octants, limits, block, XGimbal, YGimbal, aimDelegate); if (betterTarget != null) { Target.SetValue(__instance, betterTarget); UpdateTarget.Invoke(__instance, null); } } } } } } return(true); }