public static void Set_Drafted_PostFix(Pawn_DraftController __instance, bool value)
        {
            if (!value)
            {
                Pawn pawn = __instance.pawn;
                if (pawn != null)
                {
                    Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;
                    if (pawn_EquipmentTracker != null)
                    {
                        //Log.Message("2");
                        //ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);
                        ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);

                        if (thingWithComps != null)
                        {
                            //Log.Message("3");
                            CompActivatableEffect compActivatableEffect = thingWithComps.GetComp <CompActivatableEffect>();
                            if (compActivatableEffect != null)
                            {
                                if (compActivatableEffect.CurrentState == CompActivatableEffect.State.Activated)
                                {
                                    compActivatableEffect.Deactivate();
                                }
                            }
                        }
                    }
                }
            }
        }
        public static void ExitMap_PreFix(Pawn __instance, bool allowedToJoinOrCreateCaravan)
        {
            Pawn pawn = __instance;

            if (pawn != null)
            {
                Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;
                if (pawn_EquipmentTracker != null)
                {
                    //Log.Message("2");
                    //ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);
                    ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);

                    if (thingWithComps != null)
                    {
                        //Log.Message("3");
                        CompActivatableEffect compActivatableEffect = thingWithComps.GetComp <CompActivatableEffect>();
                        if (compActivatableEffect != null)
                        {
                            if (compActivatableEffect.CurrentState == CompActivatableEffect.State.Activated)
                            {
                                compActivatableEffect.Deactivate();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static bool HasKeycardAccess(this Thing t, Pawn pawn)
        {
            if (Faction.OfPlayer is null)
            {
                return(false);
            }
            if (Faction.OfPlayer != t.Faction)
            {
                return(false);
            }
            if (!pawn.RaceProps.Humanlike)
            {
                return(false);
            }
            if (!(t as ThingWithComps).GetComp <CompPowerTrader>().PowerOn)
            {
                return(false);
            }
            ThingWithComps thingWithComps = t as ThingWithComps;

            if (thingWithComps is null)
            {
                return(true);
            }
            CompKeycard comp = thingWithComps.GetComp <CompKeycard>();

            if (comp.Locked)
            {
                return(false);
            }
            return(comp.Level <= pawn.def.GetModExtension <KeycardHandler>().AccessLevel ? true : false);
        }
Exemplo n.º 4
0
        public static void SetKeycard(this Thing t, int value, bool warnOnFail = true)
        {
            if (t is null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to Set Keycard on null Thing.", false);
                }
                return;
            }
            ThingWithComps thing = t as ThingWithComps;

            if (thing is null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to Set Keycard on non-ThingWithComps Thing " + t, false);
                }
                return;
            }
            CompKeycard comp = thing.GetComp <CompKeycard>();

            if (comp is null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to Set Keycard on non-Keycard thing " + t, false);
                }
                return;
            }
            comp.Level = value;
        }
Exemplo n.º 5
0
        public static void SetForbidden(this Thing t, bool value, bool warnOnFail = true)
        {
            if (t == null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to SetForbidden on null Thing.");
                }
                return;
            }
            ThingWithComps thingWithComps = t as ThingWithComps;

            if (thingWithComps == null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to SetForbidden on non-ThingWithComps Thing " + t);
                }
                return;
            }
            CompForbiddable comp = thingWithComps.GetComp <CompForbiddable>();

            if (comp == null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to SetForbidden on non-Forbiddable Thing " + t);
                }
                return;
            }
            comp.Forbidden = value;
        }
        public static Dictionary <int, List <IWirelessDetonationReceiver> > FindReceiversInNetworkRange(ThingWithComps origin)
        {
            var comp = origin.GetComp <CompWirelessDetonationGridNode>();

            if (comp == null)
            {
                throw new Exception("Missing CompWirelessDetonationGridNode on sender");
            }
            var results = new Dictionary <int, List <IWirelessDetonationReceiver> >();
            var sample  = comp.FindReceiversInNetworkRange();

            foreach (var pair in sample)
            {
                if (pair.Receiver.CanReceiveWirelessSignal)
                {
                    results.TryGetValue(pair.Receiver.CurrentChannel, out List <IWirelessDetonationReceiver> list);
                    if (list == null)
                    {
                        list = new List <IWirelessDetonationReceiver>();
                        results[pair.Receiver.CurrentChannel] = list;
                    }
                    list.Add(pair.Receiver);
                }
            }
            return(results);
        }
