Ejemplo n.º 1
0
        private ESItem[] GetWoolApparel(BiomeDef _biome, string _ApparelDefName, bool _LogCalculation)
        {
            // Variables
            bool boolLogCalculation = _LogCalculation;

            PawnKindDef[] aBiomeAnimals = new PawnKindDef[0];
            aBiomeAnimals = aBiomeAnimals.Concat(_biome.AllWildAnimals).ToArray();
            string strThingDef = _ApparelDefName;

            PawnKindDef[] aAllAnimals              = (from k in DefDatabase <PawnKindDef> .AllDefs where (k.RaceProps.Animal) select k).ToArray();
            PawnKindDef[] aWoolAnimals             = (from a in aAllAnimals where a.race.HasComp(typeof(CompShearable)) select a).ToArray();
            PawnKindDef[] aTameAnimals             = (from a in aAllAnimals where (a.race.race.wildness < .1f) select a).ToArray();
            PawnKindDef[] aTameWoolAnimals         = aWoolAnimals.Intersect(aTameAnimals).ToArray();
            PawnKindDef[] aBiomeWoolAnimals        = aBiomeAnimals.Intersect(aWoolAnimals).ToArray();
            PawnKindDef[] aBiomeAndTameWoolAnimals = aTameWoolAnimals.Union(aBiomeWoolAnimals).ToArray();
            PawnKindDef[] aAnimals = aBiomeAndTameWoolAnimals;
            ESItem[]      aESI     = new ESItem[aAnimals.Length];

            // Logging for variables
            if (boolLogCalculation == true)
            {
                string[] aStr = new string[] { "All tame animals: \n" };
                foreach (PawnKindDef pkd in aTameAnimals)
                {
                    aStr = aStr.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr));

                string[] aStr2 = new string[] { "All wool producing animals: \n" };
                foreach (PawnKindDef pkd in aWoolAnimals)
                {
                    aStr2 = aStr2.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr2));

                string[] aStr3 = new string[] { "All tame animals that produce wool: \n" };
                foreach (PawnKindDef pkd in aTameWoolAnimals)
                {
                    aStr3 = aStr3.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr3));

                string[] aStr4 = new string[] { "All animals that produce wool in this biome: \n" };
                foreach (PawnKindDef pkd in aBiomeWoolAnimals)
                {
                    aStr4 = aStr4.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr4));

                string[] aStr5 = new string[] { "All Tame and Biome wool producing animals: \n" };
                foreach (PawnKindDef pkd in aAnimals)
                {
                    aStr5 = aStr5.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr5));
            }

            // Variables for logging
            string strAnimalCommonality    = "";
            string strAnimalWool           = "";
            string strAnimalBodySize       = "";
            string strAnimalDanger         = "";
            string strAnimalwoolComonality = "";
            string strAnimalWMVF           = "";
            string strCostPerWool          = "";
            string strFinal = "";

            string[] aStrings = new string[0];

            // Start master loop for each wool producing animal in biome
            for (int i = 0; i < aAnimals.Count(); i++)
            {
                // variables
                int            intThingAmount = 1;
                float          floBasePrice   = 0f;
                string         strStuff;
                string         strAnimalName        = aAnimals[i].defName;
                float          floAnimalDPS         = 0f;
                float          floAnimalCommonality = 0f;
                string         strAnimalWoolDef     = aAnimals[i].race.GetCompProperties <CompProperties_Shearable>().woolDef.defName;
                StatModifier[] asmStatOffsets       = ThingDef.Named(strAnimalWoolDef).stuffProps.statOffsets.ToArray();
                StatModifier[] asmStatFactors       = ThingDef.Named(strAnimalWoolDef).stuffProps.statFactors.ToArray();
                (from a in aAllAnimals where a.race.HasComp(typeof(CompShearable)) select a).ToArray();

                // variables for tweeking
                // Scale opens price gaps
                float floHealthScale      = 1f;            // drives prices up
                float floDangerScale      = 1f;            // drives prices up
                float floCommonalityScale = 1f;            // drives prices down
                float floBodySizeScale    = 1f;            // drives prices down
                float floInsulationScale  = 6f;            // drives prices up

                // Floor closes price gaps
                float floHealthFloor      = .4f;
                float floDangerFloor      = 20f;
                float floCommonalityFloor = 1f;
                float floBodySizeFloor    = 1f;
                float floInsulationFloor  = 0f;

                float floPredatorScale = 4f;
                float floFarmScale     = 1.5f;
                float floTotalScale    = .05f;

                // Calc animal DPS
                if (!aAnimals[i].race.Verbs.NullOrEmpty <VerbProperties>())
                {
                    VerbProperties[] aVerbs = aAnimals[i].race.Verbs.ToArray();

                    for (int x = 0; x < aVerbs.Length; x++)
                    {
                        if ((float)aVerbs[x].meleeDamageBaseAmount > .001f)
                        {
                            floAnimalDPS += (float)aVerbs[x].meleeDamageBaseAmount / (aVerbs[x].defaultCooldownTime + aVerbs[x].warmupTime);
                        }
                    }

                    floAnimalDPS = floAnimalDPS / (float)aVerbs.Length;
                }

                // Calc animal danger with baseHealthScale scale and floor
                float floAnimalDanger = floAnimalDPS * aAnimals[i].race.GetStatValueAbstract(StatDefOf.MoveSpeed) * (aAnimals[i].race.race.baseHealthScale * floHealthScale + floHealthFloor);

                // Add danger scale and floor
                floAnimalDanger = floAnimalDanger * floDangerScale + floDangerFloor;

                // Calc animal commonality, multiply for predators and farm types
                if (aAnimals[i].race.race.predator == true)
                {
                    floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floPredatorScale * floCommonalityScale * _biome.animalDensity;
                }
                else if (aTameAnimals.Contains(aAnimals[i]))
                {
                    floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floFarmScale * floCommonalityScale * _biome.animalDensity;
                    floAnimalDanger     /= floFarmScale;
                }
                else
                {
                    floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floCommonalityScale * _biome.animalDensity;
                }

                // Add animal commonality scale and floor
                floAnimalCommonality += floCommonalityFloor;

                // Calc animal Wool commonality with baseBodySize scale and floor
                float floAnimalWoolCommonality = (floAnimalCommonality * ((aAnimals[i].race.race.baseBodySize * 3f) * floBodySizeScale + floBodySizeFloor)) / floAnimalDanger;

                // Calc total statOffsets
                float floStatOffsetsTotal = 0f;
                foreach (StatModifier sm in asmStatOffsets)
                {
                    floStatOffsetsTotal += sm.value;
                }

                // Calc total statFactors
                float floStatFactorsTotal = 0f;
                foreach (StatModifier sf in asmStatFactors)
                {
                    floStatFactorsTotal += (sf.value * .75f);
                }

                //Add woolInsulation scale and floor
                floBasePrice = ((floStatFactorsTotal * floInsulationScale + floInsulationFloor) + floStatOffsetsTotal) / floAnimalWoolCommonality;

                // Logging part 1
                if (boolLogCalculation)
                {
                    strAnimalCommonality    = string.Concat("Commonality of ", aAnimals[i].ToString(), " * Animal Density: ", floAnimalCommonality.ToString(), "\n");
                    strAnimalWool           = string.Concat(aAnimals[i].race.race.leatherDef.ToString(), ", statFactors: ", floStatFactorsTotal.ToString(), "\n");
                    strAnimalBodySize       = string.Concat("BodySize: ", aAnimals[i].race.race.baseBodySize.ToString(), "\n");
                    strAnimalDanger         = string.Concat("AnimalDPS * AnimalMoveSpeed * AnimalBaseHealthScale = Danger: ", floAnimalDanger.ToString(), "\n");
                    strAnimalwoolComonality = string.Concat("Animal Commonality * BodySize / Danger = woolCommonality: ", floAnimalWoolCommonality.ToString(), "\n");
                    strAnimalWMVF           = string.Concat("woolMarketValueFactor: ", aAnimals[i].race.race.leatherMarketValueFactor.ToString(), "\n");
                    strCostPerWool          = string.Concat("statFactors / woolCommonality = Cost per leather: ");
                }

                // Add total scale
                floBasePrice *= floTotalScale;

                // Calc ThingDef string for Stuff, calc wool needed for apparel
                strStuff = strAnimalWoolDef;
                float floFinalCost = (float)ThingDef.Named(strThingDef).costStuffCount *floBasePrice;

                // Populate ESItem list for return
                aESI[i] = new ESItem(strThingDef, intThingAmount, floFinalCost, 1, strStuff);

                // Logging part 2
                if (boolLogCalculation)
                {
                    strFinal = string.Concat(aAnimals[i].ToString(), " FINAL: ", floBasePrice.ToString(), "\n", strThingDef, ": ", floFinalCost.ToString());
                    aStrings = new string[] { strAnimalCommonality, strAnimalWool, strAnimalBodySize, strAnimalDanger, strAnimalwoolComonality, strAnimalWMVF, strCostPerWool, strFinal };
                    Log.Message(string.Concat(aStrings));
                }
            }

            return(aESI);
        }