A Saner Loot Spawn System (SRC)
0

6 posts in this topic

Recommended Posts

The current* loot system has a very rough feel to it, in that you have very random assortments of objects in a given "room" container. As in a kitchen cabinet might have a spoon, a bag of flour, and a hammer in it. I don't know what sorts of kitchens TIS has at home, but it makes me very concerned for them lol

 

I propose a saner loot system with sub-room categories (SRC), like "dishes cabinet" and "food cabinet", even down to the level of "baking cabinet" if we want to go crazy with it. It's all just a few lines of code, so why not?

 

Currently, I believe, when you spawn a room, it randomly assigns objects from a "room list" to each cabinet, based on weightings and roll chances. But that's it, every container gets spawned with the same random crap. Hence spoon, flour, hammer.

 

Instead, when a room is spawned, it should:

Step 1: get a list of these real-world containers

Step 2: check the room type, then make a list of the appropriate SRC, grabbed from an XML file

Step 3: (optional) some of the SRCs should be "mandatory", in that they will all spawn first at least once before going full-random. This way we don't have kitchens with 20 utensil drawers and no actual food, just because the RNG can be crazy some times.

Step 4: for each container, randomly choose an SRC type, then fill it with the loot contained within that SRC file (loot generation as it currently is in-game)

 

SRC types would include weightings (so a kitchen might have a 20% chance of food, 10% chance of utensils, 20% chance of dishes, 5% chance of pet food, whatever), and then each type also has a list of loot, weighted also (so "utensils" would be 20% spoons, 20% forks, etc).

 

Here's my very hackish and definitely-not-functional attempt at coding it.

 

Spoiler

 


import java.util.ArrayList;

public class IndieSampleCode {

    public void spawnRoomLoot(Room RoomBeingSpawned) { //whatver the method is called currently, uses the specific and entire room being initiated/spawned as the parameter


        String roomType = RoomBeingSpawned.getType();                                       //  method returns the type of room that is being spawned
        ArrayList<Container> containers = RoomBeingSpawned.getContainersArray();            //  not sure how it's done currently, but I'm assuming each specific room has a list of loot containers in it
        int numberContainers = containers.size();
        ArrayList<ContainerArchetype> archetypes = new ArrayList<ContainerArchetypes>();   //  this class is the new thing I'm proposing, the predefined "drawer type". It contains a few fields, detailed below

        switch (roomType) {
            case "kitchen":
                /*code that adds all entries into this arraylist from the XML file below, see SAMPLE ARCHETYPE XML below, as class ContainerArchetype, with fields for name, weight, size, and arrays of objects with type and weight */
                break;
            case "bedroom":
                /*same for bedrooms*/
                break;

                //etc, etc
        }

        int numberOfNecessaryContainers= 0;                                                    //  an optional thing, any container with weight >= 100 is a "must spawn", so if a room has a limited number of containers, these get spawned first. Allows for more niche/"exotic" container types to be used in larger rooms, and so we don't have kitchens that randomly get all utensil drawers or some weirdness like that
        ArrayList<ContainerArchetypes> necessaryContainers = new ArrayList<ContainerArchetypes>();
        for (int i=0; i<archetypes.size();i++) {
            if (archetypes.get(i).getWeight() >= 100) {
                numberOfNecessaryContainers++;
                necessaryContainers.add(archetypes.get(i));
            }
        }

                                                                                                //  code goes through and fills in every container in the room, first starting with "must-haves" and once that list is exhausted, doing a totally random selection of all archetypes for remaining containers
        for(int i=0; i<numberContainers;i++) {
            for (int j=0;j<numberOfNecessaryContainers;j++) {                                   //  the optional "must spawn" for loop
                if (i>=numberContainers)
                    break;
                int pos = this.addLoots(containers.get(i), necessaryContainers, this.randomSelect(necessaryContainers));
                necessaryContainers.remove(pos);                                                //  removed so it is not selected again, so all necessary containers can be spawned first. it still exists in the full archetypes list, so it can be spawned again once this process is over
                numberContainers--;
            }
            this.addLoots(containers.get(i), this.randomSelect(archetypes));
        }
    }

    public ContainerArchetype randomSelect(ArrayList<ContainerArchetype> archetype) {
        /* code that randomly chooses an archetype based on weightings, then returns the position in the arraylist */
    }

    public int addLoots(ArrayList<Container> container, ArrayList<ContainerArchetypes> archetype, int pos) {
        /* code that does basically what the current in-game code does: adds random loots to room container from archetype #pos's list in XML below.
        /* code returns the int pos passed in parameters */
    }
}



// SAMPLE ARCHETYPE XML (very simplified)

roomType Kitchen {

        //   NAME       ODDS/WEIGHT  SLOTS
        containerType1="utensils",100,20;
        containerType2="dishes",100,20;
        containerType3="cookwear",75,5;
        containerType4="baking supplies",50,5;
        containerType5="foods",150,10;
        containerType6="household",25,10;
}

objectList utensils {
    spoon, 1;  // loot type and weight
    fork, 1;
    butter knife, 1;
    kitchen knife, 0.5;
}

//etc

 

 

This just bothered me so much while playing. I suppose I can mod it in later if you guys don't include it, but I'd rather not, and the as-is system really feels like an "alpha feature" that should be updated for 1.0.

 

*(note that I haven't played for a few releases, as I've been on a gaming hiatus, but I assume this is still the case, and if I'm wrong well I've wasted 30min but at least I'm happy that it's fixed :) )

Edited by Talksintext

Share this post


Link to post
Share on other sites

I might mod it in down the road. I know from doing previous loot mods that the system is mostly moddable. I'm not sure if there's a way to edit the main code so you can take all the containers in a room at once, which is required for such a mod. I never got that into the weeds on modding this game.

 

If the code works like: [i have a new room spawned],[for each singular container run a loot gen script] then it might be hard to do.

I need: [i have a new room spawned],[here's a list of all the containers],[take the entire list and run a loot gen script]

 

I would guess it's possible. I don't know. I don't have the game files on my system any more.

Share this post


Link to post
Share on other sites

Yessss do it. Do it. Do it.

 

Quote

He’s also experimenting with having more specific containers in homes for more specific items (all the cutlery in one drawer, male clothes in one wardrobe, female in another etc) but the jury is currently out on whether it actually detracts from the looting gameplay.

It doesn't. Do it.

Share this post


Link to post
Share on other sites

I remeber of reading about this in a News. And i just found it.

Quote
  • RJ has been tinkering with in-game loot, and has occasionally been popping into the PZ Discord to look for willing testers. The overall plan is to have more information in the game code in terms of what’s a desirable item, and what’s junk – so we can then fill containers with a lot more realistic junk items even on higher difficulty levels. He’s also experimenting with having more specific containers in homes for more specific items (all the cutlery in one drawer, male clothes in one wardrobe, female in another etc) but the jury is currently out on whether it actually detracts from the looting gameplay.

 

This in written down in this NEWS: https://projectzomboid.com/blog/2018/12/zedlocation/

Share this post


Link to post
Share on other sites
0