示例#1
0
        internal static bool tryRangedWeaponSwap(Pawn pawn, bool dropCurrent, bool skipDangerous)
        {
            if (pawn.Dead)
            {
                return(false);
            }
            Thing best = null;

            if (pawn.inventory.innerContainer.Any((Thing x) => x.def.IsRangedWeapon))
            {
                best = GettersFilters.findBestRangedWeapon(pawn, skipDangerous /*, RangedSelectionMode*/);
            }

            if (best == null)
            {
                return(false);
            }

            if (best is ThingWithComps)
            {
                ThingWithComps bestThing = (ThingWithComps)best;

                SetPrimary(pawn, bestThing, false, true, dropCurrent, false);

                return(true);
            }
            return(false);
        }
示例#2
0
        internal static bool tryRangedWeaponSwap(Pawn pawn, bool dropCurrent, bool skipDangerous)
        {
            if (pawn.Dead)
            {
                return(false);
            }
            Thing best = null;

            //Log.Message("looking for ranged weapon in inventory");
            if (pawn.inventory.innerContainer.Any((Thing x) => x.def.IsRangedWeapon))
            {
                //Log.Message("found ranged weapon in inventory");
                best = GettersFilters.findBestRangedWeapon(pawn, skipDangerous /*, RangedSelectionMode*/);
            }

            if (best == null)
            {
                return(false);
            }

            //Log.Message("sorted out best (" + best.LabelShort + ")");

            if (best is ThingWithComps)
            {
                //Log.Message("converted to ThingWithComps");
                ThingWithComps bestThing = (ThingWithComps)best;

                SetPrimary(pawn, bestThing, false, true, dropCurrent, false);

                return(true);
            }
            return(false);
        }
        internal static bool trySwapToMoreAccurateRangedWeapon(Pawn pawn, bool dropCurrent, float range, bool skipDangerous)
        {
            if (pawn.Dead)
                return false;
            Thing betterWeapon = null;
            float betterDPS;
            
            if (pawn.inventory.innerContainer.Any((Thing x) => x.def.IsRangedWeapon))
            {
                betterWeapon = GettersFilters.findBestRangedWeaponAtRanged(pawn, range, skipDangerous, out betterDPS);
            }
            else
            {
                return false;
            }
            if (betterWeapon == null)
                return false;

            float currentDPS = StatCalculator.RangedDPS(pawn.equipment.Primary, SpeedSelectionBiasRanged.Value, range);

            if (betterDPS < currentDPS + ANTI_OSCILLATION_FACTOR)
                return false;

            if (betterWeapon is ThingWithComps)
            {
                SetPrimary(pawn, betterWeapon, false, true, dropCurrent, false);

                return true;
            }
            return false;
        }
        internal static bool tryMeleeWeaponSwap(Pawn pawn, bool dropCurrent, bool considerUnarmed, bool skipDangerous)
        {
            if (pawn.Dead)
                return false;
            Thing best = null;

            bool unarmedIsBest;
            
            if (pawn.inventory.innerContainer.Any((Thing x) => x.def.IsMeleeWeapon))
            {
                best = GettersFilters.findBestMeleeWeapon(pawn, skipDangerous, out unarmedIsBest/*, MeleeSelectionMode*/);
            }
            else
            {
                unarmedIsBest = true;
            }

            if (best == null | unarmedIsBest)
            {
                if (considerUnarmed)
                {
                    SetPrimary(pawn, null, false, true, dropCurrent, false);
                }
            }
            else
            {
                if (best is ThingWithComps)
                {
                    SetPrimary(pawn, best, false, true, dropCurrent, false);
                    return true;
                }
            }
            
            return false;
        }
        public static bool trySwapToMoreAccurateRangedWeapon(Pawn pawn, LocalTargetInfo target, bool dropCurrent, bool skipDangerous = true)
        {
            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);

            if (pawn == null || pawn.Dead || pawnMemory == null || pawn.equipment == null || pawn.inventory == null)
            {
                return(false);
            }

            if (pawnMemory.IsCurrentWeaponForced(false))
            {
                return(false);
            }

            (ThingWithComps weapon, float dps, float averageSpeed)bestWeapon = GettersFilters.findBestRangedWeapon(pawn, target, skipDangerous, true);

            if (bestWeapon.weapon == null)
            {
                return(false);
            }

            CellRect cellRect   = (!target.HasThing) ? CellRect.SingleCell(target.Cell) : target.Thing.OccupiedRect();
            float    range      = cellRect.ClosestDistSquaredTo(pawn.Position);
            float    currentDPS = StatCalculator.RangedDPS(pawn.equipment.Primary, SpeedSelectionBiasRanged.Value, bestWeapon.averageSpeed, range);

            if (bestWeapon.dps < currentDPS + ANTI_OSCILLATION_FACTOR)
            {
                return(false);
            }

            equipSpecificWeaponFromInventory(pawn, bestWeapon.weapon, dropCurrent, false);
            return(true);
        }
