/* * Stop working on Site */ public static Command StopWorkingOnSite(Caravan caravan) { var command_Action = new Command_Action { defaultLabel = "RoadsOfTheRimStopWorkingOnSite".Translate(), defaultDesc = "RoadsOfTheRimStopWorkingOnSiteDescription".Translate(), icon = ContentFinder <Texture2D> .Get("UI/Commands/RemoveConstructionSite"), action = delegate { SoundDefOf.CancelMode.PlayOneShotOnCamera(); caravan.GetComponent <WorldObjectComp_Caravan>().StopWorking(); } }; return(command_Action); }
/* * Purpose: Remove object from caravan. * Effects: Part's parent is now attach_point of the capsule (capsule is now grandparent!) * Input/Output: N/A. * Global Variables Used: caravan_tf, parts_tf, caravan, char_control (Class Caravan), transform (Class Part), * has_object (Class CharacterControl) */ public void RemoveFromCaravan() { if (caravan.FindPartSlot()) { Part part = PartToBeRemoved(); part.Drop(); caravan.parts_tf.Remove(part.transform); if (!health) { health = caravan.GetComponent <Health>(); } health.Reduce(part.healthValue); } else { Debug.Log("No part attached to caravan"); } }
public static void Postfix(ref IEnumerable <Gizmo> __result, Caravan __instance) { bool isThereAConstructionSiteHere = Find.WorldObjects.AnyWorldObjectOfDefAt(DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionSite", true), __instance.Tile); bool isTheCaravanWorkingOnASite = true; try { isTheCaravanWorkingOnASite = __instance.GetComponent <WorldObjectComp_Caravan>().currentlyWorkingOnSite; } catch (Exception e) { RoadsOfTheRim.DebugLog(null, e); } __result = __result.Concat(new Gizmo[] { RoadsOfTheRim.AddConstructionSite(__instance) }) .Concat(new Gizmo[] { RoadsOfTheRim.RemoveConstructionSite(__instance.Tile) }); if (isThereAConstructionSiteHere & !isTheCaravanWorkingOnASite && RoadsOfTheRim.RoadBuildingState.CurrentlyTargeting == null) { __result = __result.Concat(new Gizmo[] { RoadsOfTheRim.WorkOnSite(__instance) }); } if (isTheCaravanWorkingOnASite) { __result = __result.Concat(new Gizmo[] { RoadsOfTheRim.StopWorkingOnSite(__instance) }); } }
public void DoOutcome(Caravan caravan) { this.workStarted = false; caravan.GetComponent <WorldObjectComp_CaravanComp>().caravanIsWorking = false; this.Outcome_Triumph(caravan: caravan); }
/* * Purpose: Interact with caravan (Add and Remove Parts). * Effects: Effects from AddToCaravan() and RemoveFromCaravan(). * Input/Output: Keyboard input "E" to add & "R" to remove. Output N/A. * Global Variables Used: caravan_tf, part_slot_tf, caravan, char_control (Class InteractWithCaravan), * transform, parts_tf (Class Caravan), transform (Class Part), has_object (Class CharacterControl). */ void OnTriggerStay(Collider c) { if (c.gameObject.tag == "Caravan") { canInteract = true; caravan_tf = c.gameObject.transform; caravan = caravan_tf.GetComponentInParent <Caravan>(); health = caravan.GetComponent <Health>(); if (Input.GetButtonDown(interact_botton_str) && gameObject.tag == "Player" && p_inv.CaravanPart != 0) { if (char_control.has_part) { AddToCaravan(); } } else if (Input.GetKeyDown(KeyCode.R)) { if (gameObject.name == "Player_2") //if (!char_control.has_part) { RemoveFromCaravan(); } } /* * Purpose: Temporary shop code * Effects: Allows Player to buy equipment and bandages from the shop * Input/Output: Keyboard input "T" to deposit wood, "Y" to buy a trap, "U" to buy bandages * Global Variables Used: Player_Inventory.wood, Caravan_Inventory.wood, Player_Inventory.GP, Player_Inventory.Trap1 & Trap2, * Player_Inventory.Bandage, Caravan_Inventory.bandages */ else if (Input.GetButtonDown(char_control.interact_botton_str) && p_inv.wood > 0) { if (p_inv.wood > 0) { c_inv.wood += p_inv.wood; p_inv.Score += 3 * p_inv.wood; p_inv.wood = 0; } } else if (Input.GetKeyDown(KeyCode.Alpha2)) { if (p_inv.GP > 4 && c_inv.traps > 0) { if (p_inv.Trap1 < 1) { p_inv.GP = p_inv.GP - 5; p_inv.Trap1 = 1; } else if (p_inv.Trap1 > 0 && p_inv.Trap2 < 1) { p_inv.GP = p_inv.GP - 5; p_inv.Trap2 = 1; } else if (p_inv.Trap1 > 0 && p_inv.Trap2 > 0) { Debug.Log("I'm sorry friend, but you're carrying too much right now"); } } else if (p_inv.GP < 5) { Debug.Log("I'm sorry friend, but it looks like you're a little light on coin"); } else if (c_inv.traps < 1) { Debug.Log("I'm sorry friend, but it looks like I'm fresh out of stock"); } } else if (Input.GetKeyDown(KeyCode.Alpha3)) { if (p_inv.GP > 0 && c_inv.bandages > 0) { p_inv.GP -= 1; p_inv.Bandage += 1; c_inv.bandages -= 1; } } } }
/* * Based on the Caravan's resources, Pawns & the road's cost (modified by terrain) : * - Determine the amount of work done in a tick * - Consume the caravan's resources * - Return whether or not the Caravan must now stop because it ran out of resources * - NOTE : Does this need to be here ? Maybe better in Mod.cs * Returns TRUE if work finished * CALLED FROM : CompTick() of WorldObjectComp_Caravan */ public static bool DoSomeWork(Caravan caravan, RoadConstructionSite site, out bool noMoreResources) { var caravanComp = caravan.GetComponent <WorldObjectComp_Caravan>(); var siteComp = site.GetComponent <WorldObjectComp_ConstructionSite>(); _ = site.roadDef.GetModExtension <DefModExtension_RotR_RoadDef>(); noMoreResources = false; var useISR2G = caravanComp.UseISR2G(); var available = new Dictionary <string, int>(); var needed = new Dictionary <string, int>(); var ratio = new Dictionary <string, float>(); float ratio_final = 1; //RoadsOfTheRim.DebugLog("[RotR] DEBUG ========== doSomeWork() =========="); //RoadsOfTheRim.DebugLog("[RotR] DEBUG ISR2G set to "+useISR2G); if (DebugSettings.godMode) { return(siteComp.FinishWork(caravan)); } if (caravanComp.CaravanCurrentState() != CaravanState.ReadyToWork) { DebugLog("[RotR] DEBUG : doSomeWork() failed because the caravan can't work."); return(false); } // Percentage of total work that can be done in this batch, might be 0 if no pawn was found with enough skill var amountOfWork = caravanComp.AmountOfWork(true); // Work was 0 (not enough skill) if (Math.Abs(amountOfWork) < double.Epsilon) { Messages.Message("RoadsOfTheRim_CaravanNoWork".Translate(caravan.Name, site.roadDef.label), MessageTypeDefOf.RejectInput); caravanComp.StopWorking(); return(false); } // calculate material present in the caravan foreach (var resourceName in DefModExtension_RotR_RoadDef.allResources) { available[resourceName] = 0; } foreach (var aThing in CaravanInventoryUtility.AllInventoryItems(caravan)) { foreach (var resourceName in DefModExtension_RotR_RoadDef.allResources) { if (IsThis(aThing.def, resourceName)) { available[resourceName] += aThing.stackCount; } } } // What percentage of work will remain after amountOfWork is done ? var percentOfWorkLeftToDoAfter = (siteComp.GetLeft("Work") - amountOfWork) / siteComp.GetCost("Work"); // The amount of each resource left to spend in total is : percentOfWorkLeftToDoAfter * {this resource cost} // Materials that would be needed to do that much work foreach (var resourceName in DefModExtension_RotR_RoadDef.allResources) { needed[resourceName] = (int)Math.Round(siteComp.GetLeft(resourceName) - (percentOfWorkLeftToDoAfter * siteComp.GetCost(resourceName))); // Check if there's enough material to go through this batch. Materials with a cost of 0 are always OK // Don't check when ISR2G is in use for this resource, don't check for work if (DefModExtension_RotR_RoadDef.GetInSituModifier(resourceName, useISR2G) || resourceName == "Work") { continue; } ratio[resourceName] = needed[resourceName] == 0 ? 1f : Math.Min(available[resourceName] / (float)needed[resourceName], 1f); if (ratio[resourceName] < ratio_final) { ratio_final = ratio[resourceName]; } } // The caravan didn't have enough resources for a full batch of work. Use as much as we can then stop working if (ratio_final < 1f) { Messages.Message("RoadsOfTheRim_CaravanNoResource".Translate(caravan.Name, site.roadDef.label), MessageTypeDefOf.RejectInput); foreach (var resourceName in DefModExtension_RotR_RoadDef.allResources) { needed[resourceName] = (int)(needed[resourceName] * ratio_final); } caravanComp.StopWorking(); } //RoadsOfTheRim.DebugLog("[RotR] ISR2G DEBUG ratio final = " + ratio_final); // Consume resources from the caravan _ = site.roadDef.defName == "DirtPathBuilt"; // Always consider resources have been consumed when the road is a dirt path foreach (var aThing in CaravanInventoryUtility.AllInventoryItems(caravan)) { foreach (var resourceName in DefModExtension_RotR_RoadDef.allResources) { if (!DefModExtension_RotR_RoadDef.GetInSituModifier(resourceName, useISR2G)) { if (needed[resourceName] <= 0 || !IsThis(aThing.def, resourceName)) { continue; //RoadsOfTheRim.DebugLog("[RotR] ISR2G consumption DEBUG =" + resourceName + " Qty consumed = " + amountUsed); } var amountUsed = aThing.stackCount > needed[resourceName] ? needed[resourceName] : aThing.stackCount; aThing.stackCount -= amountUsed; // Reduce how much of this resource is needed needed[resourceName] -= amountUsed; siteComp.ReduceLeft(resourceName, amountUsed); } else { if (needed[resourceName] <= 0) { continue; } //RoadsOfTheRim.DebugLog("[RotR] ISR2G consumption DEBUG =" + resourceName + " Qty freely awarded = " + needed[resourceName]); siteComp.ReduceLeft(resourceName, needed[resourceName]); needed[resourceName] = 0; } } if (aThing.stackCount == 0) { aThing.Destroy(); } } caravanComp.TeachPawns(ratio_final); // Pawns learn some construction // HARDCODED : ISR2G divides work done by 4 , AISR2G by 2 for all roads except dirt path if (useISR2G > 0 && site.roadDef.defName != "DirtPathBuilt") { amountOfWork = amountOfWork * 0.25f * useISR2G; } // Update amountOfWork based on the actual ratio worked & finally reducing the work & resources left amountOfWork = ratio_final * amountOfWork; return(siteComp.UpdateProgress(amountOfWork, caravan)); }