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));
                                }
                            }
                        }
                    }
                }
            }
        }
 public override Graphic PostGraphicEffects(Graphic graphic)
 {
     if (graphic != null)
     {
         ThingComp comp = this.parent.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable.CompSlotLoadable);
         if (comp != null)
         {
             CompSlotLoadable.CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable.CompSlotLoadable;
             SlotLoadable colorSlot = compSlotLoadable.Slots.FirstOrDefault((SlotLoadable x) => ((SlotLoadableDef)x.def).doesChangeColor == true);
             if (colorSlot != null)
             {
                 if (colorSlot.SlotOccupant != null)
                 {
                     if (graphic.Shader != null)
                     {
                         Graphic result = graphic.GetColoredVersion(graphic.Shader, colorSlot.SlotOccupant.DrawColor, colorSlot.SlotOccupant.DrawColorTwo);
                         if (result != null)
                         {
                             return(result);
                         }
                     }
                 }
             }
         }
     }
     return(base.PostGraphicEffects(graphic));
 }
        public static void GetStatValue_PostFix(ref float __result, Thing thing, StatDef stat, bool applyPostProcess)
        {
            __result += CompSlotLoadable.CheckThingSlotsForStatAugment(thing, stat);

            /*
             * //Log.Message("1");
             * ThingWithComps ownerEquipment = thing as ThingWithComps;
             * if (ownerEquipment != null)
             * {
             * ThingComp comp = ownerEquipment.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable);
             * if (comp != null)
             * {
             * CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable;
             * if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0)
             * {
             * List<SlotLoadable> statSlots = compSlotLoadable.Slots.FindAll((SlotLoadable z) => !z.IsEmpty() && ((SlotLoadableDef)z.def).doesChangeStats == true);
             * if (statSlots != null && statSlots.Count > 0)
             * {
             * foreach (SlotLoadable slot in statSlots)
             * {
             * CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp<CompSlottedBonus>();
             * if (slotBonus != null)
             * {
             * if (slotBonus.Props != null)
             * {
             * if (slotBonus.Props.statModifiers != null && slotBonus.Props.statModifiers.Count > 0)
             * {
             * //StatModifier thisStat = slotBonus.Props.statModifiers.FirstOrDefault(
             * //(StatModifier y) => y.stat == stat &&
             * //(y.stat.category == StatCategoryDefOf.Weapon ||
             * //y.stat.category == StatCategoryDefOf.EquippedStatOffsets
             * //));
             * //if (thisStat != null)
             * //{
             * //        __result += thisStat.value;
             * //    }
             * //    foreach ( StatModifier thisStat in slotBonus.Props.statModifiers ) {
             * //        if ( thisStat.stat == stat ) {
             * //            //Log.Message("GetValue_PostFix adding in "+thisStat.stat+":"+thisStat.value);
             * //            __result += thisStat.value;
             * //        }
             * //    }
             * //}
             * }
             * }
             * }
             *      }
             *  }
             * }
             * }
             */
        }
        /// <summary>
        /// Applies the special properties to the slot loadable.
        /// </summary>
        /// <param name="__instance"></param>
        /// <param name="dinfo"></param>
        /// <param name="totalDamageDealt"></param>
        public static void PostApplyDamage_PostFix(Pawn __instance, DamageInfo dinfo, float totalDamageDealt)
        {
            if (__instance == null)
            {
                return;
            }
            if (__instance.Dead || __instance.equipment == null)
            {
                return;
            }
            ThingWithComps thingWithComps = __instance.equipment.Primary;

            if (thingWithComps != null)
            {
                ThingComp comp = thingWithComps.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable);
                if (comp != null)
                {
                    CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable;
                    if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0)
                    {
                        foreach (SlotLoadable slot in compSlotLoadable.Slots)
                        {
                            if (!slot.IsEmpty())
                            {
                                CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>();
                                if (slotBonus != null)
                                {
                                    if (slotBonus.Props != null)
                                    {
                                        SlotBonusProps_DefensiveHealChance defensiveHealChance = slotBonus.Props.defensiveHealChance;
                                        if (defensiveHealChance != null)
                                        {
                                            //Log.Message("defensiveHealingCalled");
                                            float randValue = Rand.Value;
                                            //Log.Message("randValue = " + randValue.ToString());
                                            if (randValue <= defensiveHealChance.chance)
                                            {
                                                MoteMaker.ThrowText(__instance.DrawPos, __instance.Map, "Heal Chance: Success", 6f);
                                                ApplyHealing(__instance, defensiveHealChance.woundLimit);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 public static IEnumerable <Gizmo> GizmoGetter(CompSlotLoadable CompSlotLoadable)
 {
     //Log.Message("5");
     if (CompSlotLoadable.GizmosOnEquip)
     {
         //Log.Message("6");
         //Iterate EquippedGizmos
         IEnumerator <Gizmo> enumerator = CompSlotLoadable.EquippedGizmos().GetEnumerator();
         while (enumerator.MoveNext())
         {
             //Log.Message("7");
             Gizmo current = enumerator.Current;
             yield return(current);
         }
     }
 }
        public static void get_Graphic_PostFix(Thing __instance, ref Graphic __result)
        {
            ThingWithComps thingWithComps = __instance as ThingWithComps;

            if (thingWithComps != null)
            {
                //Log.Message("3");
                CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>();
                if (CompSlotLoadable != null)
                {
                    //ThingComp activatableEffect = thingWithComps.AllComps.FirstOrDefault<ThingComp>((ThingComp y) => y.GetType().ToString() == "CompActivatableEffect.CompActivatableEffect");

                    SlotLoadable slot = CompSlotLoadable.ColorChangingSlot;
                    if (slot != null)
                    {
                        if (!slot.IsEmpty())
                        {
                            CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>();
                            if (slotBonus != null)
                            {
                                //if (activatableEffect != null)
                                //{
                                //    AccessTools.Field(activatableEffect.GetType(), "overrideColor").SetValue(activatableEffect, slot.SlotOccupant.DrawColor);
                                //    Log.ErrorOnce("GraphicPostFix_Called_Activatable", 1866);
                                //}
                                //else
                                //{
                                Graphic tempGraphic = (Graphic)AccessTools.Field(typeof(Thing), "graphicInt").GetValue(__instance);
                                if (tempGraphic != null)
                                {
                                    if (tempGraphic.Shader != null)
                                    {
                                        tempGraphic = tempGraphic.GetColoredVersion(tempGraphic.Shader, slotBonus.Props.color, slotBonus.Props.color); //slot.SlotOccupant.DrawColor;
                                        __result    = tempGraphic;
                                        //Log.Message("SlotLoadableDraw");
                                    }
                                }
                            }
                            //Log.ErrorOnce("GraphicPostFix_Called_5", 1866);
                            //}
                        }
                    }
                }
            }
        }
Example #7
0
        // Get the thing's modificaiton to stat from it's slots
        public static float CheckThingSlotsForStatAugment(Thing slottedThing, StatDef stat)
        {
            float retval = 0.0f;
            List <SlotLoadable> slots = CompSlotLoadable.GetSlots(slottedThing);

            if (slots != null)
            {
                foreach (SlotLoadable slot in slots)
                {
                    if (!slot.IsEmpty())
                    {
                        Thing slottable = slot.SlotOccupant;
                        retval += DetermineSlottableStatAugment(slottable, stat);
                    }
                }
            }
            return(retval);
        }
        //=================================== COMPSLOTLOADABLE

        public static void DrawThingRow_PostFix(ITab_Pawn_Gear __instance, ref float y, float width, Thing thing, bool showDropButtonIfPrisoner = false)
        {
            //Log.Message("1");
            ThingWithComps thingWithComps = thing as ThingWithComps;

            if (thingWithComps != null)
            {
                ThingComp comp = thingWithComps.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable);
                if (comp != null)
                {
                    CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable;
                    if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0)
                    {
                        foreach (SlotLoadable slot in compSlotLoadable.Slots)
                        {
                            if (!slot.IsEmpty())
                            {
                                Rect rect = new Rect(0f, y, width, 28f);
                                Widgets.InfoCardButton(rect.width - 24f, y, slot.SlotOccupant);
                                rect.width -= 24f;
                                //bool CanControl = (bool)AccessTools.Method(typeof(ITab_Pawn_Gear), "get_CanControl").Invoke(__instance, null);
                                if (Mouse.IsOver(rect))
                                {
                                    GUI.color = HarmonyCompSlotLoadable.HighlightColor;
                                    GUI.DrawTexture(rect, TexUI.HighlightTex);
                                }
                                if (slot.SlotOccupant.def.DrawMatSingle != null && slot.SlotOccupant.def.DrawMatSingle.mainTexture != null)
                                {
                                    Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), slot.SlotOccupant, 1f);
                                }
                                Text.Anchor = TextAnchor.MiddleLeft;
                                GUI.color   = HarmonyCompSlotLoadable.ThingLabelColor;
                                Rect   rect4 = new Rect(36f, y, width - 36f, 28f);
                                string text  = slot.SlotOccupant.LabelCap;
                                Widgets.Label(rect4, text);
                                y += 28f;
                            }
                        }
                    }
                }
            }
        }
        public override void ActiveTick()
        {
            //Log.Message("1");
            ThingComp comp = this.parent.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable.CompSlotLoadable);

            if (comp != null)
            {
                //Log.Message("2");
                CompSlotLoadable.CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable.CompSlotLoadable;
                SlotLoadable colorSlot = compSlotLoadable.Slots.FirstOrDefault((SlotLoadable x) => ((SlotLoadableDef)x.def).doesChangeColor == true);
                if (colorSlot != null)
                {
                    //Log.Message("3");
                    if (colorSlot.IsEmpty())
                    {
                        this.Deactivate();
                    }
                }
            }
        }
 public static void DrawColorTwoPostFix(Thing __instance, ref Color __result)
 {
     if (__instance is ThingWithComps thingWithComps)
     {
         //Log.Message("3");
         CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>();
         if (CompSlotLoadable != null)
         {
             SlotLoadable slot = CompSlotLoadable.SecondColorChangingSlot;
             if (slot != null)
             {
                 if (!slot.IsEmpty())
                 {
                     __result = slot.SlotOccupant.DrawColor;
                     __instance.Graphic.colorTwo = slot.SlotOccupant.DrawColor;
                 }
             }
         }
     }
 }
Example #11
0
        // Grab slots of the thing if they exists. Returns null if none
        public static List <SlotLoadable> GetSlots(Thing someThing)
        {
            List <SlotLoadable> retval = null;

            if (someThing is ThingWithComps thingWithComps)
            {
                ThingComp comp = thingWithComps.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable);
                if (comp != null)
                {
                    CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable;

                    if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0)
                    {
                        retval = compSlotLoadable.Slots;
                    }
                }
            }

            return(retval);
        }
        public override bool CanActivate()
        {
            //Log.Message("1");
            ThingComp comp = this.parent.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable.CompSlotLoadable);

            if (comp != null)
            {
                //Log.Message("2");
                CompSlotLoadable.CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable.CompSlotLoadable;
                SlotLoadable colorSlot = compSlotLoadable.Slots.FirstOrDefault((SlotLoadable x) => ((SlotLoadableDef)x.def).doesChangeColor == true);
                if (colorSlot != null)
                {
                    //Log.Message("3");
                    if (colorSlot.SlotOccupant != null)
                    {
                        return(true);
                    }
                }//
            }
            Messages.Message("KyberCrystalRequired".Translate(), MessageSound.RejectInput);
            return(false);
        }
        // debugging

        /*
         * public static void TicksPerMove_PostFix(Pawn __instance, ref float __result, bool diagonal) {
         *  if ( __instance.IsColonist )  {
         *      float num = __instance.GetStatValue(StatDefOf.MoveSpeed, true);
         *      Log.Message("move speed : "+__instance.Name+ " : (GetStatValue of MoveSpeed:" +num+") (TicksPerMove:"+__result+")");
         *  }
         * } */

        //try to extend this
        public static void StatOffsetFromGear_PostFix(ref float __result, Thing gear, StatDef stat) => __result += CompSlotLoadable.CheckThingSlotsForStatAugment(gear, stat);
 public static void GetStatValue_PostFix(ref float __result, Thing thing, StatDef stat, bool applyPostProcess) => __result += CompSlotLoadable.CheckThingSlotsForStatAugment(thing, stat);
        public static void AddHumanlikeOrders_PostFix(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts)
        {
            IntVec3 c = IntVec3.FromVector3(clickPos);

            ThingWithComps slotLoadable = pawn.equipment.AllEquipmentListForReading.FirstOrDefault((ThingWithComps x) => x.TryGetComp <CompSlotLoadable>() != null);

            if (slotLoadable != null)
            {
                CompSlotLoadable compSlotLoadable = slotLoadable.GetComp <CompSlotLoadable>();
                if (compSlotLoadable != null)
                {
                    List <Thing> thingList = c.GetThingList(pawn.Map);

                    foreach (SlotLoadable slot in compSlotLoadable.Slots)
                    {
                        Thing loadableThing = thingList.FirstOrDefault((Thing y) => slot.CanLoad(y.def));
                        if (loadableThing != null)
                        {
                            FloatMenuOption itemSlotLoadable;
                            string          labelShort = loadableThing.Label;
                            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                            {
                                itemSlotLoadable = new FloatMenuOption("CannotEquip".Translate(new object[]
                                {
                                    labelShort
                                }) + " (" + "Incapable".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null);
                            }
                            else if (!pawn.CanReach(loadableThing, PathEndMode.ClosestTouch, Danger.Deadly))
                            {
                                itemSlotLoadable = new FloatMenuOption("CannotEquip".Translate(new object[]
                                {
                                    labelShort
                                }) + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null);
                            }
                            else if (!pawn.CanReserve(loadableThing, 1))
                            {
                                itemSlotLoadable = new FloatMenuOption("CannotEquip".Translate(new object[]
                                {
                                    labelShort
                                }) + " (" + "ReservedBy".Translate(new object[]
                                {
                                    pawn.Map.physicalInteractionReservationManager.FirstReserverOf(loadableThing).LabelShort
                                }) + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null);
                            }
                            else
                            {
                                string text2 = "Equip".Translate(new object[]
                                {
                                    labelShort
                                });
                                itemSlotLoadable = new FloatMenuOption(text2, delegate
                                {
                                    loadableThing.SetForbidden(false, true);
                                    pawn.jobs.TryTakeOrderedJob(new Job(DefDatabase <JobDef> .GetNamed("GatherSlotItem"), loadableThing));
                                    MoteMaker.MakeStaticMote(loadableThing.DrawPos, loadableThing.Map, ThingDefOf.Mote_FeedbackEquip, 1f);
                                    //PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.EquippingWeapons, KnowledgeAmount.Total);
                                }, MenuOptionPriority.High, null, null, 0f, null, null);
                            }
                            opts.Add(itemSlotLoadable);
                        }
                    }
                }
            }
        }
        // RimWorld.Verb_MeleeAttack
        public static void DamageInfosToApply_PostFix(Verb_MeleeAttack __instance, ref IEnumerable <DamageInfo> __result, LocalTargetInfo target)
        {
            List <DamageInfo> newList = new List <DamageInfo>();
            //__result = null;
            ThingWithComps ownerEquipment = __instance.ownerEquipment;

            if (ownerEquipment != null)
            {
                //Log.Message("1");
                ThingComp comp = ownerEquipment.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable);
                if (comp != null)
                {
                    //Log.Message("2");
                    CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable;
                    if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0)
                    {
                        //Log.Message("3");
                        List <SlotLoadable> statSlots = compSlotLoadable.Slots.FindAll((SlotLoadable z) => !z.IsEmpty() && ((SlotLoadableDef)z.def).doesChangeStats == true);
                        if (statSlots != null && statSlots.Count > 0)
                        {
                            //Log.Message("4");
                            foreach (SlotLoadable slot in statSlots)
                            {
                                //Log.Message("5");
                                CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>();
                                if (slotBonus != null)
                                {
                                    //Log.Message("6");
                                    Type superClass = __instance.GetType().BaseType;
                                    if (slotBonus.Props.damageDef != null)
                                    {
                                        //Log.Message("7");
                                        float            num = __instance.verbProps.AdjustedMeleeDamageAmount(__instance, __instance.CasterPawn, __instance.ownerEquipment);
                                        DamageDef        def = __instance.verbProps.meleeDamageDef;
                                        BodyPartGroupDef weaponBodyPartGroup = null;
                                        HediffDef        weaponHediff        = null;
                                        if (__instance.CasterIsPawn)
                                        {
                                            //Log.Message("8");
                                            if (num >= 1f)
                                            {
                                                weaponBodyPartGroup = __instance.verbProps.linkedBodyPartsGroup;
                                                if (__instance.ownerHediffComp != null)
                                                {
                                                    weaponHediff = __instance.ownerHediffComp.Def;
                                                }
                                            }
                                            else
                                            {
                                                num = 1f;
                                                def = DamageDefOf.Blunt;
                                            }
                                        }

                                        //Log.Message("9");
                                        ThingDef def2;
                                        if (__instance.ownerEquipment != null)
                                        {
                                            def2 = __instance.ownerEquipment.def;
                                        }
                                        else
                                        {
                                            def2 = __instance.CasterPawn.def;
                                        }

                                        //Log.Message("10");
                                        Vector3 angle = (target.Thing.Position - __instance.CasterPawn.Position).ToVector3();

                                        //Log.Message("11");
                                        Thing caster = __instance.caster;

                                        //Log.Message("12");
                                        int newdamage = GenMath.RoundRandom(num);
//                                        Log.Message("applying damage "+newdamage+" out of "+num);
                                        DamageInfo damageInfo = new DamageInfo(slotBonus.Props.damageDef, newdamage, -1f, caster, null, def2);
                                        damageInfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                                        damageInfo.SetWeaponBodyPartGroup(weaponBodyPartGroup);
                                        damageInfo.SetWeaponHediff(weaponHediff);
                                        damageInfo.SetAngle(angle);

                                        //Log.Message("13");
                                        newList.Add(damageInfo);

                                        __result = newList.AsEnumerable <DamageInfo>();
                                    }
                                    SlotBonusProps_VampiricEffect vampiricEffect = slotBonus.Props.vampiricHealChance;
                                    if (vampiricEffect != null)
                                    {
                                        //Log.Message("vampiricHealingCalled");
                                        float randValue = Rand.Value;
                                        //Log.Message("randValue = " + randValue.ToString());

                                        if (randValue <= vampiricEffect.chance)
                                        {
                                            MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Vampiric Effect: Success", 6f);
                                            //MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Success".Translate(), 6f);
                                            ApplyHealing(__instance.caster, vampiricEffect.woundLimit, target.Thing);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

            Toil toil = new Toil()
            {
                initAction = delegate
                {
                    this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch);
                },
                defaultCompleteMode = ToilCompleteMode.PatherArrival
            };

            toil.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(toil);

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing itemToGather = this.CurJob.targetA.Thing;
                    //bool flag = false;
                    Thing itemToGatherSplit;
                    if (itemToGather.def.stackLimit > 1 && itemToGather.stackCount > 1)
                    {
                        itemToGatherSplit = itemToGather.SplitOff(1);
                    }
                    else
                    {
                        itemToGatherSplit = itemToGather;
                        //flag = true;
                    }

                    //Find the compslotloadable
                    Pawn_EquipmentTracker pawn_EquipmentTracker = this.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");
                            CompSlotLoadable CompSlotLoadable = thingWithComps.GetComp <CompSlotLoadable>();
                            if (CompSlotLoadable != null)
                            {
                                CompSlotLoadable.TryLoadSlot(itemToGather);
                                if (thingWithComps.def.soundInteract != null)
                                {
                                    thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.pawn.Position, this.pawn.Map, false));
                                }
                                //if (flag)
                                //{
                                //    thingWithComps.DeSpawn();
                                //}
                            }
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }