public static bool tryCQCWeaponSwapToMelee(Pawn pawn, Pawn target, DroppingModeEnum drop) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawn == null || pawn.Dead || pawnMemory == null || pawn.equipment == null || pawn.inventory == null) { return(false); } if (!pawn.RaceProps.Humanlike) { return(false); } if (pawn.equipment.Primary != null) { if (pawn.equipment.Primary.def.destroyOnDrop) { return(false); } } if (pawnMemory.IsCurrentWeaponForced(false)) { return(false); } var current = pawn.equipment.Primary; equipBestWeaponFromInventoryByPreference(pawn, drop, GoldfishModule.PrimaryWeaponMode.Melee, target: target); return(current != pawn.equipment.Primary); }
public static bool shouldDrop(DroppingModeEnum mode) { switch (SimpleSidearms.DropMode.Value) { case DroppingModeOptionsEnum.Never: return(false); case DroppingModeOptionsEnum.InDistress: if (mode == DroppingModeEnum.InDistress) { return(true); } else { return(false); } case DroppingModeOptionsEnum.InCombat: if (mode == DroppingModeEnum.InDistress || mode == DroppingModeEnum.Combat) { return(true); } else { return(false); } case DroppingModeOptionsEnum.Always: default: return(true); } }
internal static bool shouldDrop(DroppingModeEnum mode) { switch (SimpleSidearms.DropMode.Value) { case DroppingModeOptionsEnum.Never: return(false); case DroppingModeOptionsEnum.Panic: if (mode == DroppingModeEnum.Panic) { return(true); } else { return(false); } case DroppingModeOptionsEnum.PanicOrRange: if (mode == DroppingModeEnum.Panic || mode == DroppingModeEnum.Range) { return(true); } else { return(false); } case DroppingModeOptionsEnum.Always: default: return(true); } }
public static bool shouldDrop(Pawn pawn, DroppingModeEnum mode, bool ignoreRecoveryChance) { bool drop; switch (Settings.FumbleMode) { case FumbleModeOptionsEnum.Never: drop = false; break; case FumbleModeOptionsEnum.InDistress: if (mode == DroppingModeEnum.InDistress) { drop = true; } else { drop = false; } break; case FumbleModeOptionsEnum.InCombat: if (mode == DroppingModeEnum.InDistress || mode == DroppingModeEnum.Combat) { drop = true; } else { drop = false; } break; case FumbleModeOptionsEnum.Always: default: drop = true; break; } if (ignoreRecoveryChance) { return(drop); } else if (drop) { var bestSkill = Math.Max(pawn.skills.GetSkill(SkillDefOf.Shooting).Level, pawn.skills.GetSkill(SkillDefOf.Melee).Level); var chance = Settings.FumbleRecoveryChance.Evaluate(bestSkill); var recovered = Rand.Chance(chance); return(!recovered); } return(false); }
public static bool tryCQCWeaponSwapToMelee(Pawn pawn, Pawn target, DroppingModeEnum dropMode) { if (!pawn.IsValidSidearmsCarrier()) { return(false); } CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory == null) { return(false); } if (!pawn.RaceProps.Humanlike) { return(false); } if (pawn.equipment.Primary != null) { if (pawn.equipment.Primary.def.destroyOnDrop) { return(false); } } if (pawnMemory.IsCurrentWeaponForced(false)) { return(false); } var current = pawn.equipment.Primary; equipBestWeaponFromInventoryByPreference(pawn, dropMode, PrimaryWeaponMode.Melee, target: target); return(current != pawn.equipment.Primary); }
public static void equipBestWeaponFromInventoryByPreference(Pawn pawn, DroppingModeEnum dropMode, PrimaryWeaponMode?modeOverride = null, Pawn target = null) { if (!pawn.IsValidSidearmsCarrier()) { return; } CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory == null) { return; } PrimaryWeaponMode mode = modeOverride == null ? pawnMemory.primaryWeaponMode : modeOverride.Value; if ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } if (pawn.Drafted && (pawnMemory.ForcedUnarmedWhileDrafted || pawnMemory.ForcedUnarmed && pawnMemory.ForcedWeaponWhileDrafted == null)) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } if (pawn.Drafted && pawnMemory.ForcedWeaponWhileDrafted != null) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingDefStuffDefPair() != pawnMemory.ForcedWeaponWhileDrafted.Value) { var requiredWeapon = pawnMemory.ForcedWeaponWhileDrafted.Value; if (!Settings.AllowBlockedWeaponUse && StatCalculator.canCarrySidearmType(requiredWeapon, pawn, out _)) { //clear invalid pawnMemory.ForcedWeaponWhileDrafted = null; return; } bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } if (pawnMemory.ForcedUnarmed) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } if (pawnMemory.ForcedWeapon != null) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingDefStuffDefPair() != pawnMemory.ForcedWeapon.Value) { var requiredWeapon = pawnMemory.ForcedWeapon.Value; if (!Settings.AllowBlockedWeaponUse && StatCalculator.canCarrySidearmType(requiredWeapon, pawn, out _)) { //clear invalid pawnMemory.ForcedWeapon = null; return; } bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } if (mode == PrimaryWeaponMode.Ranged || ((mode == PrimaryWeaponMode.BySkill) && (pawn.getSkillWeaponPreference() == PrimaryWeaponMode.Ranged))) { if (pawnMemory.DefaultRangedWeapon != null && pawn.hasWeaponType(pawnMemory.DefaultRangedWeapon.Value)) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingDefStuffDefPair() != pawnMemory.DefaultRangedWeapon.Value) { var requiredWeapon = pawnMemory.DefaultRangedWeapon.Value; if (!Settings.AllowBlockedWeaponUse && StatCalculator.canCarrySidearmType(requiredWeapon, pawn, out _)) { //clear invalid pawnMemory.DefaultRangedWeapon = null; return; } bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } else { bool skipManualUse = true; bool skipDangerous = pawn.IsColonistPlayerControlled && Settings.SkipDangerousWeapons; bool skipEMP = true; (ThingWithComps weapon, float dps, float averageSpeed)bestWeapon = GettersFilters.findBestRangedWeapon(pawn, null, skipManualUse, skipDangerous, skipEMP); if (bestWeapon.weapon != null) { if (pawn.equipment.Primary != bestWeapon.weapon) { bool success = equipSpecificWeaponFromInventory(pawn, bestWeapon.weapon, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } } } //all that's left is either melee preference or no ranged weapon found - so in either case, we want to equip a melee weapon. /*if (mode == GoldfishModule.PrimaryWeaponMode.Melee || * ((mode == GoldfishModule.PrimaryWeaponMode.BySkill) && (pawn.getSkillWeaponPreference() == GoldfishModule.PrimaryWeaponMode.Melee)))*/ { //Log.Message("melee mode"); //prefers melee if (pawnMemory.PreferredUnarmed) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } else { if (pawnMemory.PreferredMeleeWeapon != null && pawn.hasWeaponType(pawnMemory.PreferredMeleeWeapon.Value)) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingDefStuffDefPair() != pawnMemory.PreferredMeleeWeapon.Value) { var requiredWeapon = pawnMemory.PreferredMeleeWeapon.Value; if (!Settings.AllowBlockedWeaponUse && StatCalculator.canCarrySidearmType(requiredWeapon, pawn, out _)) { //clear invalid pawnMemory.PreferredMeleeWeapon = null; return; } bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } else { ThingWithComps result; bool foundAlternative = GettersFilters.findBestMeleeWeapon(pawn, out result, includeRangedWithBash: false); if (foundAlternative) { if (pawn.equipment.Primary != result) { bool success = equipSpecificWeaponFromInventory(pawn, result, MiscUtils.shouldDrop(pawn, dropMode, false), false); if (success) { return; } } else { return; } } } } } return; }
public static void equipBestWeaponFromInventoryByPreference(Pawn pawn, DroppingModeEnum drop, GoldfishModule.PrimaryWeaponMode?modeOverride = null, Pawn target = null) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawn == null || pawn.Dead || pawnMemory == null || pawn.equipment == null || pawn.inventory == null) { return; } GoldfishModule.PrimaryWeaponMode mode = modeOverride == null ? pawnMemory.primaryWeaponMode : modeOverride.Value; if (pawn.Drafted && (pawnMemory.ForcedUnarmedWhileDrafted || pawnMemory.ForcedUnarmed && pawnMemory.ForcedWeaponWhileDrafted == null)) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } if (pawn.Drafted && pawnMemory.ForcedWeaponWhileDrafted != null) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingStuffPair() != pawnMemory.ForcedWeaponWhileDrafted.Value) { var requiredWeapon = pawnMemory.ForcedWeaponWhileDrafted.Value; bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } if (pawnMemory.ForcedUnarmed) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } if (pawnMemory.ForcedWeapon != null) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingStuffPair() != pawnMemory.ForcedWeapon.Value) { var requiredWeapon = pawnMemory.ForcedWeapon.Value; bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } if (mode == GoldfishModule.PrimaryWeaponMode.Ranged || ((mode == GoldfishModule.PrimaryWeaponMode.BySkill) && (pawn.getSkillWeaponPreference() == GoldfishModule.PrimaryWeaponMode.Ranged))) { if (pawnMemory.DefaultRangedWeapon != null && pawn.hasWeaponSomewhere(pawnMemory.DefaultRangedWeapon.Value)) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingStuffPair() != pawnMemory.DefaultRangedWeapon.Value) { var requiredWeapon = pawnMemory.DefaultRangedWeapon.Value; bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } else { ThingWithComps result; (ThingWithComps weapon, float dps, float averageSpeed)bestWeapon = GettersFilters.findBestRangedWeapon(pawn, null, pawn.IsColonistPlayerControlled); if (bestWeapon.weapon != null) { if (pawn.equipment.Primary != bestWeapon.weapon) { bool success = equipSpecificWeaponFromInventory(pawn, bestWeapon.weapon, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } } } //all that's left is either melee preference or no ranged weapon found - so in either case, we want to equip a melee weapon. /*if (mode == GoldfishModule.PrimaryWeaponMode.Melee || * ((mode == GoldfishModule.PrimaryWeaponMode.BySkill) && (pawn.getSkillWeaponPreference() == GoldfishModule.PrimaryWeaponMode.Melee)))*/ { //Log.Message("melee mode"); //prefers melee if (pawnMemory.PreferredUnarmed) { if (pawn.equipment.Primary != null) { bool success = equipSpecificWeapon(pawn, null, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } else { if (pawnMemory.PreferredMeleeWeapon != null && pawn.hasWeaponSomewhere(pawnMemory.PreferredMeleeWeapon.Value)) { if (pawn.equipment.Primary == null || pawn.equipment.Primary.toThingStuffPair() != pawnMemory.PreferredMeleeWeapon.Value) { var requiredWeapon = pawnMemory.PreferredMeleeWeapon.Value; bool success = equipSpecificWeaponTypeFromInventory(pawn, requiredWeapon, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } else { ThingWithComps result; bool foundAlternative = GettersFilters.findBestMeleeWeapon(pawn, out result, includeRangedWithBash: false); if (foundAlternative) { if (pawn.equipment.Primary != result) { bool success = equipSpecificWeaponFromInventory(pawn, result, MiscUtils.shouldDrop(drop), false); if (success) { return; } } else { return; } } } } } return; }