Repository reorganisation

Unified kotlin and java into just src/main
Unified the rs09 and core packages
Took all content out of the core package, and placed it into the new content package
Reorganised all source code relating to content to be easier to find and explore
This commit is contained in:
Ceikry
2023-01-26 13:59:28 +00:00
committed by Ryan
parent e4b799c44a
commit a100affda2
3156 changed files with 24205 additions and 30585 deletions
@@ -0,0 +1,94 @@
package content.data.tables;
import core.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 core.ServerConstants;
import core.tools.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 core.tools.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);}
}