예제 #1
0
 public SaveRecordPawnV3(CustomPawn pawn)
 {
     this.gender           = pawn.Gender;
     this.adulthood        = pawn.Adulthood.uniqueSaveKey;
     this.childhood        = pawn.Childhood.uniqueSaveKey;
     this.skinColor        = pawn.SkinColor;
     this.hairDef          = pawn.HairDef.defName;
     this.hairColor        = pawn.GetColor(PawnLayers.Hair);
     this.headGraphicPath  = pawn.HeadGraphicPath;
     this.firstName        = pawn.FirstName;
     this.nickName         = pawn.NickName;
     this.lastName         = pawn.LastName;
     this.age              = 0;
     this.biologicalAge    = pawn.BiologicalAge;
     this.chronologicalAge = pawn.ChronologicalAge;
     foreach (var trait in pawn.Traits)
     {
         if (trait != null)
         {
             this.traitNames.Add(trait.def.defName);
             this.traitDegrees.Add(trait.Degree);
         }
     }
     foreach (var skill in pawn.Pawn.skills.skills)
     {
         this.skillNames.Add(skill.def.defName);
         this.skillValues.Add(pawn.GetUnmodifiedSkillLevel(skill.def));
         this.passions.Add(pawn.currentPassions[skill.def]);
         this.originalPassions.Add(pawn.originalPassions[skill.def]);
     }
     for (int layer = 0; layer < PawnLayers.Count; layer++)
     {
         ThingDef thingDef = pawn.GetAcceptedApparel(layer);
         ThingDef stuffDef = pawn.GetSelectedStuff(layer);
         Color    color    = pawn.GetColor(layer);
         if (thingDef != null)
         {
             this.apparelLayers.Add(layer);
             this.apparel.Add(thingDef.defName);
             this.apparelStuff.Add(stuffDef != null ? stuffDef.defName : "");
             this.apparelColors.Add(color);
         }
     }
     this.randomInjuries = pawn.RandomInjuries;
     foreach (Implant implant in pawn.Implants)
     {
         this.implants.Add(new SaveRecordImplantV3(implant));
     }
     foreach (Injury injury in pawn.Injuries)
     {
         this.injuries.Add(new SaveRecordInjuryV3(injury));
     }
 }
예제 #2
0
        protected void ShowApparelDialog(CustomPawn customPawn, int layer)
        {
            List <ThingDef>           apparelList = PrepareCarefully.Instance.Providers.Apparel.GetApparel(customPawn, layer);
            Dialog_Options <ThingDef> dialog      = new Dialog_Options <ThingDef>(apparelList)
            {
                IncludeNone = true,
                NameFunc    = (ThingDef apparel) => {
                    return(apparel.LabelCap);
                },
                SelectedFunc = (ThingDef apparel) => {
                    return(customPawn.GetSelectedApparel(layer) == apparel);
                },
                SelectAction = (ThingDef apparel) => {
                    this.pawnLayerLabel = apparel.LabelCap;
                    if (apparel.MadeFromStuff)
                    {
                        if (customPawn.GetSelectedStuff(layer) == null)
                        {
                            customPawn.SetSelectedStuff(layer, apparelStuffLookup[apparel][0]);
                        }
                    }
                    else
                    {
                        customPawn.SetSelectedStuff(layer, null);
                    }
                    customPawn.SetSelectedApparel(layer, apparel);
                },
                NoneSelectedFunc = () => {
                    return(customPawn.GetSelectedApparel(layer) == null);
                },
                SelectNoneAction = () => {
                    customPawn.SetSelectedApparel(layer, null);
                    customPawn.SetSelectedStuff(layer, null);
                    this.pawnLayerLabel = "EdB.PC.Panel.Appearance.NoneSelected".Translate();
                }
            };

            Find.WindowStack.Add(dialog);
        }
