public static bool canCarrySidearmInstance(ThingWithComps sidearmThing, Pawn pawn, out string errString)
        {
            //nicked from EquipmentUtility.CanEquip
            CompBladelinkWeapon compBladelinkWeapon = sidearmThing.TryGetComp <CompBladelinkWeapon>();

            if (compBladelinkWeapon != null && compBladelinkWeapon.Biocodable && compBladelinkWeapon.CodedPawn != null && compBladelinkWeapon.CodedPawn != pawn)
            {
                errString = "BladelinkBondedToSomeoneElse".Translate();
                return(false);
            }
            if (CompBiocodable.IsBiocoded(sidearmThing) && !CompBiocodable.IsBiocodedFor(sidearmThing, pawn))
            {
                errString = "BiocodedCodedForSomeoneElse".Translate();
                return(false);
            }
            if (EquipmentUtility.AlreadyBondedToWeapon(sidearmThing, pawn))
            {
                errString = "BladelinkAlreadyBondedMessage".Translate(pawn.Named("PAWN"), pawn.equipment.bondedWeapon.Named("BONDEDWEAPON"));
                return(false);
            }
            if (compBladelinkWeapon != null && !compBladelinkWeapon.Biocoded && !compBladelinkWeapon.TraitsListForReading.Any(t => t.neverBond == true))
            {
                errString = "SidearmPickupFail_NotYetBladelinkBonded".Translate();
                return(false);
            }
            if (EquipmentUtility.RolePreventsFromUsing(pawn, sidearmThing, out string roleReason))
            {
                errString = roleReason;
                return(false);
            }

            ThingDefStuffDefPair sidearm = sidearmThing.toThingDefStuffDefPair();

            return(canCarrySidearmType(sidearm, pawn, out errString));
        }
Exemple #2
0
        public static Thing PickBestArmorFor(Pawn pawn)
        {
            if (pawn.outfits == null)
            {
                return(null);
            }
            if (pawn.Faction != Faction.OfPlayer)
            {
                return(null);
            }
            if (pawn.IsQuestLodger())
            {
                return(null);
            }

            Outfit       currentOutfit = pawn.outfits.CurrentOutfit;
            Thing        thing         = null;
            float        num2          = 0f;
            List <Thing> list          = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel);

            if (list.Count == 0)
            {
                return(null);
            }
            neededWarmth      = PawnApparelGenerator.CalculateNeededWarmth(pawn, pawn.Map.Tile, GenLocalDate.Twelfth(pawn));
            wornApparelScores = new List <float>();
            List <Apparel> wornApparel = pawn.apparel.WornApparel;

            for (int i = 0; i < wornApparel.Count; i++)
            {
                wornApparelScores.Add(ApparelScoreRaw(pawn, wornApparel[i]));
            }
            for (int j = 0; j < list.Count; j++)
            {
                Apparel apparel = (Apparel)list[j];                 // && apparel.IsInAnyStorage()
                if (!apparel.IsBurning() && currentOutfit.filter.Allows(apparel) && !apparel.IsForbidden(pawn) &&
                    (apparel.def.apparel.gender == Gender.None || apparel.def.apparel.gender == pawn.gender))
                {
                    float num3 = ApparelScoreGain_NewTmp(pawn, apparel, wornApparelScores);
                    if (!(num3 < 0.05f) && !(num3 < num2) && (!CompBiocodable.IsBiocoded(apparel) || CompBiocodable.IsBiocodedFor(apparel, pawn)) &&
                        ApparelUtility.HasPartsToWear(pawn, apparel.def) &&
                        pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger()))
                    {
                        thing = apparel;
                        num2  = num3;
                    }
                }
            }
            return(thing);
        }
        /// <summary>
        /// METHOD SIGNATURE CANNOT BE CHANGED AS MENDING PATCH USES THIS METHOD
        /// </summary>
        public bool Remove(ThingWithComps weapon)
        {
            if (weapon == null)
            {
                return(true);
            }

            if (!CompBiocodable.IsBiocoded(weapon))
            {
                //Log.Warning("Remove non-biocoded");
                return(this.RemoveFrom(weapon, this.StoredWeapons));
            }
            //Log.Warning("Remove biocoded");
            //foreach (var l in this.StoredBioEncodedWeapons.Values)
            //    foreach (var w in l)
            //         Log.Warning("  - " + w.Label);
            return(this.RemoveFrom(weapon, this.StoredBioEncodedWeapons));
        }
        /*internal void AddWeapons(IEnumerable<ThingWithComps> weapons)
         * {
         * if (weapons == null)
         * return;
         *
         * foreach (ThingWithComps w in weapons)
         * {
         * this.AddWeapon(w);
         * }
         * }*/

        internal bool AddWeapon(ThingWithComps weapon)
        {
            if (this.CanAdd(weapon))
            {
                if (weapon.Spawned)
                {
                    weapon.DeSpawn();
                }

                if (CombatExtendedUtil.AddAmmo(weapon))
                {
                    return(true);
                }

                this.AddToSortedList(weapon, (CompBiocodable.IsBiocoded(weapon)) ? this.StoredBioEncodedWeapons : this.StoredWeapons);
                return(true);
            }
            return(false);
        }
        public override void ExposeData()
        {
            base.ExposeData();

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                this.temp = new List <ThingWithComps>();
                foreach (IEnumerable <ThingWithComps> l in this.StoredWeapons.Values)
                {
                    this.temp.AddRange(l);
                }
                foreach (IEnumerable <ThingWithComps> l in this.StoredBioEncodedWeapons.Values)
                {
                    this.temp.AddRange(l);
                }
                if (this.forceAddedWeapons == null)
                {
                    this.forceAddedWeapons = new List <Thing>(0);
                }
            }

            Scribe_Collections.Look(ref this.temp, false, "storedWeapons", LookMode.Deep, new object[0]);
            Scribe_Values.Look <bool>(ref this.includeInTradeDeals, "includeInTradeDeals", true, false);
            Scribe_Values.Look <bool>(ref this.IncludeInSharedWeapons, "includeInSharedWeapons", true, false);
            Scribe_Collections.Look(ref this.forceAddedWeapons, false, "forceAddedWeapons", LookMode.Deep, new object[0]);
            Scribe_Values.Look(ref this.Name, "name", "", false);

            if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs)
            {
                this.StoredWeapons.Clear();
                this.StoredBioEncodedWeapons.Clear();
                if (this.temp != null)
                {
                    foreach (ThingWithComps t in this.temp)
                    {
                        if (CompBiocodable.IsBiocoded(t))
                        {
                            this.AddToSortedList(t, this.StoredBioEncodedWeapons);
                        }
                        else
                        {
                            this.AddToSortedList(t, this.StoredWeapons);
                        }
                    }
                }
            }

            if (Scribe.mode == LoadSaveMode.Saving ||
                Scribe.mode == LoadSaveMode.ResolvingCrossRefs)
            {
                if (this.temp != null)
                {
                    this.temp.Clear();
                    this.temp = null;
                }

                if (this.forceAddedWeapons != null && this.forceAddedWeapons.Count == 0)
                {
                    this.forceAddedWeapons = null;
                }
            }
        }
 private bool Contains(ThingWithComps t)
 {
     return(this.Contains(t, (CompBiocodable.IsBiocoded(t)) ? this.StoredBioEncodedWeapons : this.StoredWeapons));
 }