Exemplo n.º 7
0
        public static IRadiationReciever LinkedRadiationReciever(this ThingWithComps thing)
        {
            CompFacility facility = thing.GetComp <CompFacility>();

            if (facility == null)
            {
                return(null);
            }

            foreach (Thing linkedThing in facility.LinkedBuildings())
            {
                IRadiationReciever res = linkedThing as IRadiationReciever;
                if (res != null)
                {
                    return(res);
                }

                Building linkedBuilding = linkedThing as Building;
                if (linkedBuilding == null)
                {
                    continue;
                }

                foreach (ThingComp comp in linkedBuilding.AllComps)
                {
                    res = comp as IRadiationReciever;
                    if (res != null)
                    {
                        return(res);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        public static bool IsForbidden(this Thing t, Faction faction)
        {
            bool result;

            if (faction == null)
            {
                result = false;
            }
            else if (faction != Faction.OfPlayer)
            {
                result = false;
            }
            else
            {
                ThingWithComps thingWithComps = t as ThingWithComps;
                if (thingWithComps == null)
                {
                    result = false;
                }
                else
                {
                    CompForbiddable comp = thingWithComps.GetComp <CompForbiddable>();
                    result = (comp != null && comp.Forbidden);
                }
            }
            return(result);
        }
Exemplo n.º 9
0
        static bool Prefix(this Thing t, bool value, bool warnOnFail = true)
        {
            if (t == null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to SetForbidden on null Thing.", false);
                }
                return(false);
            }
            ThingWithComps thingWithComps = t as ThingWithComps;

            if (thingWithComps == null)
            {
                if (warnOnFail)
                {
                    Log.Error("Tried to SetForbidden on non-ThingWithComps Thing " + t, false);
                }
                return(false);
            }
            CompForbiddable comp = thingWithComps.GetComp <CompForbiddable>();

            if (comp == null)
            {
                return(false);
            }
            comp.Forbidden = value;
            return(false);
        }
Exemplo n.º 10
0
        public static void SoundMissPrefix(ref SoundDef __result, Verb_MeleeAttack __instance)
        {
            if (__instance.caster is Pawn pawn)
            {
                Pawn_EquipmentTracker pawn_EquipmentTracker = pawn.equipment;
                if (pawn_EquipmentTracker != null)
                {
                    //Log.Message("2");
                    ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; // (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);

                    if (thingWithComps != null)
                    {
                        //Log.Message("3");
                        CompExtraSounds CompExtraSounds = thingWithComps.GetComp <CompExtraSounds>();
                        if (CompExtraSounds != null)
                        {
                            if (CompExtraSounds.Props.soundMiss != null)
                            {
                                Log.Message("Returned");
                                __result = CompExtraSounds.Props.soundMiss;
                                return;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public static void GetInspectStringPostfix(ref Pawn __instance, ref string __result)
        {
            if (__instance.IsColonist == false)
            {
                return;
            }

            ThingWithComps equipedWeapon = __instance.equipment.Primary;

            if (equipedWeapon != null)
            {
                CompRangedWeaponAvali compWeaponAvali = equipedWeapon.GetComp <CompRangedWeaponAvali>();
                if (compWeaponAvali == null)
                {
                    return;
                }

                if (compWeaponAvali.ownerPawn != null)
                {
                    __result = __result + "\n" + "EquipedWeaponOwnerPawn".Translate() + compWeaponAvali.ownerPawn.Name;
                }
                else
                {
                    __result = __result + "\n" + "EquipedWeaponOwnerPawn".Translate() + "None".Translate();
                }
            }
        }
Exemplo n.º 12
0
        public static void RegisterPosting(HaulExplicitlyPosting posting)
        {
            HaulExplicitlyJobManager manager = GetManager(posting.map);

            foreach (Thing i in posting.items)
            {
                {
                    ThingWithComps twc = i as ThingWithComps;
                    if (twc != null && twc.GetComp <CompForbiddable>() != null)
                    {
                        i.SetForbidden(false);
                    }
                }
                if (i.IsAHaulableSetToHaulable())
                {
                    i.ToggleHaulDesignation();
                }
                foreach (var p2 in manager.postings.Values)
                {
                    p2.TryRemoveItem(i);
                }
            }
            if (manager.postings.Keys.Contains(posting.id))
            {
                throw new ArgumentException("Posting ID " + posting.id + " already exists in this manager.");
            }
            manager.postings[posting.id] = posting;
        }
Exemplo n.º 13
0
        public static void GetGizmos_PostFix(Pawn __instance, ref IEnumerable <Gizmo> __result)
        {
            //Log.Message("1");
            Pawn_EquipmentTracker pawn_EquipmentTracker = __instance.equipment;

            if (pawn_EquipmentTracker != null)
            {
                //Log.Message("2");
                ThingWithComps thingWithComps = pawn_EquipmentTracker.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker);

                if (thingWithComps != null)
                {
                    //Log.Message("3");
                    CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>();
                    if (CompSlotLoadable != null)
                    {
                        if (GizmoGetter(CompSlotLoadable).Count <Gizmo>() > 0)
                        {
                            //Log.Message("4");
                            if (__instance != null)
                            {
                                if (__instance.Faction == Faction.OfPlayer)
                                {
                                    __result = __result.Concat <Gizmo>(GizmoGetter(CompSlotLoadable));
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public static float RangedDPS(ThingWithComps weapon, float speedBias, float averageSpeed, float range)
        {
            Verb           atkVerb  = (weapon.GetComp <CompEquippable>()).PrimaryVerb;
            VerbProperties atkProps = atkVerb.verbProps;

            if (atkProps.range * atkProps.range < range || atkProps.minRange * atkProps.minRange > range)
            {
                return(-1);
            }

            float hitChance       = atkProps.GetHitChanceFactor(weapon, range);
            float damage          = (atkProps.defaultProjectile == null) ? 0 : atkProps.defaultProjectile.projectile.GetDamageAmount(weapon);
            int   burstShot       = atkProps.burstShotCount;
            float speedFactor     = RangedSpeed(weapon);
            float speedFactorBase = speedFactor;

            float diffFromAverage = speedFactor - averageSpeed;

            diffFromAverage *= (speedBias - 1);
            speedFactor     += diffFromAverage;

            float rawDps = (damage * burstShot) / speedFactor;
            float Dps    = rawDps * hitChance;

            //Log.Message(weapon.LabelCap + " dps:" + rawDps + "dam:"+damage*burstShot + " spdfac:" + speedFactor + " spdFacBase:" + speedFactorBase);
            return(Dps);
        }
Exemplo n.º 15
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            var tc = t as ThingWithComps;

            if (t == null)
            {
                return(false);
            }
            var leakables  = tc.AllComps.Where(x => x is ILeakable);
            var thingComps = leakables as ThingComp[] ?? leakables.ToArray();

            if (!thingComps.Any())
            {
                return(false);
            }
            var biggestLeak = thingComps.Max(y => ((ILeakable)y).CurLeakRate());

            if (biggestLeak < 5f)
            {
                return(false);
            }
            bool flag = !forced;

            if (flag && biggestLeak < 1f)
            {
                return(false);
            }
            if (!t.IsForbidden(pawn))
            {
                LocalTargetInfo target = t;
                if (pawn.CanReserve(target, 1, -1, null, forced))
                {
                    if (t.Faction != pawn.Faction)
                    {
                        return(false);
                    }
                    ThingWithComps thingWithComps = t as ThingWithComps;
                    if (thingWithComps != null)
                    {
                        CompFlickable comp = thingWithComps.GetComp <CompFlickable>();
                        if (comp != null && !comp.SwitchIsOn)
                        {
                            return(false);
                        }
                    }

/*					if (this.FindBestFuel(pawn, t) == null)
 *                                      {
 *                                              ThingFilter fuelFilter = t.TryGetComp<CompRefuelable>().Props.fuelFilter;
 *                                              JobFailReason.Is("NoFuelToRefuel".Translate(new object[]
 *                                              {
 *                                                      fuelFilter.Summary
 *                                              }));
 *                                              return false;
 *                                      }*/
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 16
0
 static void Postfix(ThingWithComps __instance, ref Color __result)
 {
     if (__instance.def.Equals(UmbrellaDefOf.Parasol) || __instance.def.Equals(UmbrellaDefOf.FoldableParasol))
     {
         __result = __instance.GetComp <CompColorable>().Color;
     }
 }
Exemplo n.º 17
0
        public static float RangedDPSAverage(ThingWithComps weapon, float speedBias, float averageSpeed)
        {
            if (weapon == null)
            {
                return(0);
            }

            Verb           atkVerb         = (weapon.GetComp <CompEquippable>()).PrimaryVerb;
            VerbProperties atkProps        = atkVerb.verbProps;
            float          damage          = (atkProps.defaultProjectile == null) ? 0 : atkProps.defaultProjectile.projectile.GetDamageAmount(weapon);
            int            burstShot       = atkProps.burstShotCount;
            float          speedFactor     = RangedSpeed(weapon);
            float          speedFactorBase = speedFactor;

            float diffFromAverage = speedFactor - averageSpeed;

            diffFromAverage *= (speedBias - 1);
            speedFactor     += diffFromAverage;

            float rawDps = (damage * burstShot) / speedFactor;
            //Log.Message(weapon.LabelCap + " dps:" + rawDps + "dam:" + damage * burstShot + " spdfac:" + speedFactor + " spdFacBase:" + speedFactorBase);
            float DpsAvg = 0f;

            DpsAvg += rawDps * AdjustedAccuracy(atkProps, RangeCategory.Short, weapon);
            DpsAvg += rawDps * AdjustedAccuracy(atkProps, RangeCategory.Medium, weapon);
            DpsAvg += rawDps * AdjustedAccuracy(atkProps, RangeCategory.Long, weapon);
            return(DpsAvg / 3f);
        }
        public static void TriggerReceiversInNetworkRange(ThingWithComps origin, int channel, bool noTargetsMessage = true)
        {
            var comp = origin.GetComp <CompWirelessDetonationGridNode>();

            if (comp == null)
            {
                throw new Exception("Missing CompWirelessDetonationGridNode on sender");
            }
            var sample = comp.FindReceiversInNetworkRange().Where(pair => pair.Receiver.CurrentChannel == channel);
            // closer ones to their transmitters will go off first. This is used to simulate a bit of signal delay
            var sortedByDistance = sample.OrderBy(pair => pair.Transmitter.Position.DistanceToSquared(pair.Receiver.Position)).Select(pair => pair.Receiver);
            int counter          = 0;

            foreach (var receiver in sortedByDistance)
            {
                HugsLibController.Instance.TickDelayScheduler.ScheduleCallback(() => {
                    if (receiver.CanReceiveWirelessSignal)
                    {
                        receiver.ReceiveWirelessSignal(origin);
                    }
                }, TicksBetweenTriggers * counter++, GetHighestHolderInMap(origin));
            }
            if (counter == 0 && noTargetsMessage)
            {
                Messages.Message("Detonator_notargets".Translate(), origin, MessageTypeDefOf.RejectInput);
            }
        }
        private static void Postfix(Pawn __instance, ref IEnumerable <Gizmo> __result)
        {
            Pawn_EquipmentTracker equipment = __instance.equipment;

            if (equipment != null)
            {
                ThingWithComps primary = equipment.Primary;
                if (primary != null)
                {
                    CompToggleFireMode comp = primary.GetComp <CompToggleFireMode>();
                    if (comp != null)
                    {
                        if (GizmoGetter(comp).Count <Gizmo>() > 0)
                        {
                            if (__instance != null)
                            {
                                if (__instance.Faction == Faction.OfPlayer)
                                {
                                    __result = __result.Concat(GizmoGetter(comp));
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        public static void AddEquipment_PostFix(Pawn_EquipmentTracker __instance, ThingWithComps newEq)
        {
            var pawn = (Pawn)AccessTools.Field(typeof(Pawn_EquipmentTracker), "pawn").GetValue(__instance);

            var lightsaberEffect = newEq.TryGetComp <CompLightsaberActivatableEffect>();

            if (lightsaberEffect == null)
            {
                return;
            }

            if (pawn == null)
            {
                return;
            }

            if (pawn.Faction == null)
            {
                return;
            }

            if (pawn.Faction == Faction.OfPlayerSilentFail)
            {
                return;
            }

            var crystalSlot = newEq.GetComp <CompCrystalSlotLoadable>();

            if (crystalSlot == null)
            {
                return;
            }

            CrystalSlotter(crystalSlot, lightsaberEffect);
        }
Exemplo n.º 21
0
            public static void Postfix(Pawn __instance, DamageInfo dinfo, float totalDamageDealt)
            {
                if (__instance == null)
                {
                    return;
                }

                if (__instance.apparel != null)
                {
                    for (int i = 0; i < __instance.apparel.WornApparel.Count; ++i)
                    {
                        Apparel apparel = __instance.apparel.WornApparel[i];
                        CompIncreaseUserHediffSeverityWhenHurt comp = apparel.GetComp <CompIncreaseUserHediffSeverityWhenHurt>();

                        if (comp != null)
                        {
                            comp.PostPostApplyDamage(dinfo, totalDamageDealt);
                        }
                    }
                }

                if (__instance.equipment != null)
                {
                    for (int i = 0; i < __instance.equipment.AllEquipmentListForReading.Count; ++i)
                    {
                        ThingWithComps equipped = __instance.equipment.AllEquipmentListForReading[i];
                        CompIncreaseUserHediffSeverityWhenHurt comp = equipped.GetComp <CompIncreaseUserHediffSeverityWhenHurt>();

                        if (comp != null)
                        {
                            comp.PostPostApplyDamage(dinfo, totalDamageDealt);
                        }
                    }
                }
            }
Exemplo n.º 22
0
        public static void SetColorTwo(this Thing t, Color newColor, bool reportFailure = true)
        {
            ThingWithComps thingWithComps = t as ThingWithComps;

            if (thingWithComps == null)
            {
                if (reportFailure)
                {
                    Log.Error("SetColor on non-ThingWithComps " + t, false);
                }
                return;
            }
            CompColorableTwo comp = thingWithComps.GetComp <CompColorableTwo>();

            if (comp == null)
            {
                if (reportFailure)
                {
                    Log.Error("SetColor on Thing without CompColorableTwo " + t, false);
                }
                return;
            }
            if (comp.ColorTwo != newColor)
            {
                comp.ColorTwo = newColor;
            }
        }
Exemplo n.º 23
0
        // RimWorld.CharacterCardUtility
        public static void DrawCard(Rect rect, ThingWithComps selectedThing)
        {
            GUI.BeginGroup(rect);

            var compToggleDef = selectedThing.GetComp <CompToggleDef>();

            if (compToggleDef != null)
            {
                var ts    = Text.CalcSize(selectedThing.LabelCap).x;
                var y     = rect.y;
                var rect2 = new Rect(rect.width / 2 - ts + SpacingOffset, y, rect.width, HeaderSize);
                y        += rect2.height;
                Text.Font = GameFont.Medium;
                Widgets.Label(rect2, selectedThing.LabelCap);
                Text.Font = GameFont.Small;
                Widgets.ListSeparator(ref y, rect2.width, "Select one of the following:");

                // add all the buttons for the toggle defs
                foreach (var td in compToggleDef.toggleDefs)
                {
                    var rect3    = new Rect(0f, y, rect.width, 20f);
                    var isactive = false;
                    if (selectedThing.def == td)
                    {
                        isactive = true;
                    }
                    if (Widgets.RadioButtonLabeled(rect3, td.LabelCap, isactive))
                    {
                        //Log.Message(".. change location to "+td.LabelCap);

                        // CHange def then give it a new id. Hopefully nothing index on the id
                        var map = selectedThing.Map;
                        var loc = selectedThing.Position;
                        var rot = selectedThing.Rotation;
                        selectedThing.DeSpawn();
                        selectedThing.def           = td;
                        selectedThing.thingIDNumber = -1;
                        ThingIDMaker.GiveIDTo(selectedThing); // necessary
                        CompColorable colorable = selectedThing.TryGetComp <CompColorable>();
                        if (colorable != null)
                        {
                            colorable.Color = selectedThing.def.colorGenerator.NewRandomizedColor();
                        }
                        //    selectedThing.DrawColor = selectedThing.def.colorGenerator.NewRandomizedColor();
                        Graphic graphic = selectedThing.def.graphicData.GraphicColoredFor(selectedThing);
                        GenSpawn.Spawn(selectedThing, loc, map, rot);
                        FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                        Traverse  traverse   = Traverse.Create(selectedThing);
                        subgraphic.SetValue(selectedThing, graphic);
                        Find.Selector.Select(selectedThing);
                        break;
                    }
                    y += 25f;
                }
            }

            GUI.EndGroup();
        }
Exemplo n.º 24
0
 public static CompPowerPlant PowerPlantComp(this ThingWithComps parent)
 {
     if (_powerplants.TryGetValue(parent, out var powerplant))
     {
         return(powerplant);
     }
     powerplant = parent.GetComp <CompPowerPlant>();
     _powerplants.Add(parent, powerplant);
     return(powerplant);
 }
Exemplo n.º 25
0
 public static CompBreakdownable BreakdownableComp(this ThingWithComps parent)
 {
     if (_breakdownables.TryGetValue(parent, out var breakdownable))
     {
         return(breakdownable);
     }
     breakdownable = parent.GetComp <CompBreakdownable>();
     _breakdownables.Add(parent, breakdownable);
     return(breakdownable);
 }
Exemplo n.º 26
0
 public static CompFlickable FlickableComp(this ThingWithComps parent)
 {
     if (_flickables.TryGetValue(parent, out var flickable))
     {
         return(flickable);
     }
     flickable = parent.GetComp <CompFlickable>();
     _flickables.Add(parent, flickable);
     return(flickable);
 }
Exemplo n.º 27
0
        public static T RequireComp <T>(this ThingWithComps thing) where T : ThingComp
        {
            var c = thing.GetComp <T>();

            if (c == null)
            {
                Log.Error($"{thing.GetType().Name} requires ThingComp of type {nameof(T)} in def {thing.def.defName}");
            }
            return(c);
        }
Exemplo n.º 28
0
 public static CompRefuelable RefuelableComp(this ThingWithComps parent)
 {
     if (_refuelables.TryGetValue(parent, out var refuelable))
     {
         return(refuelable);
     }
     refuelable = parent.GetComp <CompRefuelable>();
     _refuelables.Add(parent, refuelable);
     return(refuelable);
 }
        public static T TryGetComp <T>(this Thing thing) where T : ThingComp
        {
            ThingWithComps thingWithComps = thing as ThingWithComps;

            if (thingWithComps == null)
            {
                return(null);
            }
            return(thingWithComps.GetComp <T>());
        }
 public static void ApplySilverTreatment(ThingWithComps n, List <Thing> silverToUse)
 {
     if (n?.GetComp <CompSilverTreated>() is CompSilverTreated silverTreatment)
     {
         for (int i = 0; i < silverToUse.Count(); i++)
         {
             silverToUse[i].Destroy(DestroyMode.Vanish);
         }
         silverTreatment.treated = true;
     }
 }
Exemplo n.º 31
0
 private void RegisterAllComponentsOf(ThingWithComps parentThing)
 {
     CompGasTrader comp = parentThing.GetComp<CompGasTrader>();
     if (comp != null)
     {
         if (this.traders.Contains(comp))
         {
             Log.Error("GasNet Adding GasComp " + comp + " which it already has.");
         }
         else
         {
             this.traders.Add(comp);
         }
     }
 }
Exemplo n.º 32
0
 private void DeregisterAllComponentsOf(ThingWithComps parentThing)
 {
     CompGasTrader comp = parentThing.GetComp<CompGasTrader>();
     if (comp != null)
     {
         this.traders.Remove(comp);
     }
 }