cool
|
I'm posting this for 2 reasons:
1 - if anyone is interested to see how this is handled and if they could apply it to themselves, or learn the infrastructure of loot spawns on a good zombie sever.
2 - if anyone could give me some advice/tips on any ways I could handle it better
*posting this in tutorial section because I think I'm 'teaching' people the logic behind this code rather than just copy-paste which is what Snippets is for.*
So, what this does is hold the information for each specific item that has the ability to be spawned within this certain loot category. In this example the loot category that we are dealing with is Low Supplies. The Low means the given severity, or sub-category, within the main category, which in this case is Supplies (the other three categories are equipment, weapons, and armor). Then, within the subcategory we have a subsubcategory (we're gettin deep ) that specifies it even further, but the uncommon loot isn't technically better or worse than common, it's just that those specific uncommon items I've chosen don't 100% fit under the specific main category I've chosen, but may share some characteristics. By using this system I have allowed my self to create a more realistic environment (for example, this essentially means you wont always find exactly food in the same spot, but if it's a good environment for food, like say, a house, then there is a BETTER chance for food to be there than say a blacksmith's shop). Hopefully this isn't too far over anyone's heads. Also trash loot is just junk, to create, once again, a more realistic environment.
This class also holds within it the capabilities of randomly selecting a value from the specific subsubcategory enum, when called upon by the main spawning class. When the main class calls upon these subcategory classes it'll randomly decide if it wants a common, uncommon, or trash. Then, depending on which subsubcategory it has chosen, it will randomly pick an item from the specific enum, and return it to the main spawning class. If you can't tell by the code, trash loot has a 10% chance of being selected, uncommon has a 20% chance, and common has a 70% chance of being spawned.
Code:package com.rs.utils.spawning.itemspawning.Supplies; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; import com.rs.game.item.Item; public class LowSupplies { public enum Common { TUNA(361, 1), TROUT(333, 1), RAW_LOBSTER(377, 1), RAW_MEAT(2132, 1), RAW_CHICKEN( 2138, 1), POTATO(1942, 1), CABBAGE(1965, 1), WATER_BOTTLE(6953, 1), EMPTY_WATER_BOTTLE(3377, 1), SALMON(329, 1), RAW_TUNA(359, 1), BANANA(1963, 1), JUG_OF_WATER(1937, 1), BUCKET(1925, 1), REDBERRY_PIE( 2325, 1), BANDAGE(4049, 1), COOKED_RABBIT(3228, 1), MEAT_PIZZA( 2293, 1), ANCHOVY_PIZZA_HALF(2299, 1); /** * The specific item ID */ private int itemId; /** * Amount of item being spawned. */ private int amount; private Common(int itemId, int amount) { this.itemId = itemId; this.amount = amount; } public int getItemId() { return itemId; } public int getAmount() { return amount; } private static final List<Common> VALUES = Collections .unmodifiableList(Arrays.asList(values())); private static final int SIZE = VALUES.size(); private static final Random RANDOM = new Random(); public static Common randomCommon() { return VALUES.get(RANDOM.nextInt(SIZE)); } } public enum Uncommon { KNIFE(5605, 1), SMALL_FISHING_NET(6209, 1), PLANK(960, 1), IRON_NAILS( 4820, 25), STEEL_CHAIN(1105, 1), STEEL_SWORD(1281, 1), IRON_PICKAXE( 1267, 1); /** * The specific item ID */ private int itemId; /** * Amount of item being spawned. */ private int amount; private Uncommon(int itemId, int amount) { this.itemId = itemId; this.amount = amount; } public int getItemId() { return itemId; } public int getAmount() { return amount; } private static final List<Uncommon> VALUES = Collections .unmodifiableList(Arrays.asList(values())); private static final int SIZE = VALUES.size(); private static final Random RANDOM = new Random(); public static Uncommon randomUncommon() { return VALUES.get(RANDOM.nextInt(SIZE)); } } public enum Trash { BROKEN_ARROW(687, 1), RUSTY_SWORD(686, 1), OLD_BOOT(685, 1), CAKE_TIN( 1887, 1), BEER_GLASS(1919, 1); /** * The specific item ID */ private int itemId; /** * Amount of item being spawned. */ private int amount; private Trash(int itemId, int amount) { this.itemId = itemId; this.amount = amount; } public int getItemId() { return itemId; } public int getAmount() { return amount; } private static final List<Trash> VALUES = Collections .unmodifiableList(Arrays.asList(values())); private static final int SIZE = VALUES.size(); private static final Random RANDOM = new Random(); public static Trash randomTrash() { return VALUES.get(RANDOM.nextInt(SIZE)); } } public Item returnItem() { Random rand = new Random(); int randomNum = rand.nextInt((10 - 1) + 1) + 1; if (randomNum > 3) return new Item(Common.randomCommon().getItemId(), Common .randomCommon().getAmount()); else if (randomNum > 1) return new Item(Uncommon.randomUncommon().getItemId(), Uncommon .randomUncommon().getAmount()); else return new Item(Trash.randomTrash().getItemId(), Trash .randomTrash().getAmount()); } }
cool
Thanks for contributing mate
Could all be in one enumeration with the 'type' being defined as part of the parameter. Also, you could change the constructor to not take in the amount, on which it would default to 1
25 minutes for now, but that's subject to change. It depends what different approaches I take. I can either do more loot spawn locations, but a lower respawn rate, or less loot spawn locations but a quicker respawn rate. I haven't quite decided yet.
I have switched this whole system to importing from external files. I haven't really noticed much of a difference either than adding items being easier. And thanks to Kaleem's idea I don't need to enter an amount if that item I want is just an amount of 1
Good idea, but I would have no use to implement it.
Like said above, create a enum with types (common, uncommon, trash) and create one main enum with all the items. If you know that your going to end up with a large enum you might aswell create a XML/Json config for it.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |