Files
lakebane/src/engine/objects/ItemBase.java
T

308 lines
8.8 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
2024-02-07 19:20:29 -06:00
import engine.Enum;
2022-04-30 09:41:17 -04:00
import engine.Enum.ItemType;
import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
public class ItemBase {
2023-07-15 09:23:48 -04:00
public static ItemBase GOLD_ITEM_BASE = null;
public static int GOLD_BASE_ID = 7;
public static ArrayList<Integer> AnniversaryGifts = new ArrayList<>();
2023-07-15 09:23:48 -04:00
public static HashMap<Integer, ItemBase> _itemBaseByUUID = new HashMap<>();
2024-02-14 12:29:42 -05:00
private static final HashMap<Integer, Integer> itemHashIDMap = new HashMap<>();
private static final HashMap<String, Integer> _IDsByNames = new HashMap<>();
private static final ArrayList<ItemBase> _resourceList = new ArrayList<>();
2024-03-10 07:32:30 -04:00
public final int uuid;
2024-02-14 12:29:42 -05:00
private final int modTable;
private final int useID;
2023-07-15 09:23:48 -04:00
private int hashID;
2024-02-14 12:29:42 -05:00
private final byte useAmount;
2024-03-09 11:26:19 -05:00
2023-07-15 09:23:48 -04:00
// Armor and weapon related values
2024-02-14 12:29:42 -05:00
private final String skillRequired;
private final short percentRequired;
private final short defense;
private final float dexPenalty;
private final float speed;
private final float range;
private final short minDamage;
private final short maxDamage;
private final String mastery;
2024-02-26 03:44:51 -05:00
private final engine.Enum.SourceType damageType;
2024-02-14 12:29:42 -05:00
private final boolean twoHanded;
2023-07-15 09:23:48 -04:00
private boolean isConsumable;
2023-07-15 09:23:48 -04:00
// Item stat modifiers
2024-02-14 12:29:42 -05:00
private final HashMap<Integer, Integer> bakedInStats = new HashMap<>();
private final HashMap<Integer, Integer> usedStats = new HashMap<>();
private final boolean isStrBased;
2023-07-15 09:23:48 -04:00
private ArrayList<Integer> animations = new ArrayList<>();
private ArrayList<Integer> offHandAnimations = new ArrayList<>();
public ItemBase(ResultSet rs) throws SQLException {
this.uuid = rs.getInt("ID");
this.useID = rs.getInt("useID");
this.useAmount = rs.getByte("useAmount");
this.modTable = rs.getInt("modTable");
this.hashID = rs.getInt("itemHashID");
this.isConsumable = false;
this.skillRequired = rs.getString("skillRequired");
this.percentRequired = rs.getShort("percentRequired");
this.defense = rs.getShort("defense");
this.dexPenalty = rs.getFloat("dexPenalty");
this.isStrBased = (rs.getInt("isStrBased") == 1);
this.speed = rs.getFloat("speed");
this.range = rs.getFloat("range");
this.minDamage = rs.getShort("minDamage");
this.maxDamage = rs.getShort("maxDamage");
this.mastery = rs.getString("mastery");
2024-02-26 15:18:03 -05:00
damageType = Enum.SourceType.valueOf(rs.getString("damageType").toUpperCase());
2023-07-15 09:23:48 -04:00
this.twoHanded = (rs.getInt("twoHanded") == 1);
2024-03-10 13:34:24 -04:00
switch (ItemTemplate.itemTemplates.get(this.getUUID()).item_type) {
2023-07-15 09:23:48 -04:00
case RUNE:
case SCROLL:
2024-03-10 13:34:24 -04:00
case WAND:
2023-07-15 09:23:48 -04:00
case POTION:
2024-03-10 13:34:24 -04:00
case CHARTER:
2023-07-15 09:23:48 -04:00
case DEED:
2024-03-10 13:34:24 -04:00
case EMPLOYMENTCONTRACT:
case BUCKET:
2023-07-15 09:23:48 -04:00
case REALMCHARTER:
2024-03-10 13:34:24 -04:00
case TREASURE:
2023-07-15 09:23:48 -04:00
this.isConsumable = true;
break;
case OFFERING:
this.isConsumable = true;
Boon.HandleBoonListsForItemBase(uuid);
break;
}
try {
DbManager.ItemBaseQueries.LOAD_ANIMATIONS(this);
} catch (Exception e) {
Logger.error(e.getMessage());
}
initBakedInStats();
initializeHashes();
}
public static void addToCache(ItemBase itemBase) {
_itemBaseByUUID.put(itemBase.uuid, itemBase);
2024-03-10 13:34:24 -04:00
if (ItemTemplate.itemTemplates.get(itemBase.uuid).item_type.equals(ItemType.RESOURCE))
2023-07-15 09:23:48 -04:00
_resourceList.add(itemBase);
2024-02-28 16:42:07 -05:00
ItemTemplate template = ItemTemplate.itemTemplates.get(itemBase.uuid);
2024-02-28 17:41:48 -05:00
if (template == null)
Logger.error("Null template for: " + itemBase.uuid);
else
_IDsByNames.put(template.item_base_name.toLowerCase().replace(" ", "_"), itemBase.uuid);
2023-07-15 09:23:48 -04:00
}
public static HashMap<Integer, Integer> getItemHashIDMap() {
return itemHashIDMap;
}
public static ItemBase getItemBase(int uuid) {
return _itemBaseByUUID.get(uuid);
}
public static ItemBase getGoldItemBase() {
if (ItemBase.GOLD_ITEM_BASE == null)
ItemBase.GOLD_ITEM_BASE = getItemBase(7);
return ItemBase.GOLD_ITEM_BASE;
}
public static int getIDByName(String name) {
if (ItemBase._IDsByNames.containsKey(name))
return ItemBase._IDsByNames.get(name);
return 0;
}
public static HashMap<Integer, ItemBase> getUUIDCache() {
return _itemBaseByUUID;
}
public static ArrayList<ItemBase> getResourceList() {
return _resourceList;
}
public static void loadAllItemBases() {
DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES();
2024-02-11 07:29:42 -05:00
AnniversaryGifts.add(971000);
AnniversaryGifts.add(971001);
AnniversaryGifts.add(971002);
AnniversaryGifts.add(971003);
AnniversaryGifts.add(971004);
AnniversaryGifts.add(971005);
AnniversaryGifts.add(971006);
AnniversaryGifts.add(971007);
AnniversaryGifts.add(971008);
AnniversaryGifts.add(971009);
AnniversaryGifts.add(971010);
AnniversaryGifts.add(5101000);
AnniversaryGifts.add(5101020);
AnniversaryGifts.add(5101100);
AnniversaryGifts.add(5101120);
AnniversaryGifts.add(5101040);
AnniversaryGifts.add(5101140);
AnniversaryGifts.add(5101060);
AnniversaryGifts.add(5101080);
2023-07-15 09:23:48 -04:00
}
private void initBakedInStats() {
DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this);
}
public boolean isConsumable() {
return this.isConsumable;
}
public boolean isRune() {
int ID = uuid;
if (ID > 2499 && ID < 3050) //class, discipline runes
return true;
else
return ID > 249999 && ID < 252137;
}
public boolean isDiscRune() {
int ID = uuid;
2024-02-14 12:29:42 -05:00
//class, discipline runes
return ID > 2499 && ID < 3050;
2023-07-15 09:23:48 -04:00
}
public boolean isGlass() {
int ID = uuid;
return ID > 7000099 && ID < 7000281;
}
//returns powers tokens baked in to item
public HashMap<Integer, Integer> getBakedInStats() {
return this.bakedInStats;
}
//returns power tokens granted when using item, such as scrolls and potions
public HashMap<Integer, Integer> getUsedStats() {
return this.usedStats;
}
public final void initializeHashes() {
itemHashIDMap.put(this.hashID, uuid);
}
public int getUseID() {
return this.useID;
}
public byte getUseAmount() {
return this.useAmount;
}
public int getModTable() {
return modTable;
}
public int getHashID() {
return hashID;
}
public final int getUUID() {
return uuid;
}
public boolean isTwoHanded() {
return this.twoHanded;
}
public String getSkillRequired() {
return skillRequired;
}
public String getMastery() {
return mastery;
}
public short getDefense() {
return defense;
}
public float getDexPenalty() {
return dexPenalty;
}
public float getSpeed() {
return speed;
}
public float getRange() {
return range;
}
public boolean isStrBased() {
return isStrBased;
}
public short getMaxDamage() {
return maxDamage;
}
public short getMinDamage() {
return minDamage;
}
2024-02-26 03:44:51 -05:00
public Enum.SourceType getDamageType() {
2023-07-15 09:23:48 -04:00
return damageType;
}
public short getPercentRequired() {
return percentRequired;
}
public ArrayList<Integer> getAnimations() {
return animations;
}
public void setAnimations(ArrayList<Integer> animations) {
this.animations = animations;
}
public ArrayList<Integer> getOffHandAnimations() {
return offHandAnimations;
}
public void setOffHandAnimations(ArrayList<Integer> offHandAnimations) {
this.offHandAnimations = offHandAnimations;
}
2022-04-30 09:41:17 -04:00
}