Ejemplo n.º 1
0
 public LoadableEquipment(SelectedEquipment customPawn)
 {
     count    = customPawn.count;
     def      = customPawn.def.defName;
     stuffDef = customPawn.stuffDef.defName;
     gender   = customPawn.gender == Gender.None ? null : customPawn.gender.ToString();
 }
Ejemplo n.º 2
0
        public void RemoveEquipment(EquipmentDatabaseEntry entry)
        {
            SelectedEquipment e = Find(entry);

            if (e != null)
            {
                removals.Add(e);
            }
        }
        public double CalculateEquipmentCost(SelectedEquipment customPawn)
        {
            EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey];

            if (entry != null)
            {
                return((double)customPawn.count * entry.cost);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        //
        // Static Methods
        //
        public static void SaveToFile(PrepareCarefully data, string presetName)
        {
            try {
                Scribe.InitWriting(PresetFiles.FilePathForSavedPreset(presetName), "preset");
                string versionStringFull = "3";
                Scribe_Values.LookValue <string>(ref versionStringFull, "version", null, false);
                bool usePoints      = data.Config.pointsEnabled;
                int  startingPoints = PrepareCarefully.Instance.StartingPoints;
                Scribe_Values.LookValue <bool>(ref usePoints, "usePoints", false, true);
                Scribe_Values.LookValue <int>(ref startingPoints, "startingPoints", 0, true);
                string modString = GenText.ToCommaList(Enumerable.Select <ModContentPack, string>(LoadedModManager.RunningMods, (Func <ModContentPack, string>)(mod => mod.Name)), true);
                Scribe_Values.LookValue <string>(ref modString, "mods", null, false);
                Scribe.EnterNode("colonists");
                foreach (CustomPawn customPawn in data.Pawns)
                {
                    SaveRecordPawnV3 pawn = new SaveRecordPawnV3(customPawn);
                    Scribe_Deep.LookDeep <SaveRecordPawnV3>(ref pawn, "colonist");
                }
                Scribe.ExitNode();

                Scribe.EnterNode("relationships");
                foreach (var r in data.RelationshipManager.ExplicitRelationships)
                {
                    SaveRecordRelationshipV3 s = new SaveRecordRelationshipV3(r);
                    Scribe_Deep.LookDeep <SaveRecordRelationshipV3>(ref s, "relationship");
                }
                Scribe.ExitNode();

                Scribe.EnterNode("equipment");
                foreach (var e in data.Equipment)
                {
                    SelectedEquipment customPawn = e;
                    Scribe_Deep.LookDeep <SelectedEquipment>(ref customPawn, "equipment");
                }
                Scribe.ExitNode();
            }
            catch (Exception e) {
                Log.Error("Failed to save preset file");
                throw e;
            }
            finally {
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
Ejemplo n.º 7
0
 public void RemoveEquipment(SelectedEquipment equipment)
 {
     removals.Add(equipment);
 }
        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();
        }
Ejemplo n.º 9
0
        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]);
                }
            }
        }