public void SpawnStartingResources(Map map) { foreach (var e in PrepareCarefully.Instance.Equipment) { EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[e.EquipmentKey]; if (entry == null) { string thing = e.def != null ? e.def.defName : "null"; string stuff = e.stuffDef != null ? e.stuffDef.defName : "null"; Log.Warning(string.Format("Unrecognized resource/equipment. This may be caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); continue; } // TODO: Look into what the clusterSize and minSpacing parameters do. If we are spawning an // exceptionally large number of a given resource, would the numbers for those parameters // need to be increased to allow the scatterer to find a place on the map? if (!entry.gear && !entry.animal) { new GenStep_ScatterThings { nearPlayerStart = true, thingDef = e.def, stuff = e.stuffDef, clusterSize = 4, count = e.Count, spotMustBeStandable = true, minSpacing = 5f }.Generate(map); } } }
public SelectedEquipment(EquipmentDatabaseEntry entry) { count = 1; def = entry.def; stuffDef = entry.stuffDef; gender = entry.gender; }
public SelectedEquipment(EquipmentDatabaseEntry entry, int count) { this.count = count; def = entry.def; stuffDef = entry.stuffDef; gender = entry.gender; }
private Thing CreateAnimal(EquipmentDatabaseEntry entry) { ThingDef def = entry.def; PawnKindDef kindDef = (from td in DefDatabase <PawnKindDef> .AllDefs where td.race == def select td).FirstOrDefault(); if (kindDef != null) { Pawn pawn = PawnGenerator.GeneratePawn(kindDef, Faction.OfPlayer); pawn.gender = entry.gender; if (pawn.Name == null || pawn.Name.Numerical) { pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, null); } if (kindDef.RaceProps.petness > 0) { Pawn bondedColonist = Find.GameInitData.startingPawns.RandomElement <Pawn>(); bondedColonist.relations.AddDirectRelation(PawnRelationDefOf.Bond, pawn); } return(pawn); } else { return(null); } }
private static EquipmentDatabaseEntry RandomPet(ScenPart_StartingAnimal startingAnimal) { FieldInfo animalKindField = typeof(ScenPart_StartingAnimal).GetField("animalKind", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo randomPetsMethod = typeof(ScenPart_StartingAnimal).GetMethod("RandomPets", BindingFlags.Instance | BindingFlags.NonPublic); PawnKindDef animalKindDef = (PawnKindDef)animalKindField.GetValue(startingAnimal); if (animalKindDef == null) { IEnumerable <PawnKindDef> animalKindDefs = (IEnumerable <PawnKindDef>)randomPetsMethod.Invoke(startingAnimal, null); animalKindDef = animalKindDefs.RandomElementByWeight((PawnKindDef td) => td.RaceProps.petness); } List <EquipmentDatabaseEntry> entries = PrepareCarefully.Instance.EquipmentEntries.Animals.FindAll((EquipmentDatabaseEntry e) => { return(e.def == animalKindDef.race); }); if (entries.Count > 0) { EquipmentDatabaseEntry entry = entries.RandomElement(); return(entry); } else { return(null); } }
public void RemoveEquipment(EquipmentDatabaseEntry entry) { SelectedEquipment e = Find(entry); if (e != null) { removals.Add(e); } }
protected void AddThingDef(ThingDef def, int type) { if (def.MadeFromStuff) { foreach (var s in stuff) { if (s.stuffProps.CanMake(def)) { EquipmentKey key = new EquipmentKey(def, s); EquipmentDatabaseEntry entry = CreateEquipmentEntry(def, s, type); if (entry != null) { entries[key] = entry; } } } } else if (def.race != null && def.race.Animal) { if (def.race.hasGenders) { EquipmentDatabaseEntry femaleEntry = CreateEquipmentEntry(def, Gender.Female, type); if (femaleEntry != null) { entries[new EquipmentKey(def, Gender.Female)] = femaleEntry; } EquipmentDatabaseEntry maleEntry = CreateEquipmentEntry(def, Gender.Male, type); if (maleEntry != null) { entries[new EquipmentKey(def, Gender.Male)] = maleEntry; } } else { EquipmentKey key = new EquipmentKey(def, Gender.None); EquipmentDatabaseEntry entry = CreateEquipmentEntry(def, Gender.None, type); if (entry != null) { entries[key] = entry; } } } else { EquipmentKey key = new EquipmentKey(def, null); EquipmentDatabaseEntry entry = CreateEquipmentEntry(def, null, Gender.None, type); if (entry != null) { entries[key] = entry; } } }
public double CalculateEquipmentCost(SelectedEquipment customPawn) { EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]; if (entry != null) { return((double)customPawn.count * entry.cost); } else { return(0); } }
public bool AddEquipment(EquipmentDatabaseEntry entry, int count) { SelectedEquipment e = Find(entry); if (e == null) { equipment.Add(new SelectedEquipment(entry, count)); return(true); } else { e.count += count; return(false); } }
public bool AddEquipment(EquipmentDatabaseEntry entry) { SelectedEquipment e = Find(entry); if (e == null) { equipment.Add(new SelectedEquipment(entry)); return(true); } else { e.count += entry.stackSize; return(false); } }
public EquipmentDatabaseEntry AddThingDefWithStuff(ThingDef def, ThingDef stuff, int type) { if (type == -1) { Log.Warning("Prepare Carefully could not add unclassified equipment: " + def); return(null); } EquipmentKey key = new EquipmentKey(def, stuff); EquipmentDatabaseEntry entry = CreateEquipmentEntry(def, stuff, type); if (entry != null) { entries[key] = entry; } return(entry); }
protected void ScrollTo(EquipmentDatabaseEntry entry) { int index = PrepareCarefully.Instance.Equipment.FindIndex((SelectedEquipment e) => { return(e.def == entry.def && e.stuffDef == entry.stuffDef); }); if (index != -1) { destSelection = index; float pos = (float)index * RectDestEntry.height; if (pos < destScrollPosition.y) { newDestScrollPosition = pos; } else if (pos > destScrollPosition.y + RectDestContent.height - RectDestEntry.height) { newDestScrollPosition = pos + RectDestEntry.height - RectDestContent.height; } } }
protected void InitializeDefaultEquipment() { // Go through all of the scenario steps that scatter resources near the player starting location and add // them to the resource/equipment list. foreach (ScenPart part in Verse.Find.Scenario.AllParts) { ScenPart_ScatterThingsNearPlayerStart nearPlayerStart = part as ScenPart_ScatterThingsNearPlayerStart; if (nearPlayerStart != null) { FieldInfo thingDefField = typeof(ScenPart_ScatterThingsNearPlayerStart).GetField("thingDef", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo stuffDefField = typeof(ScenPart_ScatterThingsNearPlayerStart).GetField("stuff", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo countField = typeof(ScenPart_ScatterThingsNearPlayerStart).GetField("count", BindingFlags.Instance | BindingFlags.NonPublic); ThingDef thingDef = (ThingDef)thingDefField.GetValue(nearPlayerStart); ThingDef stuffDef = (ThingDef)stuffDefField.GetValue(nearPlayerStart); int count = (int)countField.GetValue(nearPlayerStart); EquipmentKey key = new EquipmentKey(thingDef, stuffDef); EquipmentDatabaseEntry entry = equipmentDatabase[key]; if (entry == null) { entry = AddNonStandardScenarioEquipmentEntry(key); } if (entry != null) { AddEquipment(entry, count); } } // Go through all of the scenario steps that place starting equipment with the colonists and // add them to the resource/equipment list. ScenPart_StartingThing_Defined startingThing = part as ScenPart_StartingThing_Defined; if (startingThing != null) { FieldInfo thingDefField = typeof(ScenPart_StartingThing_Defined).GetField("thingDef", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo stuffDefField = typeof(ScenPart_StartingThing_Defined).GetField("stuff", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo countField = typeof(ScenPart_StartingThing_Defined).GetField("count", BindingFlags.Instance | BindingFlags.NonPublic); ThingDef thingDef = (ThingDef)thingDefField.GetValue(startingThing); ThingDef stuffDef = (ThingDef)stuffDefField.GetValue(startingThing); int count = (int)countField.GetValue(startingThing); EquipmentKey key = new EquipmentKey(thingDef, stuffDef); EquipmentDatabaseEntry entry = equipmentDatabase[key]; if (entry == null) { entry = AddNonStandardScenarioEquipmentEntry(key); } if (entry != null) { AddEquipment(entry, count); } } // Go through all of the scenario steps that spawn a pet and add the pet to the equipment/resource // list. ScenPart_StartingAnimal animal = part as ScenPart_StartingAnimal; if (animal != null) { FieldInfo animalCountField = typeof(ScenPart_StartingAnimal).GetField("count", BindingFlags.Instance | BindingFlags.NonPublic); int count = (int)animalCountField.GetValue(animal); for (int i = 0; i < count; i++) { AddEquipment(RandomPet(animal)); } } } }
public bool Load(PrepareCarefully loadout, string presetName) { List <SaveRecordPawnV3> pawns = new List <SaveRecordPawnV3>(); List <SaveRecordRelationshipV3> savedRelationships = new List <SaveRecordRelationshipV3>(); Failed = false; int startingPoints = 0; bool usePoints = false; try { Scribe.InitLoading(PresetFiles.FilePathForSavedPreset(presetName)); Scribe_Values.LookValue <bool>(ref usePoints, "usePoints", true, false); Scribe_Values.LookValue <int>(ref startingPoints, "startingPoints", 0, false); Scribe_Values.LookValue <string>(ref ModString, "mods", "", false); try { Scribe_Collections.LookList <SaveRecordPawnV3>(ref pawns, "colonists", LookMode.Deep, null); } catch (Exception e) { Messages.Message(ModString, MessageSound.Silent); Messages.Message("EdB.PresetPawnLoadFailed".Translate(), MessageSound.SeriousAlert); Log.Warning(e.ToString()); Log.Warning("Preset was created with the following mods: " + ModString); return(false); } try { Scribe_Collections.LookList <SaveRecordRelationshipV3>(ref savedRelationships, "relationships", LookMode.Deep, null); } catch (Exception e) { Messages.Message(ModString, MessageSound.Silent); Messages.Message("EdB.PresetPawnLoadFailed".Translate(), MessageSound.SeriousAlert); Log.Warning(e.ToString()); Log.Warning("Preset was created with the following mods: " + ModString); return(false); } List <LoadableEquipment> tempEquipment = new List <LoadableEquipment>(); Scribe_Collections.LookList <LoadableEquipment>(ref tempEquipment, "equipment", LookMode.Deep, null); List <SelectedEquipment> equipment = new List <SelectedEquipment>(tempEquipment.Count); foreach (var e in tempEquipment) { ThingDef thingDef = DefDatabase <ThingDef> .GetNamedSilentFail(e.def); ThingDef stuffDef = null; Gender gender = Gender.None; if (!string.IsNullOrEmpty(e.stuffDef)) { stuffDef = DefDatabase <ThingDef> .GetNamedSilentFail(e.stuffDef); } if (!string.IsNullOrEmpty(e.gender)) { try { gender = (Gender)Enum.Parse(typeof(Gender), e.gender); } catch (Exception) { Log.Warning("Failed to load gender value for animal."); Failed = true; continue; } } if (thingDef != null) { if (string.IsNullOrEmpty(e.stuffDef)) { equipment.Add(new SelectedEquipment(thingDef, null, gender, e.count)); } else { if (stuffDef != null) { EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[new EquipmentKey(thingDef, stuffDef, gender)]; if (entry == null) { string thing = thingDef != null ? thingDef.defName : "null"; string stuff = stuffDef != null ? stuffDef.defName : "null"; Log.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); Failed = true; continue; } else { equipment.Add(new SelectedEquipment(thingDef, stuffDef, gender, e.count)); } } else { Log.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); Failed = true; } } } else { Log.Warning("Could not load thing definition \"" + e.def + "\""); Failed = true; } } loadout.Equipment.Clear(); foreach (var e in equipment) { loadout.Equipment.Add(e); } // After loading items using the Scribe methods, the saveables that were loaded get // put into this saveablesToPostLoad map. This post-load initialization is only // applicable for when we load a save game. We need to clear our saveables out of // there so that they don't cause errors later. HashSet <IExposable> saveables = (HashSet <IExposable>)(typeof(PostLoadInitter).GetField("saveablesToPostLoad", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null)); saveables.Clear(); //PrepareCarefully.Instance.Config.pointsEnabled = usePoints; } catch (Exception e) { Log.Error("Failed to load preset file"); throw e; } finally { Scribe.mode = LoadSaveMode.Inactive; } List <CustomPawn> pawnModels = new List <CustomPawn>(); try { foreach (SaveRecordPawnV3 p in pawns) { pawnModels.Add(LoadPawn(p)); } } catch (Exception e) { Messages.Message(ModString, MessageSound.Silent); Messages.Message("EdB.PresetPawnLoadFailed".Translate(), MessageSound.SeriousAlert); Log.Warning(e.ToString()); Log.Warning("Preset was created with the following mods: " + ModString); return(false); } List <CustomRelationship> relationships = new List <CustomRelationship>(); try { foreach (SaveRecordRelationshipV3 r in savedRelationships) { CustomRelationship relationship = LoadRelationship(r, pawnModels); if (relationship == null) { Messages.Message(ModString, MessageSound.Silent); Messages.Message("EdB.PresetRelationshipLoadFailed".Translate(), MessageSound.SeriousAlert); Log.Warning("Failed to load relationship: " + r.relation); Log.Warning("Preset was created with the following mods: " + ModString); } else { relationships.Add(relationship); } } } catch (Exception e) { Messages.Message(ModString, MessageSound.Silent); Messages.Message("EdB.PresetRelationshipLoadFailed".Translate(), MessageSound.SeriousAlert); Log.Warning(e.ToString()); Log.Warning("Preset was created with the following mods: " + ModString); return(false); } loadout.ClearPawns(); foreach (CustomPawn p in pawnModels) { loadout.AddPawn(p); } loadout.RelationshipManager.Clear(); foreach (CustomRelationship r in relationships) { loadout.RelationshipManager.AddRelationship(r.def, r.source, r.target); } if (Failed) { Messages.Message(ModString, MessageSound.Silent); Messages.Message("EdB.PresetThingDefFailed".Translate(), MessageSound.SeriousAlert); Log.Warning("Preset was created with the following mods: " + ModString); return(false); } return(true); }
public void CalculatePawnCost(ColonistCostDetails cost, CustomPawn pawn) { cost.Clear(); cost.name = pawn.NickName; // Start with the market value plus a bit of a mark-up. cost.marketValue = pawn.Pawn.MarketValue; cost.marketValue += 300; // Reduce cost if random injuries have been chosen. if (pawn.RandomInjuries) { float ageMultiplier = pawn.BiologicalAge; if (ageMultiplier > 100) { ageMultiplier = 100; } float injuryValue = Mathf.Pow(ageMultiplier, 1.177455f); injuryValue = injuryValue / 10f; injuryValue = Mathf.Floor(injuryValue) * 10f; cost.marketValue -= injuryValue; } // Calculate passion cost. Each passion above 8 makes all passions // cost more. Minor passion counts as one passion. Major passion // counts as 3. double skillCount = pawn.currentPassions.Keys.Count(); double passionLevelCount = 0; double passionLevelCost = 20; double passionateSkillCount = 0; foreach (SkillDef def in pawn.currentPassions.Keys) { Passion passion = pawn.currentPassions[def]; int level = pawn.GetSkillLevel(def); if (passion == Passion.Major) { passionLevelCount += 3.0; passionateSkillCount += 1.0; } else if (passion == Passion.Minor) { passionLevelCount += 1.0; passionateSkillCount += 1.0; } } double levelCost = passionLevelCost; if (passionLevelCount > 8) { double penalty = passionLevelCount - 8; levelCost += penalty * 0.4; } cost.marketValue += levelCost * passionLevelCount; // Calculat cost of worn apparel. for (int layer = 0; layer < PawnLayers.Count; layer++) { if (PawnLayers.IsApparelLayer(layer)) { var def = pawn.GetAcceptedApparel(layer); SelectedEquipment customPawn = new SelectedEquipment(); customPawn.def = def; customPawn.count = 1; if (def != null) { var stuff = pawn.GetSelectedStuff(layer); customPawn.stuffDef = stuff; } double c = CalculateEquipmentCost(customPawn); if (def != null) { if (customPawn.stuffDef != null) { if (customPawn.stuffDef.defName == "Synthread") { if (freeApparel.Contains(customPawn.def.defName)) { c = 0; } else if (cheapApparel.Contains(customPawn.def.defName)) { c = c * 0.15d; } } } } cost.apparel += c; } } // Calculate cost for any materials needed for implants. foreach (Implant option in pawn.Implants) { // Check if there are any ancestor parts that override the selection. if (PrepareCarefully.Instance.HealthManager.ImplantManager.AncestorIsImplant(pawn, option.BodyPartRecord)) { continue; } // Figure out the cost of the part replacement based on its recipe's ingredients. if (option.recipe != null) { RecipeDef def = option.recipe; foreach (IngredientCount amount in def.ingredients) { int count = 0; double totalCost = 0; bool skip = false; foreach (ThingDef ingredientDef in amount.filter.AllowedThingDefs) { if (ingredientDef == ThingDefOf.Medicine) { skip = true; break; } count++; EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[new EquipmentKey(ingredientDef, null)]; if (entry != null) { totalCost += entry.cost * (double)amount.GetBaseCount(); } } if (skip || count == 0) { continue; } cost.bionics += (int)(totalCost / (double)count); } } } cost.apparel = Math.Ceiling(cost.apparel); cost.bionics = Math.Ceiling(cost.bionics); // Use a multiplier to balance pawn cost vs. equipment cost. // Disabled for now. cost.Multiply(1.0); cost.ComputeTotal(); }
protected EquipmentDatabaseEntry CreateEquipmentEntry(ThingDef def, ThingDef stuffDef, Gender gender, int type) { double baseCost = costs.GetBaseThingCost(def, stuffDef); if (baseCost == 0) { return(null); } int stackSize = CalculateStackCount(def, baseCost); EquipmentDatabaseEntry result = new EquipmentDatabaseEntry(); result.type = type; result.def = def; result.stuffDef = stuffDef; result.stackSize = stackSize; result.cost = costs.CalculateStackCost(def, stuffDef, baseCost); result.stacks = true; result.gear = false; result.animal = false; if (def.MadeFromStuff && stuffDef != null) { if (stuffDef.stuffProps.allowColorGenerators && (def.colorGenerator != null || def.colorGeneratorInTraderStock != null)) { if (def.colorGenerator != null) { result.color = def.colorGenerator.NewRandomizedColor(); } else if (def.colorGeneratorInTraderStock != null) { result.color = def.colorGeneratorInTraderStock.NewRandomizedColor(); } } else { result.color = stuffDef.stuffProps.color; } } else { if (def.graphicData != null) { result.color = def.graphicData.color; } else { result.color = Color.white; } } if (def.apparel != null) { result.stacks = false; result.gear = true; } if (def.weaponTags != null && def.weaponTags.Count > 0) { result.stacks = false; result.gear = true; } if (def.thingCategories != null) { if (def.thingCategories.SingleOrDefault((ThingCategoryDef d) => { return(d.defName == "FoodMeals"); }) != null) { result.gear = true; } if (def.thingCategories.SingleOrDefault((ThingCategoryDef d) => { return(d.defName == "Medicine"); }) != null) { result.gear = true; } } if (def.defName == "Apparel_PersonalShield") { result.hideFromPortrait = true; } if (def.race != null && def.race.Animal) { result.animal = true; result.gender = gender; Pawn pawn = CreatePawn(def, stuffDef, gender); if (pawn == null) { return(null); } else { result.thing = pawn; } } return(result); }
protected void DrawSelectedEquipmentList() { if (destSelection >= PrepareCarefully.Instance.Equipment.Count) { destSelection = PrepareCarefully.Instance.Equipment.Count - 1; } GUI.color = ColorBoxBackground; GUI.DrawTexture(RectDestBox, BaseContent.WhiteTex); GUI.color = ColorBoxOutline; Widgets.DrawBox(RectDestBox, 1); try { GUI.color = Color.white; GUI.BeginGroup(RectDestContent); Rect scrollRect = new Rect(0, 0, RectDestContent.width, RectDestContent.height); Rect viewRect = new Rect(scrollRect.x, scrollRect.y, scrollRect.width - 16, destScrollViewHeight); Widgets.BeginScrollView(scrollRect, ref destScrollPosition, viewRect); Rect rectEntry = RectDestEntry; Rect rectText = RectDestEntry; rectText.x += 65; rectText.width = 320; Rect rectCost = RectDestEntry; rectCost.x += 352; rectCost.y += 7; rectCost.height -= 14; rectCost.width = 60; Rect rectItem = RectDestItem; Rect rectEntryButton = RectDestEntry; rectEntryButton.width = 320; bool alternateBackground = false; float top = destScrollPosition.y - rectEntry.height; float bottom = destScrollPosition.y + RectDestBox.height; int index = -1; foreach (SelectedEquipment customPawn in PrepareCarefully.Instance.Equipment) { index++; ThingDef def = customPawn.def; EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]; if (entry == null) { string thing = def != null ? def.defName : "null"; string stuff = customPawn.stuffDef != null ? customPawn.stuffDef.defName : "null"; Log.Warning(string.Format("Could not draw unrecognized resource/equipment. Invalid item was removed. This may have been caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); PrepareCarefully.Instance.RemoveEquipment(customPawn); continue; } SelectedEquipment loadoutRecord = PrepareCarefully.Instance.Find(entry); if (alternateBackground) { GUI.color = ColorEntryBackground; alternateBackground = false; } else { GUI.color = ColorBoxBackground; alternateBackground = true; } if (destSelection == index) { GUI.color = ColorSelectedEntry; } GUI.DrawTexture(rectEntry, BaseContent.WhiteTex); GUI.color = ColorText; Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(rectText, entry.LabelNoCount); DrawEquipmentIcon(rectItem, entry); Rect fieldRect = rectCost; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); equipmentDragSlider.OnGUI(fieldRect, loadoutRecord.count, (int value) => { var record = loadoutRecord; record.count = value; }); bool dragging = DragSlider.IsDragging(); Rect buttonRect = new Rect(fieldRect.x - 17, fieldRect.y + 6, 16, 16); if (!dragging && buttonRect.Contains(Event.current.mousePosition)) { GUI.color = ButtonHighlightColor; } else { GUI.color = ButtonColor; } GUI.DrawTexture(buttonRect, Textures.TextureButtonPrevious); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; loadoutRecord.count -= amount; if (loadoutRecord.count < 0) { loadoutRecord.count = 0; } } buttonRect = new Rect(fieldRect.x + fieldRect.width + 1, fieldRect.y + 6, 16, 16); if (!dragging && buttonRect.Contains(Event.current.mousePosition)) { GUI.color = ButtonHighlightColor; } else { GUI.color = ButtonColor; } GUI.DrawTexture(buttonRect, Textures.TextureButtonNext); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; loadoutRecord.count += amount; } if (rectEntry.y > top && rectEntry.y < bottom) { if (Event.current.type == EventType.MouseDown && rectEntryButton.Contains(Event.current.mousePosition)) { if (Event.current.clickCount == 1) { if (Event.current.button == 1) { if (destSelection != index) { destSelection = index; } List <FloatMenuOption> list = new List <FloatMenuOption>(); ThingDef thingDef = customPawn.def; ThingDef stuffDef = customPawn.stuffDef; list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate { Find.WindowStack.Add(new Dialog_InfoCard(thingDef, stuffDef)); }, MenuOptionPriority.Default, null, null, 0, null, null)); Find.WindowStack.Add(new FloatMenu(list, null, false)); } else { destSelection = index; SoundDefOf.TickHigh.PlayOneShotOnCamera(); } } else if (Event.current.clickCount == 2) { if (customPawn.count > 0) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; loadoutRecord.count -= amount; if (loadoutRecord.count < 0) { loadoutRecord.count = 0; } } else { SoundDefOf.TickLow.PlayOneShotOnCamera(); PrepareCarefully.Instance.RemoveEquipment(PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]); } } } } rectEntry.y += rectEntry.height; rectText.y += rectEntry.height; rectCost.y += rectEntry.height; rectItem.y += rectEntry.height; rectEntryButton.y += rectEntry.height; } if (Event.current.type == EventType.Layout) { destScrollViewHeight = rectEntry.y; } } catch (Exception e) { FatalError("Could not draw selected resources", e); } finally { Widgets.EndScrollView(); GUI.EndGroup(); } if (newDestScrollPosition >= 0) { destScrollPosition.y = newDestScrollPosition; newDestScrollPosition = -1; } GUI.color = Color.white; if (destSelection != -1) { if (Widgets.ButtonText(RectDestButton, "EdB.RemoveButton".Translate(), true, false, true)) { var customPawn = PrepareCarefully.Instance.Equipment[destSelection]; SoundDefOf.TickLow.PlayOneShotOnCamera(); PrepareCarefully.Instance.RemoveEquipment(PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]); } } }
protected void DrawEquipmentIcon(Rect rect, EquipmentDatabaseEntry entry) { GUI.color = entry.color; if (entry.thing == null) { // EdB: Inline copy of static Widgets.ThingIcon(Rect, ThingDef) with the selected // color based on the stuff. GUI.color = entry.color; // EdB: Inline copy of static private method with modifications to keep scaled icons within the // bounds of the specified Rect and to draw them using the stuff color. //Widgets.ThingIconWorker(rect, thing.def, thingDef.uiIcon); float num = GenUI.IconDrawScale(entry.def); Rect resizedRect = rect; if (num != 1f) { // For items that are going to scale out of the bounds of the icon rect, we need to shrink // the bounds a little. if (num > 1) { resizedRect = rect.ContractedBy(4); } resizedRect.width *= num; resizedRect.height *= num; resizedRect.center = rect.center; } GUI.DrawTexture(resizedRect, entry.def.uiIcon); GUI.color = Color.white; } else { // EdB: Inline copy of static Widgets.ThingIcon(Rect, Thing) with graphics switched to show a side view // instead of a front view. Thing thing = entry.thing; GUI.color = thing.DrawColor; Texture resolvedIcon; if (!thing.def.uiIconPath.NullOrEmpty()) { resolvedIcon = thing.def.uiIcon; } else if (thing is Pawn) { Pawn pawn = (Pawn)thing; if (!pawn.Drawer.renderer.graphics.AllResolved) { pawn.Drawer.renderer.graphics.ResolveAllGraphics(); } Material matSingle = pawn.Drawer.renderer.graphics.nakedGraphic.MatSide; resolvedIcon = matSingle.mainTexture; GUI.color = matSingle.color; } else { resolvedIcon = thing.Graphic.ExtractInnerGraphicFor(thing).MatSide.mainTexture; } // EdB: Inline copy of static private method. //Widgets.ThingIconWorker(rect, thing.def, resolvedIcon); float num = GenUI.IconDrawScale(thing.def); if (num != 1f) { Vector2 center = rect.center; rect.width *= num; rect.height *= num; rect.center = center; } GUI.DrawTexture(rect, resolvedIcon); } GUI.color = Color.white; }
public SelectedEquipment Find(EquipmentDatabaseEntry entry) { return(equipment.Find((SelectedEquipment e) => { return e.def == entry.def && e.stuffDef == entry.stuffDef && e.gender == entry.gender; })); }
// Copy of ScenPart_PlayerPawnsArriveMethod.GenerateIntoMap(), but with changes to spawn custom // equipment. public void SpawnColonistsWithEquipment(Map map, ScenPart_PlayerPawnsArriveMethod arriveMethodPart) { List <List <Thing> > list = new List <List <Thing> >(); foreach (Pawn current in Find.GameInitData.startingPawns) { list.Add(new List <Thing> { current }); } List <Thing> list2 = new List <Thing>(); foreach (ScenPart current2 in Find.Scenario.AllParts) { ScenPart_StartingThing_Defined startingThings = current2 as ScenPart_StartingThing_Defined; ScenPart_StartingAnimal animal = current2 as ScenPart_StartingAnimal; if (startingThings == null && animal == null) { list2.AddRange(current2.PlayerStartingThings()); } } int num = 0; foreach (Thing current3 in list2) { if (current3.def.CanHaveFaction) { current3.SetFactionDirect(Faction.OfPlayer); } list[num].Add(current3); num++; if (num >= list.Count) { num = 0; } } // Spawn custom equipment List <Thing> weapons = new List <Thing>(); List <Thing> food = new List <Thing>(); List <Thing> apparel = new List <Thing>(); List <Thing> animals = new List <Thing>(); List <Thing> other = new List <Thing>(); int maxStack = 50; foreach (var e in PrepareCarefully.Instance.Equipment) { EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[e.EquipmentKey]; if (entry == null) { string thing = e.def != null ? e.def.defName : "null"; string stuff = e.stuffDef != null ? e.stuffDef.defName : "null"; Log.Warning(string.Format("Unrecognized resource/equipment. This may be caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); continue; } if (entry.gear) { int count = e.Count; int idealStackCount = count / list.Count; while (count > 0) { int stackCount = idealStackCount; if (stackCount < 1) { stackCount = 1; } if (stackCount > entry.def.stackLimit) { stackCount = entry.def.stackLimit; } if (stackCount > maxStack) { stackCount = maxStack; } if (stackCount > count) { stackCount = count; } Thing thing = null; if (entry.def.MadeFromStuff && entry.stuffDef == null) { ThingDef defaultStuffDef = null; if (entry.def.apparel != null) { defaultStuffDef = ThingDef.Named("Synthread"); } if (thing == null) { Log.Warning("Item " + entry.def.defName + " is \"made from stuff\" but no material was specified. This may be caused by a misconfigured modded item or scenario."); Log.Warning("The item will be spawned into the map and assigned a default material, if possible, but you will see an error if you are in Development Mode."); } thing = ThingMaker.MakeThing(entry.def, defaultStuffDef); } else { thing = ThingMaker.MakeThing(entry.def, entry.stuffDef); } if (thing != null) { thing.stackCount = stackCount; if (entry.def.weaponTags != null && entry.def.weaponTags.Count > 0) { weapons.Add(thing); } else if (entry.def.apparel != null) { apparel.Add(thing); } else if (entry.def.ingestible != null) { food.Add(thing); } else { other.Add(thing); } } // Decrement the count whether we were able to add a valid thing or not. If we don't decrement, // we'll be stuck in an infinite while loop. count -= stackCount; } } else if (entry.animal) { int count = e.Count; for (int i = 0; i < count; i++) { Thing animal = CreateAnimal(entry); if (animal != null) { animals.Add(animal); } } } } List <Thing> combined = new List <Thing>(); combined.AddRange(weapons); combined.AddRange(food); combined.AddRange(apparel); combined.AddRange(animals); combined.AddRange(other); num = 0; foreach (Thing thing in combined) { if (thing.def.CanHaveFaction) { thing.SetFactionDirect(Faction.OfPlayer); } list[num].Add(thing); num++; if (num >= list.Count) { num = 0; } } // Get the arrive method from the scenario part. PlayerPawnsArriveMethod arriveMethod = PlayerPawnsArriveMethod.DropPods; if (arriveMethodPart != null) { arriveMethod = (PlayerPawnsArriveMethod)typeof(ScenPart_PlayerPawnsArriveMethod).GetField("method", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(arriveMethodPart); } bool instaDrop = Find.GameInitData.QuickStarted || arriveMethod != PlayerPawnsArriveMethod.DropPods; DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, map, list, 110, instaDrop, true, true); }