Ejemplo n.º 1
0
        protected AnimalRecord CreateAnimalRecord(ThingDef def, Gender gender)
        {
            double baseCost = costCalculator.GetBaseThingCost(def, null);

            if (baseCost == 0)
            {
                return(null);
            }

            AnimalRecord result = new AnimalRecord();

            result.ThingDef = def;
            result.Gender   = gender;
            result.Cost     = baseCost;
            try {
                Pawn pawn = CreatePawn(def, gender);
                if (pawn == null)
                {
                    return(null);
                }
                else
                {
                    result.Thing = pawn;
                }
            }
            catch (Exception e) {
                Logger.Warning("Failed to create a pawn for animal database record: " + def.defName, e);
                return(null);
            }
            return(result);
        }
        protected EquipmentRecord CreateEquipmentEntry(ThingDef def, ThingDef stuffDef, Gender gender, EquipmentType type)
        {
            double baseCost = costs.GetBaseThingCost(def, stuffDef);

            if (baseCost == 0)
            {
                return(null);
            }
            int stackSize = CalculateStackCount(def, baseCost);

            EquipmentRecord result = new EquipmentRecord();

            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;
                try {
                    Pawn pawn = CreatePawn(def, stuffDef, gender);
                    if (pawn == null)
                    {
                        return(null);
                    }
                    else
                    {
                        result.thing = pawn;
                    }
                }
                catch (Exception e) {
                    Log.Warning("Prepare Carefully failed to create a pawn for animal equipment entry: " + def.defName);
                    Log.Message("  Exception message: " + e);
                    return(null);
                }
            }

            return(result);
        }
        protected EquipmentRecord CreateEquipmentRecord(ThingDef def, ThingDef stuffDef, EquipmentType type)
        {
            double baseCost = costs.GetBaseThingCost(def, stuffDef);

            if (baseCost == 0)
            {
                return(null);
            }
            int             stackSize = CalculateStackCount(def, baseCost);
            EquipmentRecord result    = new EquipmentRecord();

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

            return(result);
        }