Added an Allotment Seed drop table

Reworked Farmer drop table
This commit is contained in:
Von Hresvelg
2022-12-17 07:40:18 +00:00
committed by Ryan
parent 00d460d2ba
commit e8ea397b6b
10 changed files with 190 additions and 141 deletions
@@ -0,0 +1,94 @@
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 allotment seed drop table.
* @author Von Hresvelg
*/
public final class AllotmentSeedDropTable implements StartupListener {
/**
* The item id of the item representing the allotment seed drop table slot in a drop
* table.
*/
public static final int SLOT_ITEM_ID = 14430;
/**
* The allotment 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 AllotmentSeedDropTable() throws ParserConfigurationException {}
@Override
public void startup() {
if(ServerConstants.ASDT_DATA_PATH != null && !new File(ServerConstants.ASDT_DATA_PATH).exists()){
SystemLogger.logErr(this.getClass(), "Can't locate ASDT file at " + ServerConstants.ASDT_DATA_PATH);
return;
}
parse(ServerConstants.ASDT_DATA_PATH);
logInfo(this.getClass(), "Initialized Allotment Seed Drop Table from " + ServerConstants.ASDT_DATA_PATH);
}
/**
* Parses the xml file for the allotment seed drop table.
* @param file the .xml file containing the allotment 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);}
}
@@ -104,6 +104,9 @@ public final class NPCDropTables {
if (item.getId() == RareSeedDropTable.SLOT_ITEM_ID){
item = RareSeedDropTable.retrieve();
}
if (item.getId() == AllotmentSeedDropTable.SLOT_ITEM_ID){
item = AllotmentSeedDropTable.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);
@@ -86,6 +86,9 @@ class ServerConstants {
@JvmField
var RSDT_DATA_PATH: String? = null
@JvmField
var ASDT_DATA_PATH: String? = null
//the max number of players.
@JvmField
var MAX_PLAYERS = 2000
@@ -9,6 +9,7 @@ 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.npc.drop.AllotmentSeedDropTable
import core.game.node.entity.player.Player
import core.game.node.item.Item
import core.tools.RandomFunction
@@ -61,6 +62,7 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
SLOT_HDT -> HerbDropTable.retrieve()
SLOT_GDT -> GemDropTable.retrieve()
SLOT_RSDT -> RareSeedDropTable.retrieve()
SLOT_ASDT -> AllotmentSeedDropTable.retrieve()
else -> e.getItem()
}
safeItems.add(safeItem)
@@ -118,6 +120,11 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
return this
}
fun insertASDTRoll(weight: Double): WeightBasedTable{
this.add(WeightedItem(SLOT_ASDT,1,1,weight,false))
return this
}
companion object {
@JvmStatic
fun create(vararg items: WeightedItem): WeightBasedTable{
@@ -138,6 +145,7 @@ open class WeightBasedTable : ArrayList<WeightedItem>() {
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
val SLOT_ASDT = Items.SACRED_CLAY_POUCH_CLASS_5_14430
}
override fun toString(): String {
@@ -115,6 +115,7 @@ object ServerConfigParser {
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.ASDT_DATA_PATH = data.getPath("paths.allotment_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)
+2
View File
@@ -73,6 +73,8 @@ herb_drop_table_path = "@data/configs/shared_tables/HDT.xml"
gem_drop_table_path = "@data/configs/shared_tables/GDT.xml"
#path to file defining the rare seed drop table
rare_seed_drop_table_path = "@data/configs/shared_tables/RSDT.xml"
#path to file defining the allotment seed drop table
allotment_seed_drop_table_path = "@data/configs/shared_tables/ASDT.xml"
#path to file containing boot-time object changes
object_parser_path = "@data/ObjectParser.xml"
#path logs are written to