public void UpdateEquipmentCount(EquipmentSelection equipment, int count)
 {
     if (count >= 0)
     {
         equipment.Count = count;
     }
 }
Пример #2
0
 public EquipmentSaveRecord(EquipmentSelection equipment)
 {
     count    = equipment.Count;
     def      = equipment.Record.def.defName;
     stuffDef = equipment.Record.stuffDef != null ? equipment.Record.stuffDef.defName : null;
     gender   = equipment.Record.gender == Gender.None ? null : equipment.Record.gender.ToString();
 }
        public void RemoveEquipment(EquipmentRecord entry)
        {
            EquipmentSelection e = Find(entry);

            if (e != null)
            {
                equipmentToRemove.Add(e);
            }
        }
Пример #4
0
 protected bool PlayerStartsWith(EquipmentSelection s)
 {
     if (s.record.gear)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public void EquipmentAdded(EquipmentRecord entry)
        {
            EquipmentSelection loadoutRecord = PrepareCarefully.Instance.Find(entry);

            if (loadoutRecord != null)
            {
                table.Selected = loadoutRecord;
                // Mark that we want to scroll to the newly added entry.  We can only scroll to it once
                // it's already been drawn once in the list, so we need to temporarily store a value that
                // we'll use on the next draw pass.
                ScrollToEntry = loadoutRecord.Record;
            }
        }
Пример #6
0
        public double CalculateEquipmentCost(EquipmentSelection equipment)
        {
            EquipmentRecord entry = PrepareCarefully.Instance.EquipmentDatabase[equipment.Key];

            if (entry != null)
            {
                return((double)equipment.Count * entry.cost);
            }
            else
            {
                return(0);
            }
        }
        protected EquipmentSelection FindEntry(EquipmentSelection equipment)
        {
            ThingDef        def   = equipment.ThingDef;
            EquipmentRecord entry = PrepareCarefully.Instance.EquipmentDatabase[equipment.Key];

            if (entry == null)
            {
                string thing = def != null ? def.defName : "null";
                string stuff = equipment.StuffDef != null ? equipment.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(equipment);
                return(null);
            }
            return(PrepareCarefully.Instance.Find(entry));
        }
        public bool AddEquipment(EquipmentRecord entry, int count)
        {
            SyncEquipmentRemovals();
            EquipmentSelection e = Find(entry);

            if (e == null)
            {
                equipment.Add(new EquipmentSelection(entry, count));
                return(true);
            }
            else
            {
                e.Count += count;
                return(false);
            }
        }
Пример #9
0
        public bool AddEquipment(EquipmentRecord record, int count)
        {
            if (record == null)
            {
                return(false);
            }
            SyncEquipmentRemovals();
            EquipmentSelection e = Find(record);

            if (e == null)
            {
                equipment.Add(new EquipmentSelection(record, count));
                return(true);
            }
            else
            {
                e.Count += count;
                return(false);
            }
        }
Пример #10
0
        public bool AddEquipment(EquipmentRecord entry)
        {
            if (entry == null)
            {
                return(false);
            }
            SyncEquipmentRemovals();
            EquipmentSelection e = Find(entry);

            if (e == null)
            {
                equipment.Add(new EquipmentSelection(entry));
                return(true);
            }
            else
            {
                e.Count += entry.stackSize;
                return(false);
            }
        }
Пример #11
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();
        }
 public void RemoveEquipment(EquipmentSelection equipment)
 {
     equipmentToRemove.Add(equipment);
 }
 public void RemoveEquipment(EquipmentSelection equipment)
 {
     PrepareCarefully.Instance.RemoveEquipment(equipment);
 }