예제 #3
0
        protected void SelectNextApparel(CustomPawn customPawn, int direction)
        {
            int             layer       = this.selectedPawnLayer;
            List <ThingDef> apparelList = PrepareCarefully.Instance.Providers.Apparel.GetApparel(customPawn, layer);
            int             index       = apparelList.IndexOf(customPawn.GetSelectedApparel(layer));

            index += direction;
            if (index < -1)
            {
                index = apparelList.Count - 1;
            }
            else if (index >= apparelList.Count)
            {
                index = -1;
            }
            if (index > -1)
            {
                this.pawnLayerLabel = apparelList[index].label;
                if (apparelList[index].MadeFromStuff)
                {
                    if (customPawn.GetSelectedStuff(layer) == null)
                    {
                        customPawn.SetSelectedStuff(layer, apparelStuffLookup[apparelList[index]][0]);
                    }
                }
                else
                {
                    customPawn.SetSelectedStuff(layer, null);
                }
                customPawn.SetSelectedApparel(layer, apparelList[index]);
            }
            else
            {
                customPawn.SetSelectedApparel(layer, null);
                customPawn.SetSelectedStuff(layer, null);
                this.pawnLayerLabel = "EdB.PC.Common.None".Translate();
            }
        }
예제 #4
0
        protected void ShowApparelStuffDialog(CustomPawn customPawn, int layer)
        {
            ThingDef apparel = customPawn.GetSelectedApparel(layer);

            if (apparel == null)
            {
                return;
            }
            List <ThingDef>           stuffList = this.apparelStuffLookup[apparel];
            Dialog_Options <ThingDef> dialog    = new Dialog_Options <ThingDef>(stuffList)
            {
                NameFunc = (ThingDef stuff) => {
                    return(stuff.LabelCap);
                },
                SelectedFunc = (ThingDef stuff) => {
                    return(customPawn.GetSelectedStuff(layer) == stuff);
                },
                SelectAction = (ThingDef stuff) => {
                    customPawn.SetSelectedStuff(layer, stuff);
                }
            };

            Find.WindowStack.Add(dialog);
        }
        public SaveRecordPawnV4(CustomPawn pawn)
        {
            this.id       = pawn.Id;
            this.thingDef = pawn.Pawn.def.defName;
            this.type     = pawn.Type.ToString();
            if (pawn.Type == CustomPawnType.World && pawn.Faction != null)
            {
                this.faction        = new SaveRecordFactionV4();
                this.faction.def    = pawn.Faction.Def != null ? pawn.Faction.Def.defName : null;
                this.faction.index  = pawn.Faction.Index;
                this.faction.leader = pawn.Faction.Leader;
            }
            this.pawnKindDef        = pawn.OriginalKindDef != null ? pawn.OriginalKindDef.defName : pawn.Pawn.kindDef.defName;
            this.originalFactionDef = pawn.OriginalFactionDef != null ? pawn.OriginalFactionDef.defName : null;
            this.gender             = pawn.Gender;
            if (pawn.Adulthood != null)
            {
                this.adulthood = pawn.Adulthood.identifier;
            }
            else
            {
                this.adulthood = pawn.LastSelectedAdulthoodBackstory?.identifier;
            }
            this.childhood        = pawn.Childhood.identifier;
            this.skinColor        = pawn.Pawn.story.SkinColor;
            this.melanin          = pawn.Pawn.story.melanin;
            this.hairDef          = pawn.HairDef.defName;
            this.hairColor        = pawn.Pawn.story.hairColor;
            this.headGraphicPath  = pawn.HeadGraphicPath;
            this.bodyType         = pawn.BodyType.defName;
            this.firstName        = pawn.FirstName;
            this.nickName         = pawn.NickName;
            this.lastName         = pawn.LastName;
            this.age              = 0;
            this.biologicalAge    = pawn.BiologicalAge;
            this.chronologicalAge = pawn.ChronologicalAge;
            foreach (var trait in pawn.Traits)
            {
                if (trait != null)
                {
                    this.traitNames.Add(trait.def.defName);
                    this.traitDegrees.Add(trait.Degree);
                }
            }
            foreach (var skill in pawn.Pawn.skills.skills)
            {
                SaveRecordSkillV4 skillRecord = new SaveRecordSkillV4();
                skillRecord.name    = skill.def.defName;
                skillRecord.value   = pawn.GetUnmodifiedSkillLevel(skill.def);
                skillRecord.passion = pawn.currentPassions[skill.def];
                this.skills.Add(skillRecord);
            }
            foreach (var layer in PrepareCarefully.Instance.Providers.PawnLayers.GetLayersForPawn(pawn))
            {
                if (layer.Apparel)
                {
                    ThingDef apparelThingDef = pawn.GetAcceptedApparel(layer);
                    Color    color           = pawn.GetColor(layer);
                    if (apparelThingDef != null)
                    {
                        ThingDef            apparelStuffDef = pawn.GetSelectedStuff(layer);
                        SaveRecordApparelV4 apparelRecord   = new SaveRecordApparelV4();
                        apparelRecord.layer   = layer.Name;
                        apparelRecord.apparel = apparelThingDef.defName;
                        apparelRecord.stuff   = apparelStuffDef != null ? apparelStuffDef.defName : "";
                        apparelRecord.color   = color;
                        this.apparel.Add(apparelRecord);
                    }
                }
            }
            OptionsHealth healthOptions = PrepareCarefully.Instance.Providers.Health.GetOptions(pawn);

            foreach (Implant implant in pawn.Implants)
            {
                var saveRecord = new SaveRecordImplantV3(implant);
                if (implant.BodyPartRecord != null)
                {
                    UniqueBodyPart part = healthOptions.FindBodyPartsForRecord(implant.BodyPartRecord);
                    if (part != null && part.Index > 0)
                    {
                        saveRecord.bodyPartIndex = part.Index;
                    }
                }
                this.implants.Add(saveRecord);
            }
            foreach (Injury injury in pawn.Injuries)
            {
                var saveRecord = new SaveRecordInjuryV3(injury);
                if (injury.BodyPartRecord != null)
                {
                    UniqueBodyPart part = healthOptions.FindBodyPartsForRecord(injury.BodyPartRecord);
                    if (part != null && part.Index > 0)
                    {
                        saveRecord.bodyPartIndex = part.Index;
                    }
                }
                this.injuries.Add(saveRecord);
            }

            ThingComp alienComp = ProviderAlienRaces.FindAlienCompForPawn(pawn.Pawn);

            if (alienComp != null)
            {
                alien                 = new SaveRecordAlienV4();
                alien.crownType       = ProviderAlienRaces.GetCrownTypeFromComp(alienComp);
                alien.skinColor       = ProviderAlienRaces.GetSkinColorFromComp(alienComp);
                alien.skinColorSecond = ProviderAlienRaces.GetSkinColorSecondFromComp(alienComp);
                alien.hairColorSecond = ProviderAlienRaces.GetHairColorSecondFromComp(alienComp);
            }
        }