示例#6
0
        internal static bool tryMeleeWeaponSwap(Pawn pawn, bool dropCurrent, bool considerUnarmed, bool skipDangerous, Pawn target = null)
        {
            if (pawn.Dead)
            {
                return(false);
            }
            ThingWithComps best = GettersFilters.findBestMeleeWeapon(pawn, skipDangerous /*, MeleeSelectionMode*/, target);

            if (best != null || considerUnarmed)
            {
                return(SetPrimary(pawn, best, false, true, dropCurrent, false));
            }

            return(false);
        }
示例#7
0
        internal static bool trySwapToMoreAccurateRangedWeapon(Pawn pawn, bool dropCurrent, float range, bool skipDangerous)
        {
            //Log.Message("attempting swap");
            if (pawn.Dead)
            {
                return(false);
            }
            Thing betterWeapon = null;
            float betterDPS;

            //Log.Message("looking for ranged weapon in inventory");
            if (pawn.inventory.innerContainer.Any((Thing x) => x.def.IsRangedWeapon))
            {
                //Log.Message("found ranged weapon in inventory");
                betterWeapon = GettersFilters.findBestRangedWeaponAtRanged(pawn, range, skipDangerous, out betterDPS);
            }
            else
            {
                return(false);
            }
            if (betterWeapon == null)
            {
                return(false);
            }

            float currentDPS = StatCalculator.RangedDPS(pawn.equipment.Primary, SpeedSelectionBiasRanged.Value, range);

            //Log.Message("current DPS is "+currentDPS+ " ("+pawn.equipment.Primary.LabelShort+")");
            //Log.Message("best sidearm DPS is " + betterDPS + " (" + betterWeapon.LabelShort + ")");

            if (betterDPS < currentDPS + ANTI_OSCILLATION_FACTOR)
            {
                return(false);
            }

            //Log.Message("sorted out best (" + best.LabelShort + ")");

            if (betterWeapon is ThingWithComps)
            {
                //Log.Message("converted to ThingWithComps");

                SetPrimary(pawn, betterWeapon, false, true, dropCurrent, false);

                return(true);
            }
            return(false);
        }
示例#8
0
        internal static float weightForType(Pawn pawn, WeaponSearchType type)
        {
            float        total   = 0;
            List <Thing> weapons = GettersFilters.getWeaponsOfType(pawn, type);

            foreach (Thing thing in weapons)
            {
                switch (type)
                {
                case WeaponSearchType.MeleeCapable:
                    if ((thing.def.IsMeleeWeapon || (thing.def.tools != null && thing.def.tools.Any((Tool x) => x.VerbsProperties.Any((VerbProperties y) => y.IsMeleeAttack)))))
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;

                case WeaponSearchType.Melee:
                    if (thing.def.IsMeleeWeapon)
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;

                case WeaponSearchType.Ranged:
                    if (thing.def.IsRangedWeapon)
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;

                case WeaponSearchType.Both:
                default:
                    if (thing.def.IsWeapon)
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;
                }
            }
            return(total);
        }
示例#9
0
        public static float weightForLimitType(Pawn pawn, WeaponSearchType type)
        {
            float total = 0;
            IEnumerable <ThingWithComps> weapons = GettersFilters.filterForWeaponKind(pawn.getCarriedWeapons(), type);

            foreach (ThingWithComps thing in weapons)
            {
                switch (type)
                {
                case WeaponSearchType.MeleeCapable:
                    if ((thing.def.IsMeleeWeapon || (thing.def.tools != null && thing.def.tools.Any((Tool x) => x.VerbsProperties.Any((VerbProperties y) => y.IsMeleeAttack)))))
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;

                case WeaponSearchType.Melee:
                    if (thing.def.IsMeleeWeapon)
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;

                case WeaponSearchType.Ranged:
                    if (thing.def.IsRangedWeapon)
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;

                case WeaponSearchType.Both:
                default:
                    if (thing.def.IsWeapon)
                    {
                        total += thing.GetStatValue(StatDefOf.Mass);
                    }
                    break;
                }
            }
            return(total);
        }
示例#10
0
 internal static int countForType(Pawn pawn, WeaponSearchType type)
 {
     return(GettersFilters.getWeaponsOfType(pawn, type).Count);
 }
示例#11
0
 public static int countForLimitType(Pawn pawn, WeaponSearchType type)
 {
     return(GettersFilters.filterForWeaponKind(pawn.getCarriedWeapons(), type).Count());
 }
        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;
        }