コード例 #1
0
 public static void SetTechshardPrices()
 {
     foreach (ResearchProjectDef rpd in researchDic.Keys.ToList())
     {
         ThingDef shardDef = ShardMaker.ShardForProject(rpd);
         if (shardDef == null)
         {
             Log.Message("No techshard found for " + rpd.defName + " in SetTechshardPrices");
             continue;
         }
         var comp = shardDef.GetCompProperties <CompProperties_Techshard>();
         if (comp.project.techprintCount == 0 && !TechprintingSettings.printAllItems)
         {
             continue;
         }
         if (TechprintingSettings.profitableShards)
         {
             shardDef.SetStatBaseValue(StatDefOf.MarketValue, ShardMaker.SellValueOfOneShard(comp.project));
         }
         else
         {
             shardDef.SetStatBaseValue(StatDefOf.MarketValue, 0.01f);
         }
         shardDef.SetStatBaseValue(StatDefOf.SellPriceFactor, 1f);
     }
 }
コード例 #2
0
        public static IEnumerable <ThingDef> ImpliedTechshardDefs()
        {
            ResearchProjectHelper.AssociateAll();
            foreach (ResearchProjectDef researchProjectDef in DefDatabase <ResearchProjectDef> .AllDefsListForReading)
            {
                bool unlocks = ResearchProjectHelper.ProjectUnlocksShardable(researchProjectDef);
                if (ShardMaker.ShardForProject(researchProjectDef) == null && (researchProjectDef.techprintCount > 0 || unlocks))
                {
                    ThingDef thingDef = new ThingDef();
                    thingDef.category        = ThingCategory.Item;
                    thingDef.thingClass      = typeof(ThingWithComps);
                    thingDef.thingCategories = new List <ThingCategoryDef>();
                    thingDef.thingCategories.Add(Base.DefOf.DTechshards);
                    thingDef.useHitPoints = true;
                    thingDef.selectable   = true;
                    thingDef.SetStatBaseValue(StatDefOf.MaxHitPoints, 100f);
                    thingDef.SetStatBaseValue(StatDefOf.Flammability, 1f);
                    thingDef.SetStatBaseValue(StatDefOf.MarketValue, 0.01f);
                    thingDef.SetStatBaseValue(StatDefOf.Mass, 0.01f);
                    thingDef.SetStatBaseValue(StatDefOf.SellPriceFactor, 1f);
                    thingDef.altitudeLayer = AltitudeLayer.Item;
                    thingDef.comps.Add(new CompProperties_Forbiddable());
                    thingDef.comps.Add(new CompProperties_Techshard
                    {
                        project = researchProjectDef
                    });
                    thingDef.tickerType               = TickerType.Never;
                    thingDef.alwaysHaulable           = true;
                    thingDef.rotatable                = false;
                    thingDef.pathCost                 = 15;
                    thingDef.drawGUIOverlay           = true;
                    thingDef.stackLimit               = 100;
                    thingDef.modContentPack           = researchProjectDef.modContentPack;
                    thingDef.description              = "TechshardDesc".Translate(researchProjectDef.Named("PROJECT")) + "\n\n" + researchProjectDef.LabelCap + "\n\n" + researchProjectDef.description;
                    thingDef.graphicData              = new GraphicData();
                    thingDef.graphicData.texPath      = "Things/Item/Special/Techshard";
                    thingDef.graphicData.graphicClass = typeof(Graphic_StackCount);
                    thingDef.defName                 = "Techshard_" + researchProjectDef.defName;
                    thingDef.label                   = "TechshardLabel".Translate(researchProjectDef.Named("PROJECT"));
                    thingDef.smallVolume             = true;
                    thingDef.resourceReadoutPriority = ResourceCountPriority.Middle;
                    Base.DefOf.DTechshards.childThingDefs.Add(thingDef);

                    var giveShortHash = AccessTools.Method(typeof(ShortHashGiver), "GiveShortHash");
                    giveShortHash.Invoke(null, new object[] { thingDef, typeof(ThingDef) });
                    yield return(thingDef);
                }
            }
            yield break;
        }