예제 #6
0
        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;

            // 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;

            // Calculate trait cost.
            if (pawn.TraitCount > Constraints.MaxVanillaTraits)
            {
                int    extraTraitCount = pawn.TraitCount - Constraints.MaxVanillaTraits;
                double extraTraitCost  = 100;
                for (int i = 0; i < extraTraitCount; i++)
                {
                    cost.marketValue += extraTraitCost;
                    extraTraitCost    = Math.Ceiling(extraTraitCost * 2.5);
                }
            }

            // Calculate cost of worn apparel.
            for (int layer = 0; layer < PawnLayers.Count; layer++)
            {
                if (PawnLayers.IsApparelLayer(layer))
                {
                    var def = pawn.GetAcceptedApparel(layer);
                    if (def == null)
                    {
                        continue;
                    }
                    EquipmentKey key = new EquipmentKey();
                    key.ThingDef = def;
                    key.StuffDef = pawn.GetSelectedStuff(layer);
                    EquipmentRecord record = PrepareCarefully.Instance.EquipmentDatabase.Find(key);
                    if (record == null)
                    {
                        continue;
                    }
                    EquipmentSelection selection = new EquipmentSelection(record, 1);
                    double             c         = CalculateEquipmentCost(selection);
                    if (def != null)
                    {
                        // TODO: Discounted materials should be based on the faction, not hard-coded.
                        // TODO: Should we continue with the discounting?
                        if (key.StuffDef != null)
                        {
                            if (key.StuffDef.defName == "Synthread")
                            {
                                if (freeApparel.Contains(key.ThingDef.defName))
                                {
                                    c = 0;
                                }
                                else if (cheapApparel.Contains(key.ThingDef.defName))
                                {
                                    c = c * 0.15d;
                                }
                            }
                        }
                    }
                    cost.apparel += c;
                }
            }

            // Calculate cost for any materials needed for implants.
            OptionsHealth healthOptions = PrepareCarefully.Instance.Providers.Health.GetOptions(pawn);

            foreach (Implant option in pawn.Implants)
            {
                // Check if there are any ancestor parts that override the selection.
                UniqueBodyPart uniquePart = healthOptions.FindBodyPartsForRecord(option.BodyPartRecord);
                if (uniquePart == null)
                {
                    Log.Warning("Prepare Carefully could not find body part record when computing the cost of an implant: " + option.BodyPartRecord.def.defName);
                    continue;
                }
                if (pawn.AtLeastOneImplantedPart(uniquePart.Ancestors.Select((UniqueBodyPart p) => { return(p.Record); })))
                {
                    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++;
                            EquipmentRecord entry = PrepareCarefully.Instance.EquipmentDatabase[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();
        }
예제 #7
0
        protected override void DrawPanelContent(State state)
        {
            base.DrawPanelContent(state);
            CustomPawn customPawn = state.CurrentPawn;

            string label = PawnLayers.Label(this.selectedPawnLayer);

            if (WidgetDropdown.Button(RectLayerSelector, label, true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                int layerCount = this.pawnLayerActions.Count;
                for (int i = 0; i < layerCount; i++)
                {
                    int pawnLayer = pawnLayers[i];
                    label = PawnLayers.Label(pawnLayers[i]);
                    list.Add(new FloatMenuOption(label, this.pawnLayerActions[i], MenuOptionPriority.Default, null, null, 0, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list, null, false));
            }
            GUI.DrawTexture(RectPortrait, Textures.TexturePortraitBackground);

            customPawn.UpdatePortrait();
            DrawPawn(customPawn, RectPortrait);

            GUI.color = ColorPortraitBorder;
            Widgets.DrawBox(RectPortrait, 1);
            GUI.color = Color.white;

            // Conflict alert
            if (customPawn.ApparelConflict != null)
            {
                GUI.color = Color.white;
                Rect alertRect = new Rect(RectPortrait.x + 77, RectPortrait.y + 150, 36, 32);
                GUI.DrawTexture(alertRect, Textures.TextureAlert);
                TooltipHandler.TipRegion(alertRect, customPawn.ApparelConflict);
            }

            // Draw selector field.
            Rect   fieldRect = new Rect(RectPortrait.x, RectPortrait.y + RectPortrait.height + 5, RectPortrait.width, 28);
            Action previousSelectionAction = null;
            Action nextSelectionAction     = null;
            Action clickAction             = null;

            OptionsApparel  apparelOptions = null;
            List <ThingDef> apparelList    = null;
            OptionsHair     hairOptions    = null;
            List <HairDef>  hairList       = null;

            if (this.selectedPawnLayer == PawnLayers.Hair)
            {
                hairOptions = PrepareCarefully.Instance.Providers.Hair.GetHairsForRace(customPawn);
                hairList    = hairOptions.GetHairs(customPawn.Gender);
            }
            else if (PawnLayers.IsApparelLayer(this.selectedPawnLayer))
            {
                apparelOptions = PrepareCarefully.Instance.Providers.Apparel.GetApparelForRace(customPawn);
                apparelList    = apparelOptions.GetApparel(this.selectedPawnLayer);
            }

            if (this.selectedPawnLayer == PawnLayers.HeadType)
            {
                int headTypeCount = PrepareCarefully.Instance.Providers.HeadTypes.GetHeadTypes(customPawn).Count();
                if (customPawn.HeadType != null && headTypeCount > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHead(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHead(customPawn, 1);
                    };
                }
                if (customPawn.HeadType != null && headTypeCount > 0)
                {
                    clickAction = () => {
                        ShowHeadDialog(customPawn);
                    };
                }
            }
            else if (this.selectedPawnLayer == PawnLayers.BodyType)
            {
                if (PrepareCarefully.Instance.Providers.BodyTypes.GetBodyTypesForPawn(customPawn.Pawn).Count > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextBodyType(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextBodyType(customPawn, 1);
                    };
                }
                clickAction = () => {
                    ShowBodyTypeDialog(customPawn);
                };
            }
            else if (this.selectedPawnLayer == PawnLayers.Hair)
            {
                if (hairList.Count > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHair(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHair(customPawn, 1);
                    };
                }
                if (hairList.Count > 0)
                {
                    clickAction = () => {
                        ShowHairDialog(customPawn);
                    };
                }
            }
            else
            {
                if (apparelList.Count > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextApparel(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SelectNextApparel(customPawn, 1);
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                    };
                }
                if (apparelList.Count > 0)
                {
                    clickAction = () => {
                        ShowApparelDialog(customPawn, this.selectedPawnLayer);
                    };
                }
            }

            string selectorLabel = PawnLayerLabel.CapitalizeFirst();

            if (hairList != null && hairList.Count == 0)
            {
                selectorLabel = "EdB.PC.Common.NoOptionAvailable".Translate();
            }
            if (apparelList != null && apparelList.Count == 0)
            {
                selectorLabel = "EdB.PC.Common.NoOptionAvailable".Translate();
            }
            DrawFieldSelector(fieldRect, selectorLabel, previousSelectionAction, nextSelectionAction, clickAction);

            float cursorY = fieldRect.y + 34;

            // Draw stuff selector for apparel
            if (PawnLayers.IsApparelLayer(this.selectedPawnLayer))
            {
                ThingDef apparelDef = customPawn.GetSelectedApparel(selectedPawnLayer);
                if (apparelDef != null && apparelDef.MadeFromStuff)
                {
                    if (customPawn.GetSelectedStuff(selectedPawnLayer) == null)
                    {
                        Log.Error("Selected stuff for " + PawnLayers.ToApparelLayer(selectedPawnLayer) + " is null");
                    }
                    Rect stuffFieldRect = new Rect(RectPortrait.x, cursorY, RectPortrait.width, 28);
                    DrawFieldSelector(stuffFieldRect, customPawn.GetSelectedStuff(selectedPawnLayer).LabelCap,
                                      () => {
                        ThingDef selected = customPawn.GetSelectedStuff(selectedPawnLayer);
                        int index         = this.apparelStuffLookup[apparelDef].FindIndex((ThingDef d) => { return(selected == d); });
                        index--;
                        if (index < 0)
                        {
                            index = this.apparelStuffLookup[apparelDef].Count - 1;
                        }
                        customPawn.SetSelectedStuff(selectedPawnLayer, apparelStuffLookup[apparelDef][index]);
                    },
                                      () => {
                        ThingDef selected = customPawn.GetSelectedStuff(selectedPawnLayer);
                        int index         = this.apparelStuffLookup[apparelDef].FindIndex((ThingDef d) => { return(selected == d); });
                        index++;
                        if (index >= this.apparelStuffLookup[apparelDef].Count)
                        {
                            index = 0;
                        }
                        customPawn.SetSelectedStuff(selectedPawnLayer, this.apparelStuffLookup[apparelDef][index]);
                    },
                                      () => {
                        ShowApparelStuffDialog(customPawn, this.selectedPawnLayer);
                    }
                                      );

                    cursorY += stuffFieldRect.height;
                }
            }
            cursorY += 8;

            // Draw Color Selector
            if (PawnLayers.IsApparelLayer(selectedPawnLayer))
            {
                if (apparelList != null && apparelList.Count > 0)
                {
                    ThingDef def = customPawn.GetSelectedApparel(selectedPawnLayer);
                    if (def != null && def.HasComp(typeof(CompColorable)))
                    {
                        if (def.MadeFromStuff)
                        {
                            DrawColorSelector(customPawn, cursorY, null);
                        }
                        else
                        {
                            DrawColorSelector(customPawn, cursorY, def.colorGenerator);
                        }
                    }
                }
            }
            else if (selectedPawnLayer == PawnLayers.BodyType || selectedPawnLayer == PawnLayers.HeadType)
            {
                AlienRace alienRace = customPawn.AlienRace;
                if (alienRace == null || alienRace.UseMelaninLevels)
                {
                    DrawHumanlikeColorSelector(customPawn, cursorY);
                }
                else
                {
                    DrawAlienPawnColorSelector(customPawn, cursorY, alienRace.PrimaryColors, true);
                }
            }
            else if (selectedPawnLayer == PawnLayers.Hair)
            {
                if (hairList != null && hairList.Count > 0)
                {
                    DrawColorSelector(customPawn, cursorY, hairOptions.Colors, true);
                }
            }

            // Random button
            if (RectButtonRandomize.Contains(Event.current.mousePosition))
            {
                GUI.color = Style.ColorButtonHighlight;
            }
            else
            {
                GUI.color = Style.ColorButton;
            }
            GUI.DrawTexture(RectButtonRandomize, Textures.TextureButtonRandom);
            if (Widgets.ButtonInvisible(RectButtonRandomize, false))
            {
                SoundDefOf.TickLow.PlayOneShotOnCamera();
                RandomizeAppearance();
            }

            // Gender buttons.
            if (state.CurrentPawn.Pawn.RaceProps != null && state.CurrentPawn.Pawn.RaceProps.hasGenders)
            {
                bool genderFemaleSelected = state.CurrentPawn.Gender == Gender.Female;
                Style.SetGUIColorForButton(RectGenderFemale, genderFemaleSelected);
                GUI.DrawTexture(RectGenderFemale, Textures.TextureButtonGenderFemale);
                if (!genderFemaleSelected && Widgets.ButtonInvisible(RectGenderFemale, false))
                {
                    SoundDefOf.TickTiny.PlayOneShotOnCamera();
                    GenderUpdated(Gender.Female);
                }
                bool genderMaleSelected = state.CurrentPawn.Gender == Gender.Male;
                Style.SetGUIColorForButton(RectGenderMale, genderMaleSelected);
                GUI.DrawTexture(RectGenderMale, Textures.TextureButtonGenderMale);
                if (!genderMaleSelected && Widgets.ButtonInvisible(RectGenderMale, false))
                {
                    SoundDefOf.TickTiny.PlayOneShotOnCamera();
                    GenderUpdated(Gender.Male);
                }
            }
            GUI.color = Color.white;
        }
        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();
        }
        public SaveRecordPawnV5(CustomPawn pawn)
        {
            this.id       = pawn.Id;
            this.thingDef = pawn.Pawn.def.defName;
            this.type     = pawn.Type.ToString();
            if (pawn.Type == CustomPawnType.World && pawn.Faction != null)
            {
                this.faction = new SaveRecordFactionV4()
                {
                    def    = pawn.Faction?.Def?.defName,
                    index  = pawn.Faction.Index,
                    leader = pawn.Faction.Leader
                };
            }
            this.pawnKindDef        = pawn.OriginalKindDef?.defName ?? pawn.Pawn.kindDef.defName;
            this.originalFactionDef = pawn.OriginalFactionDef?.defName;
            this.gender             = pawn.Gender;
            this.adulthood          = pawn.Adulthood?.identifier ?? pawn.LastSelectedAdulthoodBackstory?.identifier;
            this.childhood          = pawn.Childhood?.identifier;
            this.skinColor          = pawn.Pawn.story.SkinColor;
            this.melanin            = pawn.Pawn.story.melanin;
            this.hairDef            = pawn.HairDef.defName;
            this.hairColor          = pawn.Pawn.story.hairColor;
            this.headGraphicPath    = pawn.HeadGraphicPath;
            this.bodyType           = pawn.BodyType.defName;
            this.firstName          = pawn.FirstName;
            this.nickName           = pawn.NickName;
            this.lastName           = pawn.LastName;
            this.age              = 0;
            this.biologicalAge    = pawn.BiologicalAge;
            this.chronologicalAge = pawn.ChronologicalAge;
            foreach (var trait in pawn.Traits)
            {
                if (trait != null)
                {
                    this.traits.Add(new SaveRecordTraitV5()
                    {
                        def    = trait.def.defName,
                        degree = trait.Degree
                    });
                }
            }
            foreach (var skill in pawn.Pawn.skills.skills)
            {
                this.skills.Add(new SaveRecordSkillV4()
                {
                    name    = skill.def.defName,
                    value   = pawn.GetUnmodifiedSkillLevel(skill.def),
                    passion = pawn.currentPassions[skill.def]
                });
            }
            foreach (var layer in PrepareCarefully.Instance.Providers.PawnLayers.GetLayersForPawn(pawn))
            {
                if (layer.Apparel)
                {
                    ThingDef apparelThingDef = pawn.GetAcceptedApparel(layer);
                    Color    color           = pawn.GetColor(layer);
                    if (apparelThingDef != null)
                    {
                        ThingDef apparelStuffDef = pawn.GetSelectedStuff(layer);
                        this.apparel.Add(new SaveRecordApparelV4()
                        {
                            layer   = layer.Name,
                            apparel = apparelThingDef.defName,
                            stuff   = apparelStuffDef?.defName ?? "",
                            color   = color
                        });
                    }
                }
            }
            OptionsHealth healthOptions = PrepareCarefully.Instance.Providers.Health.GetOptions(pawn);

            foreach (Implant implant in pawn.Implants)
            {
                var saveRecord = new SaveRecordImplantV3(implant);
                if (implant.BodyPartRecord != null)
                {
                    UniqueBodyPart part = healthOptions.FindBodyPartsForRecord(implant.BodyPartRecord);
                    if (part != null && part.Index > 0)
                    {
                        saveRecord.bodyPartIndex = part.Index;
                    }
                }
                this.implants.Add(saveRecord);
            }
            foreach (Injury injury in pawn.Injuries)
            {
                var saveRecord = new SaveRecordInjuryV3(injury);
                if (injury.BodyPartRecord != null)
                {
                    UniqueBodyPart part = healthOptions.FindBodyPartsForRecord(injury.BodyPartRecord);
                    if (part != null && part.Index > 0)
                    {
                        saveRecord.bodyPartIndex = part.Index;
                    }
                }
                this.injuries.Add(saveRecord);
            }

            pawnCompsSaver = new PawnCompsSaver(pawn.Pawn, DefaultPawnCompRules.RulesForSaving);
        }
예제 #10
0
        public SaveRecordPawnV3(CustomPawn pawn)
        {
            this.id          = pawn.Id;
            this.thingDef    = pawn.Pawn.def.defName;
            this.pawnKindDef = pawn.Pawn.kindDef.defName;
            this.gender      = pawn.Gender;
            if (pawn.Adulthood != null)
            {
                this.adulthood = pawn.Adulthood.identifier;
            }
            else
            {
                this.adulthood = pawn.LastSelectedAdulthoodBackstory.identifier;
            }
            this.childhood        = pawn.Childhood.identifier;
            this.skinColor        = pawn.Pawn.story.SkinColor;
            this.melanin          = pawn.Pawn.story.melanin;
            this.hairDef          = pawn.HairDef.defName;
            this.hairColor        = pawn.GetColor(PawnLayers.Hair);
            this.headGraphicPath  = pawn.HeadGraphicPath;
            this.bodyType         = Enum.GetName(typeof(BodyType), pawn.BodyType);
            this.firstName        = pawn.FirstName;
            this.nickName         = pawn.NickName;
            this.lastName         = pawn.LastName;
            this.age              = 0;
            this.biologicalAge    = pawn.BiologicalAge;
            this.chronologicalAge = pawn.ChronologicalAge;
            foreach (var trait in pawn.Traits)
            {
                if (trait != null)
                {
                    this.traitNames.Add(trait.def.defName);
                    this.traitDegrees.Add(trait.Degree);
                }
            }
            foreach (var skill in pawn.Pawn.skills.skills)
            {
                this.skillNames.Add(skill.def.defName);
                this.skillValues.Add(pawn.GetUnmodifiedSkillLevel(skill.def));
                this.passions.Add(pawn.currentPassions[skill.def]);
                this.originalPassions.Add(pawn.originalPassions[skill.def]);
            }
            for (int layer = 0; layer < PawnLayers.Count; layer++)
            {
                ThingDef apparelThingDef = pawn.GetAcceptedApparel(layer);
                ThingDef apparelStuffDef = pawn.GetSelectedStuff(layer);
                Color    color           = pawn.GetColor(layer);
                if (apparelThingDef != null)
                {
                    this.apparelLayers.Add(layer);
                    this.apparel.Add(apparelThingDef.defName);
                    this.apparelStuff.Add(apparelStuffDef != null ? apparelStuffDef.defName : "");
                    this.apparelColors.Add(color);
                }
            }
            OptionsHealth healthOptions = PrepareCarefully.Instance.Providers.Health.GetOptions(pawn);

            foreach (Implant implant in pawn.Implants)
            {
                var saveRecord = new SaveRecordImplantV3(implant);
                if (implant.BodyPartRecord != null)
                {
                    UniqueBodyPart part = healthOptions.FindBodyPartsForRecord(implant.BodyPartRecord);
                    if (part != null && part.Index > 0)
                    {
                        saveRecord.bodyPartIndex = part.Index;
                    }
                }
                this.implants.Add(saveRecord);
            }
            foreach (Injury injury in pawn.Injuries)
            {
                var saveRecord = new SaveRecordInjuryV3(injury);
                if (injury.BodyPartRecord != null)
                {
                    UniqueBodyPart part = healthOptions.FindBodyPartsForRecord(injury.BodyPartRecord);
                    if (part != null && part.Index > 0)
                    {
                        saveRecord.bodyPartIndex = part.Index;
                    }
                }
                this.injuries.Add(saveRecord);
            }
        }