Random recipe outcome

Started by NavySeal566, June 20, 2017, 05:03:55 PM

Previous topic - Next topic

NavySeal566

Is it possible to get a recipe with fixed ingredients to give me one out of x items?
I guess it could work with C# but i have no idea how to add functions to the xml part

Xnope

Having worked with some of the functions you'd be dealing with in C#, I think what you seek is certainly possible, however I'm pretty sure it would take a lot of source drilling to figure out the whole process a Thing goes through to be crafted.

I think it might work to write a ThingComp that randomly selects from a list of possible Defs to change its parent ThingWithComps's def to, directly after it is crafted. I know it somewhat works to change a Thing's def at runtime, and most of its properties get switched over. You may need to be mindful of re-assigning all of the Thing's fields with respect to the new def, though.

If you write this ThingComp, you would then add it to your custom ThingDef that is basically just a dummy wrapper with a <recipeMaker> and a <costList> (or any variation of <stuffCategories> + <costStuffCount> + <costList>), and give it an invisible 1-pixel graphic until the dynamically re-assigned ThingDef's graphic takes over pretty much the next frame.

Hope this gives you an idea. Bear in mind this is just my perspective and not the only way you could accomplish what you want.
My W.I.P. mods:
Carnivale: GitHub | Forum Post
XnopeCore: GitHub

jamaicancastle

The code linked in this thread may be what you're looking for. Never worked with it myself, but it seems to be the same basic idea.