Exemple #1
0
        public static void SubvertBiocodedGear(Pawn target, Pawn subverter)
        {
            Pawn_EquipmentTracker eqTracker = target.equipment;

            foreach (Thing eq in eqTracker.AllEquipmentListForReading)
            {
                // if biocodable and biocoded, code to subverter
                CompBiocodable biocode = eq.TryGetComp <CompBiocodable>();
                if (biocode != null && biocode.Biocoded)
                {
                    biocode.CodeFor(subverter);
                    eqTracker.TryDropEquipment(eqTracker.Primary, out ThingWithComps dontcare, target.Position);
                }
            }
            Pawn_ApparelTracker apTracker = target.apparel;

            foreach (Apparel ap in apTracker.WornApparel)
            {
                CompBiocodable biocode = ap.TryGetComp <CompBiocodable>();
                if (biocode != null && biocode.Biocoded)
                {
                    biocode.CodeFor(subverter);
                    apTracker.TryDrop(ap);
                }
            }
        }
Exemple #2
0
        public override void Tick()
        {
            base.Tick();
            if (base.Wearer == null)
            {
                return;
            }
            if (this.Wearer.kindDef == PawnKindDefOf.WildMan)
            {
                this.Destroy(DestroyMode.Vanish);
                return;
            }
            if (this.Wearer.Faction == null)
            {
                this.Destroy(DestroyMode.Vanish);
                return;
            }
            if (this.Wearer.kindDef.defaultFactionType != PSFDefOf.Polaribloc_SecuirityForce)
            {
                this.Destroy(DestroyMode.Vanish);
                return;
            }
            if (this.Wearer != null)
            {
                if (ModLister.GetActiveModWithIdentifier("Vanya.Polarisbloc.CoreLab") != null)
                {
                    this.Wearer.health.AddHediff(HediffDef.Named("PolarisCombatChip_Currency"), this.Wearer.health.hediffSet.GetBrain(), null);
                }

                BodyPartRecord eye = this.GetEye();
                if (eye != null)
                {
                    this.Wearer.health.AddHediff(HediffDef.Named("BionicEye"), eye, null);
                }
                BodyPartRecord leg = this.GetLeg();
                if (leg != null)
                {
                    this.Wearer.health.AddHediff(HediffDef.Named("BionicLeg"), leg, null);
                }

                if (this.Wearer.health.hediffSet.hediffs.Find(x => x.TryGetComp <HediffComp_Cartridge>() != null) == null)
                {
                    Hediff hediff = HediffMaker.MakeHediff(PolarisblocDefOf.Hediff_PloarisCartridge, this.Wearer, null);
                    this.Wearer.health.AddHediff(hediff);
                }
                CombatEnhancingDrugsApply(this.Wearer);
                foreach (Apparel ap in this.Wearer.apparel.WornApparel)
                {
                    CompBiocodable compBiocodable = ap.TryGetComp <CompBiocodable>();
                    if (compBiocodable != null && !compBiocodable.Biocoded)
                    {
                        compBiocodable.CodeFor(this.Wearer);
                    }
                }
                this.Wearer.apparel.Remove(this);
                this.Destroy(DestroyMode.Vanish);
                return;
            }
        }
        private void Recode()
        {
            //CompBiocodableWeapon biocodableWeapon = this.CodableThing.TryGetComp<CompBiocodableWeapon>();

            CompBiocodable      biocodableThing = this.CodableThing.TryGetComp <CompBiocodable>();
            CompBladelinkWeapon bladelinkWeapon = this.CodableThing.TryGetComp <CompBladelinkWeapon>();
            bool selfDestory = false;

            /*if (Rand.Value > this.SuccessChance)
             * {
             *      Messages.Message("PolarisDecoderFailedUsedForPawn".Translate(this.pawn.NameShortColored, this.CodableThing.Label), MessageTypeDefOf.NegativeEvent, true);
             *      if (Rand.Value < this.Configs.selfDestoryOnFailed)
             *      {
             *              Messages.Message("PolarisDecoderSelfDestroyed".Translate(), MessageTypeDefOf.NegativeEvent, true);
             *              this.Item.SplitOff(1).Destroy(DestroyMode.Vanish);
             *      }
             *      return;
             * }
             * Messages.Message("PolarisDecoderSuccessedUsedForPawn".Translate(this.pawn.NameShortColored, this.CodableThing.Label), this.pawn, MessageTypeDefOf.PositiveEvent, true);*/
            /*if (biocodableWeapon != null)
             * {
             *      if (biocodableWeapon.Biocoded)
             *      {
             *              biocodableWeapon.CodeFor(this.pawn);
             *              if (Rand.Value < this.Configs.selfDestoryOnSuccessed)
             *              {
             *                      selfDestory = true;
             *              }
             *      }
             *      else
             *      {
             *              biocodableWeapon.CodeFor(this.pawn);
             *
             *      }
             * }*/
            if (biocodableThing != null)
            {
                if (biocodableThing.Biocoded)
                {
                    if (this.CheckSuccessOnUsed())
                    {
                        biocodableThing.CodeFor(this.pawn);
                        if (Rand.Value < this.Configs.selfDestoryOnSuccessed)
                        {
                            selfDestory = true;
                        }
                    }
                }
                else
                {
                    biocodableThing.CodeFor(this.pawn);
                    Messages.Message("PolarisDecoderSuccessedUsedForPawn".Translate(this.pawn.NameShortColored, this.CodableThing.Label), this.pawn, MessageTypeDefOf.PositiveEvent, true);
                }
            }

            if (bladelinkWeapon != null)
            {
                if (bladelinkWeapon.bondedPawn != this.pawn)
                {
                    if (this.CheckSuccessOnUsed())
                    {
                        bladelinkWeapon.bondedPawn = null;
                        bladelinkWeapon.Notify_Equipped(this.pawn);
                        if (Rand.Value < this.Configs.selfDestoryOnSuccessed)
                        {
                            selfDestory = true;
                        }
                    }
                }
            }

            if (biocodableThing == null && bladelinkWeapon == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (selfDestory)
            {
                this.Item.SplitOff(1).Destroy(DestroyMode.Vanish);
                Messages.Message("PolarisDecoderSelfDestroyed".Translate(), MessageTypeDefOf.NegativeEvent, true);
            }
        }
        //reworked to use my own code instead of generator code nicked from vanilla Rimworld
        public static bool TryGenerateSidearmFor(Pawn pawn, float chance, float budgetMultiplier, PawnGenerationRequest request)
        {
            if (
                !(Current.ProgramState == ProgramState.Playing) || !pawn.IsValidSidearmsCarrier() ||
                chance < 0.01f ||
                pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0 ||
                pawn.equipment.Primary == null ||
                !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) ||
                (pawn.story != null && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0))
                )
            {
                /*
                 * Log.Message("sidearm viability conditions not met");
                 *
                 * if (pawn is null)
                 *  Log.Message("pawn is null");
                 * if (SimpleSidearms.configData is null)
                 *  Log.Message("configData null");
                 * if (chance < 0.01f)
                 *  Log.Message("chance < 0.01");
                 * if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0)
                 *  Log.Message("weapon tags null or empty");
                 * if (pawn.equipment == null || pawn.equipment.Primary == null)
                 *  Log.Message("equipment null or no primary");
                 * if (!pawn.RaceProps.ToolUser)
                 *  Log.Message("not a toolUser");
                 * if (!pawn.RaceProps.Humanlike)
                 *  Log.Message("not humanlike");
                 * if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                 *  Log.Message("not capable of manipulation");
                 * if ((pawn.story != null && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0)))
                 *  Log.Message("disabled violent work tags, tags:"+pawn.CombinedDisabledWorkTags);
                 */
                return(false);
            }
            else
            {
                //bool primarySingleUse = pawn.equipment.Primary.GetComp<CompEquippable>().PrimaryVerb is Verb_ShootOneUse;

                ThingDefStuffDefPair primaryBase = new ThingDefStuffDefPair(pawn.equipment.Primary.def, pawn.equipment.Primary.Stuff);

                var sidearmChanceRoll = Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824);
                if (sidearmChanceRoll >= chance)
                {
                    return(false); //rolled no sidearm
                }
                IEnumerable <ThingDefStuffDefPair> validSidearms = GettersFilters.getValidSidearms();

                IEnumerable <string> weaponTags = generateWeaponTags(pawn.kindDef.weaponTags);

                validSidearms = validSidearms.Where(t =>
                {
                    foreach (string tag in t.thing.weaponTags)
                    {
                        if (t == null || t.thing == null || t.thing.weaponTags == null)
                        {
                            continue;
                        }
                        if (weaponTags.Contains(tag))
                        {
                            return(true);
                        }
                    }
                    return(false);
                });

                //filter out nonsensical material weapons
                validSidearms = validSidearms.Where(w => w.stuff == null || (w.stuff != ThingDefOf.Gold && w.stuff != ThingDefOf.Silver && w.stuff != ThingDefOf.Uranium));
                //filter out weapons the pawn cant carry
                validSidearms = validSidearms.Where(w => StatCalculator.canCarrySidearmType(w, pawn, out _));

                bool onlyMelee  = (pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler));
                bool onlyRanged = (pawn.story != null && pawn.story.traits.HasTrait(TraitDef.Named("Wimp"))); //wimp has no defOf

                if (onlyMelee)
                {
                    validSidearms = validSidearms.Where(w => w.thing.IsMeleeWeapon);
                }
                if (onlyRanged)
                {
                    validSidearms = validSidearms.Where(w => w.thing.IsRangedWeapon);
                }

                //listWeapons("budget " + pawn.kindDef.weaponMoney.max* budgetMultiplier + " to " + pawn.kindDef.weaponMoney.min* budgetMultiplier + ", main "+ pawn.equipment.Primary.MarketValue +" selecting from:", validSidearms);

                //use the value of primary to limit budget maximum (but of the base to match pre-degradation value) to prevent sidearms being better than the primary weapon
                float budget = Math.Min(pawn.kindDef.weaponMoney.RandomInRange, primaryBase.Price) * budgetMultiplier;
                validSidearms = validSidearms.Where(t => t.Price <= budget);

                //listWeapons("post select:", validSidearms);

                if (validSidearms.Count() == 0)
                {
                    return(false);
                }

                ThingDefStuffDefPair rolledWeaponThingDefStuffDefPair;

                validSidearms.TryRandomElementByWeight(t => { return(t.Commonality * t.Price); }, out rolledWeaponThingDefStuffDefPair);

                ThingWithComps rolledWeaponFinal = (ThingWithComps)ThingMaker.MakeThing(rolledWeaponThingDefStuffDefPair.thing, rolledWeaponThingDefStuffDefPair.stuff);
                PawnGenerator.PostProcessGeneratedGear(rolledWeaponFinal, pawn);

                float num = (request.BiocodeWeaponChance > 0f) ? request.BiocodeWeaponChance : pawn.kindDef.biocodeWeaponChance;
                if (Rand.Value < num)
                {
                    CompBiocodable compBiocodableWeapon = rolledWeaponFinal.TryGetComp <CompBiocodable>();
                    if (compBiocodableWeapon != null)
                    {
                        compBiocodableWeapon.CodeFor(pawn);
                    }
                }

                bool success = pawn.inventory.innerContainer.TryAdd(rolledWeaponFinal);
                if (success)
                {
                    CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                    if (pawnMemory != null)
                    {
                        pawnMemory.InformOfAddedSidearm(rolledWeaponFinal);
                    }
                }
                else
                {
                    Log.Warning("Failed to add generated sidearm to inventory");
                }

                return(true);
            }
        }