コード例 #3
0
 public override bool CanPossiblyStoreInStockpile(Bill_Production bill, Zone_Stockpile stockpile)
 {
     foreach (ThingDef thingDef in bill.ingredientFilter.AllowedThingDefs)
     {
         ResearchProjectDef rpd;
         if (!Base.thingDic.TryGetValue(thingDef, out rpd))
         {
             return(false);
         }
         ThingDef shardDef = ShardMaker.ShardForProject(rpd);
         if (!stockpile.GetStoreSettings().AllowedToAccept(shardDef))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #4
0
        public static void RefundXP(ResearchProjectDef proj, Pawn applyingPawn, ResearchProjectDef shardType, int shardsApplied, float xpGained)
        {
            if (applyingPawn == null || !Base.researchDic.ContainsKey(shardType))
            {
                return;
            }
            float xpRequired = proj.baseCost - proj.ProgressReal;

            if (xpRequired >= 0)
            {
                int shardRefund = shardsApplied - Mathf.RoundToInt((float)shardsApplied * (xpRequired / xpGained));
                if (shardRefund > 0)
                {
                    ThingDef techShardDef = ShardMaker.ShardForProject(shardType);
                    Thing    shards       = ThingMaker.MakeThing(techShardDef);
                    shards.stackCount = shardRefund;
                    GenPlace.TryPlaceThing(shards, applyingPawn.Position, applyingPawn.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                }
            }
        }
コード例 #5
0
        public static void RefundUnlock(ResearchProjectDef proj, Pawn applyingPawn, int shardsApplied)
        {
            if (applyingPawn == null || !Base.researchDic.ContainsKey(proj))
            {
                return;
            }
            int shardsRequired = proj.techprintCount - Current.Game.researchManager.GetTechprints(proj);

            if (shardsRequired > 0)
            {
                int shardRefund = shardsApplied - shardsRequired;
                if (shardRefund > 0)
                {
                    ThingDef techShardDef = ShardMaker.ShardForProject(proj);
                    Thing    shards       = ThingMaker.MakeThing(techShardDef);
                    shards.stackCount = shardRefund;
                    GenPlace.TryPlaceThing(shards, applyingPawn.Position, applyingPawn.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                }
            }
        }
コード例 #6
0
        public static void MakeThingDictionaries()
        {
            thingDic    = new Dictionary <ThingDef, ResearchProjectDef>();
            researchDic = new Dictionary <ResearchProjectDef, List <ThingDef> >();

            foreach (RecipeDef recipe in DefDatabase <RecipeDef> .AllDefsListForReading)
            {
                ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForRecipe(recipe);
                if (rpd != null && recipe.ProducedThingDef != null)
                {
                    if (ShardMaker.ShardForProject(rpd) != null && (rpd.techprintCount > 0 || TechprintingSettings.printAllItems))
                    {
                        ThingDef producedThing = recipe.ProducedThingDef;
                        if (producedThing.GetCompProperties <CompProperties_Shardable>() == null)
                        {
                            producedThing.comps.Add(new CompProperties_Shardable());
                        }

                        thingDic.SetOrAdd(producedThing, rpd);

                        List <ThingDef> things;
                        if (researchDic.TryGetValue(rpd, out things))
                        {
                            things.Add(producedThing);
                        }
                        else
                        {
                            researchDic.Add(rpd, new List <ThingDef> {
                                producedThing
                            });
                        }
                    }
                }
            }

            if (TechprintingSettings.shardBuildings)
            {
                foreach (ThingDef building in DefDatabase <ThingDef> .AllDefs.Where(x => x.category == ThingCategory.Building || x.building != null))
                {
                    if (thingDic.ContainsKey(building))
                    {
                        continue;
                    }
                    ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForBuilding(building);
                    if (rpd != null)
                    {
                        if (ShardMaker.ShardForProject(rpd) != null && (rpd.techprintCount > 0 || TechprintingSettings.printAllItems))
                        {
                            if (building.GetCompProperties <CompProperties_Shardable>() == null)
                            {
                                building.comps.Add(new CompProperties_Shardable());
                            }

                            thingDic.SetOrAdd(building, rpd);

                            List <ThingDef> things;
                            if (researchDic.TryGetValue(rpd, out things))
                            {
                                things.Add(building);
                            }
                            else
                            {
                                researchDic.Add(rpd, new List <ThingDef> {
                                    building
                                });
                            }
                        }
                    }
                }
            }

            GearAssigner.HardAssign(ref thingDic, ref researchDic);
            GearAssigner.OverrideAssign(ref thingDic, ref researchDic);
        }