Exemple #7
0
        public static Thing PickBestWeaponFor(Pawn pawn)
        {
            if (pawn.Map == null || pawn.equipment == null || pawn.Faction != Faction.OfPlayer || pawn.IsQuestLodger() ||
                !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || pawn.WorkTagIsDisabled(WorkTags.Violent))
            {
                return(null);
            }

            bool isBrawler    = pawn.story?.traits?.HasTrait(TraitDefOf.Brawler) ?? false;
            bool preferRanged = !isBrawler && (!pawn.equipment.Primary?.def.IsMeleeWeapon ?? false || pawn.equipment.Primary == null);

            Predicate <Thing> validator = delegate(Thing t)
            {
                if (!t.def.IsWeapon)
                {
                    return(false);
                }
                if (t.IsForbidden(pawn))
                {
                    return(false);
                }
                if (isBrawler && t.def.IsRangedWeapon)
                {
                    return(false);
                }
                if (preferRanged && t.def.IsMeleeWeapon)
                {
                    return(false);
                }
                if (!preferRanged && t.def.IsRangedWeapon)
                {
                    return(false);
                }
                if (t.def.weaponTags != null && t.def.weaponTags.Where(x => x.ToLower().Contains("grenade")).Any())
                {
                    return(false);
                }
                if (t.def.IsRangedWeapon && t.def.Verbs.Where(x => x.verbClass == typeof(Verb_ShootOneUse)).Any())
                {
                    return(false);
                }
                return(true);
            };

            Thing        thing    = null;
            float        maxValue = 0f;
            List <Thing> list     = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon).Where(x => validator(x)).ToList();

            List <Thing> weapons = pawn.inventory.innerContainer.InnerListForReading.Where(x => validator(x)).ToList();

            list.AddRange(weapons);
            if (pawn.equipment.Primary != null)
            {
                list.Add(pawn.equipment.Primary);
            }
            for (int j = 0; j < list.Count; j++)
            {
                Thing weapon = list[j];
                if (!weapon.IsBurning())
                {
                    float weaponScore = WeaponScoreGain(weapon, StatDefOf.AccuracyMedium);
                    if (!(weaponScore < 0.05f) && !(weaponScore < maxValue) && (!CompBiocodable.IsBiocoded(weapon) || CompBiocodable.IsBiocodedFor(weapon, pawn)) &&
                        EquipmentUtility.CanEquip(weapon, pawn) && pawn.CanReserveAndReach(weapon, PathEndMode.OnCell, pawn.NormalMaxDanger()))
                    {
                        thing    = weapon;
                        maxValue = weaponScore;
                    }
                }
            }
            return(thing);
        }