RuneHive-Game
Loading...
Searching...
No Matches
NpcDrop.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.mob.npc.drop;
2
3import com.google.gson.annotations.SerializedName;
4import com.runehive.game.world.items.Item;
5import com.runehive.util.RandomGen;
6
7public final class NpcDrop implements Comparable<NpcDrop> {
8 /** The item id of this drop. */
9 @SerializedName(value="id", alternate={"item"})
10 public int id;
11 /** The chance this item is dropped. */
13
14 public int getWeight() {
15 return type.weight;
16 }
17
18 /** The alternate chance modifier to use over the {@code chance} rarity. */
19 public final int chance;
20
21 /** The minimum amount of this drop. */
22 public final int minimum;
23
24 /** The maximum amount of this drop. */
25 public final int maximum;
26
27 /** Constructs a new {@link NpcDrop}. */
28 public NpcDrop(int id, NpcDropChance type, int chance, int minimum, int maximum) {
29 this.id = id;
30 this.type = type;
31 this.chance = chance;
32 this.minimum = minimum;
33 this.maximum = maximum;
34 }
35
36 /** Converts this {@link NpcDrop} to an item. */
37 public Item toItem(RandomGen gen) {
38 return new Item(id, gen.inclusive(minimum, maximum));
39 }
40
41 public void setId(int id) {
42 this.id = id;
43 }
44
45 public void setType(NpcDropChance type) {
46 this.type = type;
47 }
48
49 @Override
50 public int compareTo(NpcDrop other) {
51 return type.ordinal() - other.type.ordinal();
52 }
53}
final int maximum
The maximum amount of this drop.
Definition NpcDrop.java:25
NpcDropChance type
The chance this item is dropped.
Definition NpcDrop.java:12
NpcDrop(int id, NpcDropChance type, int chance, int minimum, int maximum)
Constructs a new NpcDrop.
Definition NpcDrop.java:28
final int chance
The alternate chance modifier to use over the chance rarity.
Definition NpcDrop.java:19
final int minimum
The minimum amount of this drop.
Definition NpcDrop.java:22
Item toItem(RandomGen gen)
Converts this NpcDrop to an item.
Definition NpcDrop.java:37
The container class that represents an item that can be interacted with.
Definition Item.java:21
The ThreadLocalRandom wrapper that provides additional functionality for generating pseudo-random num...
int inclusive(int min, int max)
Returns a pseudo-random int value between inclusive min and inclusive max.
The enumerated type whose elements represent a set of constants used to differ between NpcDrop rariti...