public override string GetExplanation(StatRequest req, ToStringNumberSense numberSense) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(base.GetExplanation(req, numberSense)); if (req.HasThing) { Pawn thisPawn = req.Thing as Pawn; if (thisPawn != null) { if (thisPawn.RaceProps.intelligence >= Intelligence.ToolUser) { CompSlotsBackpack compSlotsBackpack = ToolsForHaulUtility.TryGetBackpack(thisPawn).TryGetComp <CompSlotsBackpack>(); if (compSlotsBackpack != null) { stringBuilder.AppendLine(); stringBuilder.AppendLine("CR_CarriedWeightBackpack".Translate() + ": x" + compSlotsBackpack.MoveSpeedFactor.ToStringPercent()); if (compSlotsBackpack.encumberPenalty > 0f) { stringBuilder.AppendLine("CR_EncumberedBackpack".Translate() + ": -" + compSlotsBackpack.encumberPenalty.ToStringPercent()); stringBuilder.AppendLine("CR_FinalModifierBackpack".Translate() + ": x" + this.GetStatFactor(thisPawn).ToStringPercent()); } } } } } return(stringBuilder.ToString()); }
private float GetStatFactor(Pawn thisPawn) { float result = 1f; if (MapComponent_ToolsForHaul.currentVehicle.ContainsKey(thisPawn)) { Vehicle_Cart vehicleCart = MapComponent_ToolsForHaul.currentVehicle[thisPawn] as Vehicle_Cart; if (vehicleCart != null) { if (vehicleCart.mountableComp.IsMounted && !vehicleCart.mountableComp.Driver.RaceProps.Animal && vehicleCart.mountableComp.Driver == thisPawn) { if (vehicleCart.IsCurrentlyMotorized()) { result = Mathf.Clamp(vehicleCart.VehicleSpeed, 2f, 100f); } else { result = Mathf.Clamp(vehicleCart.VehicleSpeed, 0.5f, 1f); } return(result); } } Vehicle_Turret vehicleTank = MapComponent_ToolsForHaul.currentVehicle[thisPawn] as Vehicle_Turret; if (vehicleTank != null) { if (vehicleTank.mountableComp.IsMounted && !vehicleTank.mountableComp.Driver.RaceProps.Animal && vehicleTank.mountableComp.Driver == thisPawn) { if (vehicleTank.IsCurrentlyMotorized()) { result = Mathf.Clamp(vehicleTank.VehicleSpeed, 2f, 100f); } else { result = Mathf.Clamp(vehicleTank.VehicleSpeed, 0.5f, 1f); } return(result); } } } Apparel_Backpack apparelBackpack = ToolsForHaulUtility.TryGetBackpack(thisPawn); CompSlotsBackpack compSlotsBackpack = apparelBackpack?.slotsComp; if (compSlotsBackpack != null) { result = Mathf.Clamp(compSlotsBackpack.moveSpeedFactor - compSlotsBackpack.encumberPenalty, 0.1f, 1f); } CompInventory compInventory = thisPawn.TryGetComp <CompInventory>(); if (compInventory != null) { result = Mathf.Clamp(compInventory.moveSpeedFactor - compInventory.encumberPenalty, 0.1f, 1f); return(result); } return(result); }
private float GetStatFactor(Pawn thisPawn) { float result = 1f; Apparel_Backpack apparelBackpack = ToolsForHaulUtility.TryGetBackpack(thisPawn); CompSlotsBackpack compSlotsBackpack = apparelBackpack?.SlotsComp; if (compSlotsBackpack != null) { result = Mathf.Clamp(compSlotsBackpack.MoveSpeedFactor - compSlotsBackpack.encumberPenalty, 0.5f, 1f); } #if CR CompInventory compInventory = thisPawn.TryGetComp <CompInventory>(); if (compInventory != null) { result = Mathf.Clamp(compInventory.moveSpeedFactor - compInventory.encumberPenalty, 0.1f, 1f); return(result); } #endif return(result); }
public void DrawSlots(Pawn wearer, CompSlotsBackpack SlotsBackpackComp, Rect inventoryRect) { // draw text message if no contents inside if (SlotsBackpackComp.slots.Count == 0) { Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(inventoryRect, "No Items"); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Tiny; } // draw slots else { Rect slotRect = new Rect( inventoryRect.x, inventoryRect.y, this.Width / this.iconsPerRow - 1f, Height / 2 - 1f); for (int currentSlotInd = 0; currentSlotInd < this.iconsPerRow * numOfRow; currentSlotInd++) { if (currentSlotInd >= this.backpack.MaxItem) { slotRect.x = inventoryRect.x + inventoryRect.width / this.iconsPerRow * (currentSlotInd % this.iconsPerRow); slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / this.iconsPerRow); Widgets.DrawTextureFitted(slotRect, NoAvailableTex, 1.0f); } if (currentSlotInd >= SlotsBackpackComp.slots.Count) { slotRect.x = inventoryRect.x + inventoryRect.width / this.iconsPerRow * (currentSlotInd % this.iconsPerRow); slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / this.iconsPerRow); Widgets.DrawTextureFitted(slotRect, EmptyTex, 1.0f); } // draw occupied slots if (currentSlotInd < SlotsBackpackComp.slots.Count) { slotRect.x = inventoryRect.x + inventoryRect.width / this.iconsPerRow * (currentSlotInd % this.iconsPerRow); slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / this.iconsPerRow); Thing currentThing = SlotsBackpackComp.slots[currentSlotInd]; // draws greyish slot background Widgets.DrawTextureFitted(slotRect.ContractedBy(3f), texOccupiedSlotBG, 1f); if (currentThing.def.IsMeleeWeapon) { Widgets.DrawTextureFitted(slotRect, MeleeWeaponTex, 1.0f); } if (currentThing.def.IsRangedWeapon) { Widgets.DrawTextureFitted(slotRect, RangedWeaponTex, 1.0f); } Widgets.DrawBox(slotRect); // highlights slot if mouse over Widgets.DrawHighlightIfMouseover(slotRect.ContractedBy(3f)); // tooltip if mouse over TooltipHandler.TipRegion(slotRect, currentThing.def.LabelCap); // draw thing texture Widgets.ThingIcon(slotRect, currentThing); // interaction with slots if (Widgets.ButtonInvisible(slotRect)) { // mouse button pressed if (Event.current.button == 0) { // Weapon if (currentThing != null && currentThing.def.equipmentType == EquipmentType.Primary && (currentThing.def.IsRangedWeapon || currentThing.def.IsMeleeWeapon)) { SlotsBackpackComp.SwapEquipment(currentThing as ThingWithComps); } //// equip weapon in slot // if (currentThing.def.equipmentType == EquipmentType.Primary) // { // slotsComp.SwapEquipment(currentThing as ThingWithComps); // } } // mouse button released else if (Event.current.button == 1) { List <FloatMenuOption> options = new List <FloatMenuOption> { new FloatMenuOption( "Info", () => { Find.WindowStack.Add( new Dialog_InfoCard(currentThing)); }), new FloatMenuOption( "Drop", () => { Thing resultThing; SlotsBackpackComp.slots.TryDrop( currentThing, wearer.Position, wearer.Map, ThingPlaceMode.Near, out resultThing); }) }; // get thing info card // drop thing // Else // Weapon if (currentThing != null && currentThing.def.equipmentType == EquipmentType.Primary) { options.Add( new FloatMenuOption( "Equip".Translate(currentThing.LabelCap), () => { SlotsBackpackComp.SwapEquipment(currentThing as ThingWithComps); })); } // Food if ( currentThing.def.thingCategories.Contains( DefDatabase <ThingCategoryDef> .GetNamed("FoodMeals"))) { // if (compSlots.owner.needs.food.CurCategory != HungerCategory.Fed) options.Add( new FloatMenuOption( "ConsumeThing".Translate(currentThing.LabelCap), () => { Thing dummy; SlotsBackpackComp.slots.TryDrop( currentThing, wearer.Position, wearer.Map, ThingPlaceMode.Direct, currentThing.def.ingestible.maxNumToIngestAtOnce, out dummy); Job jobNew = new Job(JobDefOf.Ingest, dummy); jobNew.count = currentThing.def.ingestible.maxNumToIngestAtOnce; jobNew.ignoreForbidden = true; wearer.jobs.TryTakeOrderedJob(jobNew); })); } // Drugs if (currentThing.def.ingestible?.drugCategory >= DrugCategory.Any) { options.Add( new FloatMenuOption( "ConsumeThing".Translate(currentThing.LabelCap), () => { Thing dummy; SlotsBackpackComp.slots.TryDrop( currentThing, wearer.Position, wearer.Map, ThingPlaceMode.Direct, currentThing.def.ingestible.maxNumToIngestAtOnce, out dummy); Job jobNew = new Job(JobDefOf.Ingest, dummy) { count = dummy.def.ingestible .maxNumToIngestAtOnce, ignoreForbidden = true }; wearer.jobs.TryTakeOrderedJob(jobNew); })); } Find.WindowStack.Add(new FloatMenu(options, currentThing.LabelCap)); } // plays click sound on each click SoundDefOf.Click.PlayOneShotOnCamera(); } } slotRect.x = inventoryRect.x + Height / 2 * (currentSlotInd % this.iconsPerRow); slotRect.y = inventoryRect.y + Height / 2 * (currentSlotInd / this.iconsPerRow); // slotRect.x += Height; } } }
public override string GetExplanation(StatRequest req, ToStringNumberSense numberSense) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(base.GetExplanation(req, numberSense)); if (req.HasThing) { Pawn thisPawn = req.Thing as Pawn; if (thisPawn != null) { if (thisPawn.RaceProps.intelligence >= Intelligence.ToolUser) { if (MapComponent_ToolsForHaul.currentVehicle.ContainsKey(thisPawn)) { Vehicle_Cart vehicle_Cart = MapComponent_ToolsForHaul.currentVehicle[thisPawn] as Vehicle_Cart; if (vehicle_Cart != null) { if (vehicle_Cart.mountableComp.IsMounted && vehicle_Cart.mountableComp.Driver == thisPawn) { stringBuilder.AppendLine(); stringBuilder.AppendLine("VehicleSpeed".Translate() + ": x" + vehicle_Cart.VehicleSpeed); return(stringBuilder.ToString()); } } Vehicle_Turret vehicle_Turret = MapComponent_ToolsForHaul.currentVehicle[req.Thing as Pawn] as Vehicle_Turret; if (vehicle_Turret != null) { if (vehicle_Turret.mountableComp.IsMounted && vehicle_Turret.mountableComp.Driver == thisPawn) { stringBuilder.AppendLine(); stringBuilder.AppendLine("VehicleSpeed".Translate() + ": x" + vehicle_Turret.VehicleSpeed); return(stringBuilder.ToString()); } } } CompInventory compInventory = ThingCompUtility.TryGetComp <CompInventory>(req.Thing); if (compInventory != null) { stringBuilder.AppendLine(); stringBuilder.AppendLine(Translator.Translate("CR_CarriedWeight") + ": x" + GenText.ToStringPercent(compInventory.moveSpeedFactor)); if (compInventory.encumberPenalty > 0f) { stringBuilder.AppendLine(Translator.Translate("CR_Encumbered") + ": -" + GenText.ToStringPercent(compInventory.encumberPenalty)); stringBuilder.AppendLine(Translator.Translate("CR_FinalModifier") + ": x" + GenText.ToStringPercent(this.GetStatFactor(thisPawn))); } } CompSlotsBackpack compSlotsBackpack = ToolsForHaulUtility.TryGetBackpack(thisPawn).TryGetComp <CompSlotsBackpack>(); if (compSlotsBackpack != null) { stringBuilder.AppendLine(); stringBuilder.AppendLine("CR_CarriedWeightBackpack".Translate() + ": x" + compSlotsBackpack.moveSpeedFactor.ToStringPercent()); if (compSlotsBackpack.encumberPenalty > 0f) { stringBuilder.AppendLine("CR_EncumberedBackpack".Translate() + ": -" + compSlotsBackpack.encumberPenalty.ToStringPercent()); stringBuilder.AppendLine("CR_FinalModifierBackpack".Translate() + ": x" + GetStatFactor(thisPawn).ToStringPercent()); } } } } } return(stringBuilder.ToString()); }