Moved drop tables into dedicated folder (data/config/shared_tables)

Added Rare Seed Drop Table
Reworked Aberrant Spectre drops
This commit is contained in:
Von Hresvelg
2022-11-16 08:16:22 +00:00
committed by Ryan
parent 9145fd038c
commit aa935855c9
17 changed files with 223 additions and 214 deletions
@@ -56,12 +56,12 @@ public final class HerbDropTable implements StartupListener {
@Override
public void startup() {
if(ServerConstants.HERBDT_DATA_PATH != null && !new File(ServerConstants.HERBDT_DATA_PATH).exists()){
SystemLogger.logErr(this.getClass(), "Can't locate HERBDT file at " + ServerConstants.HERBDT_DATA_PATH);
if(ServerConstants.HDT_DATA_PATH != null && !new File(ServerConstants.HDT_DATA_PATH).exists()){
SystemLogger.logErr(this.getClass(), "Can't locate HDT file at " + ServerConstants.HDT_DATA_PATH);
return;
}
parse(ServerConstants.HERBDT_DATA_PATH);
logInfo(this.getClass(), "Initialized Herb Drop Table from " + ServerConstants.HERBDT_DATA_PATH);
parse(ServerConstants.HDT_DATA_PATH);
logInfo(this.getClass(), "Initialized Herb Drop Table from " + ServerConstants.HDT_DATA_PATH);
}
/**
@@ -101,6 +101,9 @@ public final class NPCDropTables {
if (item.getId() == GemDropTable.SLOT_ITEM_ID){
item = GemDropTable.retrieve();
}
if (item.getId() == RareSeedDropTable.SLOT_ITEM_ID){
item = RareSeedDropTable.retrieve();
}
if (item.getId() == 995 && player.getBank().hasSpaceFor(item) && ( player.getGlobalData().isEnableCoinMachine() )) {
item = new Item(995, (int) (item.getAmount() + (item.getAmount() * 0.25)));
player.getBank().add(item);
@@ -0,0 +1,96 @@
package core.game.node.entity.npc.drop;
import api.StartupListener;
import core.game.node.item.Item;
import core.game.node.item.WeightedChanceItem;
import core.tools.RandomFunction;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import rs09.ServerConstants;
import rs09.game.system.SystemLogger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static rs09.game.system.SystemLogger.logInfo;
/**
* Handles the rare seed drop table.
* @author Von Hresvelg
*/
public final class RareSeedDropTable implements StartupListener {
/**
* The item id of the item representing the rare seed drop table slot in a drop
* table.
*/
public static final int SLOT_ITEM_ID = 14428;
/**
* The rare seed drop table.
*/
private static final List<WeightedChanceItem> TABLE = new ArrayList<>(20);
/**
* Initialize needed objects for xml reading/writing
*/
static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
static DocumentBuilder builder;
static {
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
public RareSeedDropTable() throws ParserConfigurationException {}
@Override
public void startup() {
if(ServerConstants.RSDT_DATA_PATH != null && !new File(ServerConstants.RSDT_DATA_PATH).exists()){
SystemLogger.logErr(this.getClass(), "Can't locate RSDT file at " + ServerConstants.RSDT_DATA_PATH);
return;
}
parse(ServerConstants.RSDT_DATA_PATH);
logInfo(this.getClass(), "Initialized Rare Seed Drop Table from " + ServerConstants.RSDT_DATA_PATH);
}
/**
* Parses the xml file for the rare seed drop table.
* @param file the .xml file containing the rare seed drop table.
*/
public static void parse(String file){
try {
Document doc = builder.parse(file);
NodeList itemNodes = doc.getElementsByTagName("item");
for(int i = 0; i < itemNodes.getLength(); i++){
Node itemNode = itemNodes.item(i);
if(itemNode.getNodeType() == Node.ELEMENT_NODE){
Element item = (Element) itemNode;
int itemId = Integer.parseInt(item.getAttribute("id"));
int minAmt = Integer.parseInt(item.getAttribute("minAmt"));
int maxAmt = Integer.parseInt(item.getAttribute("maxAmt"));
int weight = Integer.parseInt(item.getAttribute("weight"));
TABLE.add(new WeightedChanceItem(itemId,minAmt,maxAmt,weight));
}
}
} catch (Exception e){
e.printStackTrace();
}
}
public static Item retrieve(){
return RandomFunction.rollWeightedChanceTable(TABLE);
}
}
@@ -21,19 +21,19 @@ import java.util.List;
import static rs09.game.system.SystemLogger.logInfo;
/**
* Handles the seed drop table.
* Handles the uncommon seed drop table.
* @author Von Hresvelg
*/
public final class UncommonSeedDropTable implements StartupListener {
/**
* The item id of the item representing the seed drop table slot in a drop
* The item id of the item representing the uncommon seed drop table slot in a drop
* table.
*/
public static final int SLOT_ITEM_ID = 14422;
/**
* The seed drop table.
* The uncommon seed drop table.
*/
private static final List<WeightedChanceItem> TABLE = new ArrayList<>(20);
@@ -56,17 +56,17 @@ public final class UncommonSeedDropTable implements StartupListener {
@Override
public void startup() {
if(ServerConstants.SEEDDT_DATA_PATH != null && !new File(ServerConstants.SEEDDT_DATA_PATH).exists()){
SystemLogger.logErr(this.getClass(), "Can't locate SEEDDT file at " + ServerConstants.SEEDDT_DATA_PATH);
if(ServerConstants.USDT_DATA_PATH != null && !new File(ServerConstants.USDT_DATA_PATH).exists()){
SystemLogger.logErr(this.getClass(), "Can't locate USDT file at " + ServerConstants.USDT_DATA_PATH);
return;
}
parse(ServerConstants.SEEDDT_DATA_PATH);
logInfo(this.getClass(), "Initialized Uncommon Seed Drop Table from " + ServerConstants.SEEDDT_DATA_PATH);
parse(ServerConstants.USDT_DATA_PATH);
logInfo(this.getClass(), "Initialized Uncommon Seed Drop Table from " + ServerConstants.USDT_DATA_PATH);
}
/**
* Parses the xml file for the seed drop table.
* @param file the .xml file containing the seed drop table.
* Parses the xml file for the uncommon seed drop table.
* @param file the .xml file containing the uncommon seed drop table.
*/
public static void parse(String file){
try {
@@ -75,14 +75,17 @@ class ServerConstants {
var CELEDT_DATA_PATH: String? = null
@JvmField
var SEEDDT_DATA_PATH: String? = null
var USDT_DATA_PATH: String? = null
@JvmField
var HERBDT_DATA_PATH: String? = null
var HDT_DATA_PATH: String? = null
@JvmField
var GDT_DATA_PATH: String? = null
@JvmField
var RSDT_DATA_PATH: String? = null
//the max number of players.
@JvmField
var MAX_PLAYERS = 2000
@@ -8,6 +8,7 @@ import core.game.node.entity.npc.drop.CELEMinorTable
import core.game.node.entity.npc.drop.UncommonSeedDropTable
import core.game.node.entity.npc.drop.HerbDropTable
import core.game.node.entity.npc.drop.GemDropTable
import core.game.node.entity.npc.drop.RareSeedDropTable
import core.game.node.entity.player.Player
import core.game.node.item.Item
import core.tools.RandomFunction
@@ -56,9 +57,10 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
SLOT_CLUE_HARD -> ClueScrollPlugin.getClue(ClueLevel.HARD)
SLOT_RDT -> RareDropTable.retrieve()
SLOT_CELEDT -> CELEMinorTable.retrieve()
SLOT_SEEDDT -> UncommonSeedDropTable.retrieve()
SLOT_HERBDT -> HerbDropTable.retrieve()
SLOT_USDT -> UncommonSeedDropTable.retrieve()
SLOT_HDT -> HerbDropTable.retrieve()
SLOT_GDT -> GemDropTable.retrieve()
SLOT_RSDT -> RareSeedDropTable.retrieve()
else -> e.getItem()
}
safeItems.add(safeItem)
@@ -97,12 +99,12 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
}
fun insertSEEDDTRoll(weight: Double): WeightBasedTable{
this.add(WeightedItem(SLOT_SEEDDT,1,1,weight,false))
this.add(WeightedItem(SLOT_USDT,1,1,weight,false))
return this
}
fun insertHERBDTRoll(weight: Double): WeightBasedTable{
this.add(WeightedItem(SLOT_HERBDT,1,1,weight,false))
this.add(WeightedItem(SLOT_HDT,1,1,weight,false))
return this
}
@@ -111,6 +113,11 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
return this
}
fun insertRSDTRoll(weight: Double): WeightBasedTable{
this.add(WeightedItem(SLOT_RSDT,1,1,weight,false))
return this
}
companion object {
@JvmStatic
fun create(vararg items: WeightedItem): WeightBasedTable{
@@ -127,9 +134,10 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
val SLOT_CLUE_MEDIUM = Items.ROTTEN_POTATO_5733
val SLOT_CLUE_HARD = Items.GRANITE_LOBSTER_POUCH_12070
val SLOT_CELEDT = Items.NULL_799
val SLOT_SEEDDT = Items.SACRED_CLAY_POUCH_CLASS_1_14422
val SLOT_HERBDT = Items.SACRED_CLAY_POUCH_CLASS_2_14424
val SLOT_USDT = Items.SACRED_CLAY_POUCH_CLASS_1_14422
val SLOT_HDT = Items.SACRED_CLAY_POUCH_CLASS_2_14424
val SLOT_GDT = Items.SACRED_CLAY_POUCH_CLASS_3_14426
val SLOT_RSDT = Items.SACRED_CLAY_POUCH_CLASS_4_14428
}
override fun toString(): String {
@@ -110,9 +110,10 @@ object ServerConfigParser {
ServerConstants.LOG_CUTSCENE = data.getBoolean("world.verbose_cutscene", false)
ServerConstants.GRAND_EXCHANGE_DATA_PATH = data.getPath("paths.eco_data")
ServerConstants.CELEDT_DATA_PATH = data.getPath("paths.cele_drop_table_path")
ServerConstants.SEEDDT_DATA_PATH = data.getPath("paths.seed_drop_table_path")
ServerConstants.HERBDT_DATA_PATH = data.getPath("paths.herb_drop_table_path")
ServerConstants.USDT_DATA_PATH = data.getPath("paths.uncommon_seed_drop_table_path")
ServerConstants.HDT_DATA_PATH = data.getPath("paths.herb_drop_table_path")
ServerConstants.GDT_DATA_PATH = data.getPath("paths.gem_drop_table_path")
ServerConstants.RSDT_DATA_PATH = data.getPath("paths.rare_seed_drop_table_path")
ServerConstants.SERVER_GE_NAME = data.getString("world.name_ge") ?: ServerConstants.SERVER_NAME
ServerConstants.RULES_AND_INFO_ENABLED = data.getBoolean("world.show_rules", true)
ServerConstants.BOTS_INFLUENCE_PRICE_INDEX = data.getBoolean("world.bots_influence_ge_price", true)