static void Postfix(ref Pawn p, ref float __result) { ExtendedDataStorage store = GiddyUpCore.Base.Instance.GetExtendedDataStorage(); if (store == null)//this check is needed because some mods call this function on world load { return; } ExtendedPawnData pawnData = store.GetExtendedDataFor(p); if (pawnData == null || pawnData.caravanRider == null) { return; } else { //new solution A - more forgiving //float riderTotalMass = pawnData.caravanRider.GetStatValue(StatDefOf.Mass); //float riderGearInvMass = MassUtility.GearAndInventoryMass(pawnData.caravanRider); //float riderBodyMass = riderTotalMass - riderGearInvMass; //__result -= riderBodyMass; //__result = Math.Max(__result, 0f); //new solution B - more restrictive float riderTotalMass = pawnData.caravanRider.GetStatValue(StatDefOf.Mass); float riderGearInvMass = MassUtility.GearAndInventoryMass(pawnData.caravanRider); float riderBodyMass = riderTotalMass - riderGearInvMass; float riderCapacity = MassUtility.Capacity(pawnData.caravanRider); float riderGrossMass = riderBodyMass + riderCapacity; __result -= riderGrossMass; __result = Math.Max(__result, 0f); } }
public static bool CheckCanCarryGift(List <Tradeable> tradeables, ITrader trader) { Pawn pawn = trader as Pawn; if (pawn == null) { return(true); } float num = 0f; float num2 = 0f; Lord lord = pawn.GetLord(); if (lord != null) { for (int i = 0; i < lord.ownedPawns.Count; i++) { Pawn pawn2 = lord.ownedPawns[i]; TraderCaravanRole traderCaravanRole = pawn2.GetTraderCaravanRole(); if ((pawn2.RaceProps.Humanlike && traderCaravanRole != TraderCaravanRole.Guard) || traderCaravanRole == TraderCaravanRole.Carrier) { num += MassUtility.Capacity(pawn2); num2 += MassUtility.GearAndInventoryMass(pawn2); } } } else { num = MassUtility.Capacity(pawn); num2 = MassUtility.GearAndInventoryMass(pawn); } float num3 = 0f; for (int j = 0; j < tradeables.Count; j++) { if (tradeables[j].ActionToDo == TradeAction.PlayerSells) { int num4 = Mathf.Min(tradeables[j].CountToTransferToDestination, tradeables[j].CountHeldBy(Transactor.Colony)); if (num4 > 0) { num3 += tradeables[j].AnyThing.GetStatValue(StatDefOf.Mass) * (float)num4; } } } if (num2 + num3 <= num) { return(true); } float num5 = num - num2; if (num5 <= 0f) { Messages.Message("MessageCantGiveGiftBecauseCantCarryEncumbered".Translate(), MessageTypeDefOf.RejectInput, historical: false); } else { Messages.Message("MessageCantGiveGiftBecauseCantCarry".Translate(num3.ToStringMass(), num5.ToStringMass()), MessageTypeDefOf.RejectInput, historical: false); } return(false); }
public override void TransformValue(StatRequest req, ref float val) { if (req.Thing is Pawn pawn) { if (Compatibility_GiddyUp.GetMount(pawn) != null) { return; } val = Mathf.Clamp(Mathf.RoundToInt(val * _modifier), 0.1f, 100f); if (!MassUtility.CanEverCarryAnything(pawn) || _carrymodifier <= 0f) { return; } var pawnMass = pawn.GetStatValue(StatDefOf.Mass); var ignoredMass = pawnMass * (pawn.RaceProps.packAnimal ? 0.5f : 0.2f); // add our own modifiers var mass = MassUtility.GearAndInventoryMass(pawn); if (Compatibility_GiddyUp.GetRider(pawn) is Pawn rider) { mass += rider.GetStatValue(StatDefOf.Mass, true); var riderCarriedThing = rider.carryTracker.CarriedThing; if (riderCarriedThing != null) { mass += riderCarriedThing.stackCount * riderCarriedThing.GetStatValue(StatDefOf.Mass, true); if (riderCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier val *= 1.666f; } } } var capacity = pawn.GetStatValue(StatDefOf.CarryingCapacity, true); var pawnCarriedThing = pawn.carryTracker.CarriedThing; if (pawnCarriedThing != null) { mass += pawnCarriedThing.stackCount * pawnCarriedThing.GetStatValue(StatDefOf.Mass, true); if (pawnCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier val *= 1.666f; } } var encumbrance = Mathf.Max(mass - ignoredMass, 0f) / capacity; var modifier = 1 / (1 + (encumbrance * _carrymodifier)); val *= modifier; } }
public static bool DrawThingRow(object tab, ref float y, ref float width, Thing thing, bool inventory) { if (!Settings.gui_manual_unload) { return(true); } Pawn SelPawn = (Pawn)ITab_Pawn_Gear_Utility.LSelPawnForGear.GetValue(tab); bool CanControl = (bool)ITab_Pawn_Gear_Utility.LCanControl.GetValue(tab); Color hColor = new Color(1f, 0.8f, 0.8f, 1f); //Log.Message($"CanControl={CanControl}, pc={SelPawn.IsColonistPlayerControlled}, spawned={SelPawn.Spawned}, pcHome={SelPawn.Map.IsPlayerHome}, bcoded={IsBiocodedOrLinked(SelPawn, thing, inventory)}, locked={IsLocked(SelPawn, thing)}"); Rect rect = new Rect(0f, y, width, 28f); if ((thing is ThingWithComps) && CanControl && (inventory || SelPawn.IsColonistPlayerControlled || SelPawn.Spawned && !SelPawn.Map.IsPlayerHome) && !IsBiocodedOrLinked(SelPawn, thing, inventory) && !IsLocked(SelPawn, thing)) { Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); CompUnloadChecker c = CompUnloadChecker.GetChecker(thing, false, true); if (c.ShouldUnload) { TooltipHandler.TipRegion(rect2, "UnloadThingCancel".Translate()); var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing_Cancel"), hColor)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = false; if (MassUtility.Capacity(SelPawn, null) < MassUtility.GearAndInventoryMass(SelPawn) && thing.stackCount * thing.GetStatValue(StatDefOf.Mass, true) > 0 && !thing.def.destroyOnDrop) { ITab_Pawn_Gear_Utility.LInterfaceDrop.Invoke(tab, new object[] { thing }); } } GUI.color = cl; } else { TooltipHandler.TipRegion(rect2, "UnloadThing".Translate()); var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing"), Color.white)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = true; } } width -= 24f; } return(true); }
public static bool Prefix(ITab_Pawn_Gear __instance, ref float y, ref float width, Thing thing, bool inventory) { if (!Settings.gui_manual_unload) { return(true); } bool CanControl = Traverse.Create(__instance).Property("CanControl").GetValue <bool>(); Pawn SelPawnForGear = Traverse.Create(__instance).Property("SelPawnForGear").GetValue <Pawn>(); Rect rect = new Rect(0f, y, width, 28f); if (CanControl && (SelPawnForGear.IsColonistPlayerControlled || SelPawnForGear.Spawned && !SelPawnForGear.Map.IsPlayerHome) && (thing is ThingWithComps) && !IsBiocodedOrLinked(SelPawnForGear, thing, inventory) && !IsLocked(SelPawnForGear, thing)) { Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); CompUnloadChecker c = CompUnloadChecker.GetChecker(thing, false, true); if (c.ShouldUnload) { TooltipHandler.TipRegion(rect2, "UnloadThingCancel".Translate()); //weird shenanigans with colors var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing_Cancel"), hColor)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = false; if (MassUtility.Capacity(SelPawnForGear, null) < MassUtility.GearAndInventoryMass(SelPawnForGear) && thing.stackCount * thing.GetStatValue(StatDefOf.Mass, true) > 0 && !thing.def.destroyOnDrop) { Thing t; SelPawnForGear.inventory.innerContainer.TryDrop(thing, SelPawnForGear.Position, SelPawnForGear.Map, ThingPlaceMode.Near, out t, null, null); } } GUI.color = cl; } else { TooltipHandler.TipRegion(rect2, "UnloadThing".Translate()); if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing"))) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = true; } } width -= 24f; } return(true); }
private void TryDrawMassInfo(ref float curY, float width) { if (this.SelPawnForGear.Dead || !this.ShouldShowInventory(this.SelPawnForGear)) { return; } Rect rect = new Rect(0f, curY, width, 22f); float num = MassUtility.GearAndInventoryMass(this.SelPawnForGear); float num2 = MassUtility.Capacity(this.SelPawnForGear, null); Widgets.Label(rect, "MassCarried".Translate(num.ToString("0.##"), num2.ToString("0.##"))); curY += 22f; }
private void TryDrawMassInfo(ref float curY, float width) { if (this.SelPawnForCargo.GetComp <CompShips>().beached) { return; } Rect rect = new Rect(0f, curY, width, 22f); float num = MassUtility.GearAndInventoryMass(this.SelPawnForCargo); float num2 = MassUtility.Capacity(this.SelPawnForCargo, null); Widgets.Label(rect, "MassCarried".Translate(num.ToString("0.##"), num2.ToString("0.##"))); curY += 22f; }
public static void TryDrawMassInfo(Pawn pawn, ref float curY, float width) { if (pawn.Dead || !ShouldShowInventory(pawn)) { return; } Rect rect = new Rect(0f, curY, width, 22f); float num = MassUtility.GearAndInventoryMass(pawn); float num2 = MassUtility.Capacity(pawn, null); Widgets.Label(rect, "MassCarried".Translate(num.ToString("0.##"), num2.ToString("0.##"))); curY += 22f; }
private void TryDrawMassInfo1(Rect rect) { if (this.SelPawnForGear.Dead || !this.ShouldShowInventory(this.SelPawnForGear)) { return; } Rect rect1 = new Rect(rect.x, rect.y, 24f, 24f); GUI.DrawTexture(rect1, ContentFinder <Texture2D> .Get("UI/Icons/Sandy_MassCarried_Icon", true)); TooltipHandler.TipRegion(rect1, "SandyMassCarried".Translate()); float num = MassUtility.GearAndInventoryMass(this.SelPawnForGear); float num2 = MassUtility.Capacity(this.SelPawnForGear, null); Rect rect2 = new Rect(rect.x + 30f, rect.y + 2f, 104f, 24f); Widgets.Label(rect2, "SandyMassValue".Translate(num.ToString("0.##"), num2.ToString("0.##"))); }
private void DrawMassInfo(Vector2 topLeft) { if (SelPawnForGear.Dead || !ShouldShowInventory(SelPawnForGear)) { return; } Rect iconRect = new Rect(topLeft.x, topLeft.y, SmallIconSize, SmallIconSize); GUI.DrawTexture(iconRect, ContentFinder <Texture2D> .Get("UI/Icons/Sandy_MassCarried_Icon", true)); TooltipHandler.TipRegion(iconRect, "SandyMassCarried".Translate()); float mass = MassUtility.GearAndInventoryMass(SelPawnForGear); float capacity = MassUtility.Capacity(SelPawnForGear, null); Rect textRect = new Rect(topLeft.x + SmallIconSize + MediumMargin, topLeft.y + SmallIconMargin, statBoxWidth - SmallIconSize, SmallIconSize); Widgets.Label(textRect, "SandyMassValue".Translate(mass.ToString("0.##"), capacity.ToString("0.##"))); }
static void Postfix(Pawn p, ref StringBuilder explanation, ref float __result) { float bonus = 0f; bool hasMountedTurret = false; if (p.health != null && p.health.hediffSet.HasHediff(WTH_DefOf.WTH_MountedTurret)) { hasMountedTurret = true; bonus += MassUtility.GearAndInventoryMass(p); if (p.inventory.GetDirectlyHeldThings().FirstOrDefault((Thing t) => t is ThingWithComps twc && twc.TryGetComp <CompMountable>() is CompMountable comp) is Thing mountedTurret) { bonus += mountedTurret.def.BaseMass; } } if (p.def.HasModExtension <DefModExtension_PawnMassCapacity>() && !hasMountedTurret) { bonus += p.def.GetModExtension <DefModExtension_PawnMassCapacity>().bonusMassCapacity; } __result += bonus; float offset = 0; if (explanation == null) { explanation = new StringBuilder(); } if (explanation != null && bonus > 0) { explanation.AppendLine("- " + p.def.label + ": " + bonus.ToStringByStyle(ToStringStyle.Integer, ToStringNumberSense.Offset)); } if (p.health != null && p.health.hediffSet != null) { foreach (Hediff h in p.health.hediffSet.hediffs) { if (h.def.GetModExtension <DefModextension_Hediff>() is DefModextension_Hediff modExt && modExt.carryingCapacityOffset != 0) { explanation.AppendLine(); explanation.AppendLine("- " + h.def.label + ": " + modExt.carryingCapacityOffset.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Offset)); offset += modExt.carryingCapacityOffset; } } } __result += offset * __result; }
private void TryDrawMassInfo(ref float curY, float width) { if (SelPawnForCargo.beached) { return; } Rect rect = new Rect(0f, curY, width, StandardLineHeight); float cannonsNum = 0f; if (SelPawnForCargo.TryGetComp <CompCannons>() != null) { foreach (VehicleTurret cannon in SelPawnForCargo.CompCannons.Cannons) { cannonsNum += cannon.loadedAmmo is null ? 0f : cannon.loadedAmmo.BaseMass * cannon.shellCount; } } float num = MassUtility.GearAndInventoryMass(SelPawnForCargo) + cannonsNum; float num2 = MassUtility.Capacity(SelPawnForCargo, null); Widgets.Label(rect, "MassCarried".Translate(num.ToString("0.##"), num2.ToString("0.##"))); curY += StandardLineHeight; }
static void Postfix(Pawn p, ref StringBuilder explanation, ref float __result) { float bonus = 0f; bool hasMountedTurret = false; if (p.health != null && p.health.hediffSet.HasHediff(WTH_DefOf.WTH_MountedTurret)){ hasMountedTurret = true; bonus += MassUtility.GearAndInventoryMass(p); if(p.inventory.GetDirectlyHeldThings().FirstOrDefault((Thing t) => t is ThingWithComps twc && twc.TryGetComp<CompMountable>() is CompMountable comp) is Thing mountedTurret) { bonus += mountedTurret.def.BaseMass; } } if(p.def.HasModExtension<DefModExtension_PawnMassCapacity>() && !hasMountedTurret) { bonus += p.def.GetModExtension<DefModExtension_PawnMassCapacity>().bonusMassCapacity; } __result += bonus; if (explanation != null && bonus > 0) { explanation.AppendLine(); } }
private float GetMass(Thing thing) { if (thing == null) { return(0f); } float num = thing.GetStatValue(StatDefOf.Mass, true); if (thing is Pawn pawn) { if (InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignorePawnInventoryMass)) { num -= MassUtility.InventoryMass(pawn); } } else if (ignoreSpawnedCorpseGearAndInventoryMass) { if (thing is Corpse corpse && corpse.Spawned) { num -= MassUtility.GearAndInventoryMass(corpse.InnerPawn); } } return(num); }
public override string ExplanationPart(StatRequest req) { if (_modifier <= 0f) { return(string.Empty); } var sb = new StringBuilder(); if (req.Thing is Pawn pawn) { if (Compatibility_GiddyUp.GetMount(pawn) != null) { return(string.Empty); } sb.AppendLine($"Global speed factor: x{_modifier.ToStringByStyle(ToStringStyle.FloatMaxOne)}"); if (!MassUtility.CanEverCarryAnything(pawn) || _carrymodifier <= 0f) { return(sb.ToString()); } var pawnMass = pawn.GetStatValue(StatDefOf.Mass); var ignoredMass = pawnMass * (pawn.RaceProps.packAnimal ? 0.5f : 0.2f); // add our own modifiers var mass = MassUtility.GearAndInventoryMass(pawn); if (Compatibility_GiddyUp.GetRider(pawn) is Pawn rider) { sb.AppendLine($"Mounted by {rider}, adding {rider.GetStatValue(StatDefOf.Mass, true)} to carried mass."); mass += rider.GetStatValue(StatDefOf.Mass, true); var riderCarriedThing = rider.carryTracker.CarriedThing; if (riderCarriedThing != null) { mass += riderCarriedThing.stackCount * riderCarriedThing.GetStatValue(StatDefOf.Mass, true); if (riderCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier sb.AppendLine($"Carrying {riderCarriedThing}: Undoing hardcoded carrying penalty: x1.6)"); } } } var capacity = pawn.GetStatValue(StatDefOf.CarryingCapacity, true); var pawnCarriedThing = pawn.carryTracker.CarriedThing; if (pawnCarriedThing != null) { mass += pawnCarriedThing.stackCount * pawnCarriedThing.GetStatValue(StatDefOf.Mass, true); if (pawnCarriedThing.def.category == ThingCategory.Pawn) { // undo carry pawn modifier sb.AppendLine($"Carrying {pawnCarriedThing}: Undoing hardcoded carrying penalty: x1.6)"); } } var encumbrance = Mathf.Max(mass - ignoredMass, 0f) / capacity; var modifier = 1 / (1 + (encumbrance * _carrymodifier)); sb.AppendLine($"Carrying {(int)mass} ({(int)ignoredMass} free) with capacity {(int)capacity} (encumbrance {encumbrance.ToStringByStyle(ToStringStyle.FloatMaxTwo)}) and global factor {_carrymodifier}: x{modifier.ToStringByStyle(ToStringStyle.PercentOne)}"); } return(sb.ToString()); }
public VehicleInfo(List <VehiclePawn> vehicles) { this.vehicles = vehicles; massUsage = vehicles.Sum(v => MassUtility.GearAndInventoryMass(v)); massCapacity = vehicles.Sum(v => v.CargoCapacity); }
//[HarmonyPostfix] public static void TicksPerMove(bool diagonal, Pawn __instance, ref int __result) { if (_carrymodifier == 0f) { return; } if (!MassUtility.CanEverCarryAnything(__instance)) { __result = Mathf.Clamp(Mathf.RoundToInt(__result / _modifier), 1, 450); return; } var c = (float)__result; var pawnMass = __instance.GetStatValue(StatDefOf.Mass); var ignoredMass = pawnMass * (__instance.RaceProps.packAnimal ? 0.5f : 0.2f); if (Compatibility_GiddyUp.GetMount(__instance) is Pawn mount) { __result = diagonal ? mount.TicksPerMoveDiagonal : mount.TicksPerMoveCardinal; return; } // add our own modifiers var mass = ignoredMass - MassUtility.GearAndInventoryMass(__instance); if (Compatibility_GiddyUp.GetRider(__instance) is Pawn rider) { mass += MassUtility.GearAndInventoryMass(rider); mass += rider.GetStatValue(StatDefOf.Mass, true); var riderCarriedThing = rider.carryTracker.CarriedThing; if (riderCarriedThing != null) { mass += riderCarriedThing.stackCount * riderCarriedThing.GetStatValue(StatDefOf.Mass); if (riderCarriedThing is Pawn p) { mass += MassUtility.GearAndInventoryMass(p); // undo carry pawn modifier c /= 1.666f; } } } var capacity = MassUtility.Capacity(__instance, null); var pawnCarriedThing = __instance.carryTracker.CarriedThing; if (pawnCarriedThing != null) { mass += pawnCarriedThing.stackCount * pawnCarriedThing.GetStatValue(StatDefOf.Mass); if (pawnCarriedThing is Pawn p) { mass += MassUtility.GearAndInventoryMass(p); // undo carry pawn modifier c /= 1.666f; } } var encumbrance = Mathf.Clamp(mass / capacity, 0f, 1f); var modifier = 1 + (encumbrance * _carrymodifier); c *= modifier; __result = Mathf.Clamp(Mathf.RoundToInt(c / _modifier), 1, 450); }
public static bool DrawThingRow(Pawn SelPawn, bool CanControl, ref float y, ref float width, Thing thing, bool inventory) { Color hColor = new Color(1f, 0.8f, 0.8f, 1f); bool IsBiocodedOrLinked(Pawn pawn, Thing athing, bool ainventory) { if (pawn.IsQuestLodger()) { if (ainventory) { return(true); } else { CompBiocodable compBiocodable = athing.TryGetComp <CompBiocodable>(); if (compBiocodable != null && compBiocodable.Biocoded) { return(true); } else { CompBladelinkWeapon compBladelinkWeapon = athing.TryGetComp <CompBladelinkWeapon>(); return(compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn == pawn); } } } else { return(false); } } bool IsLocked(Pawn pawn, Thing athing) { Apparel apparel; return((apparel = (athing as Apparel)) != null && pawn.apparel != null && pawn.apparel.IsLocked(apparel)); } if (!Settings.gui_manual_unload) { return(true); } Rect rect = new Rect(0f, y, width, 28f); if (CanControl && (SelPawn.IsColonistPlayerControlled || SelPawn.Spawned && !SelPawn.Map.IsPlayerHome) && (thing is ThingWithComps) && !IsBiocodedOrLinked(SelPawn, thing, inventory) && !IsLocked(SelPawn, thing)) { Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); CompUnloadChecker c = CompUnloadChecker.GetChecker(thing, false, true); if (c.ShouldUnload) { TooltipHandler.TipRegion(rect2, "UnloadThingCancel".Translate()); //weird shenanigans with colors var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing_Cancel"), hColor)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = false; if (MassUtility.Capacity(SelPawn, null) < MassUtility.GearAndInventoryMass(SelPawn) && thing.stackCount * thing.GetStatValue(StatDefOf.Mass, true) > 0 && !thing.def.destroyOnDrop) { Thing t; SelPawn.inventory.innerContainer.TryDrop(thing, SelPawn.Position, SelPawn.Map, ThingPlaceMode.Near, out t, null, null); } } GUI.color = cl; } else { TooltipHandler.TipRegion(rect2, "UnloadThing".Translate()); if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing"))) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = true; } } width -= 24f; } return(true); }