More integration work
This commit is contained in:
@@ -1341,28 +1341,28 @@ public class CharacterItemManager {
|
||||
/*
|
||||
* Delegates
|
||||
*/
|
||||
public synchronized boolean bankContains(Item i) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == i.getObjectUUID());
|
||||
return bank.contains(i);
|
||||
public synchronized boolean bankContains(Item item) {
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == item.getObjectUUID());
|
||||
return bank.contains(item);
|
||||
}
|
||||
|
||||
public synchronized boolean inventoryContains(Item i) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID());
|
||||
return inventory.contains(i);
|
||||
public synchronized boolean inventoryContains(Item item) {
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == item.getObjectUUID());
|
||||
return inventory.contains(item);
|
||||
}
|
||||
|
||||
public synchronized boolean forgeContains(Item i, NPC vendor) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID());
|
||||
return vendor.getRolling().contains(i);
|
||||
public synchronized boolean forgeContains(Item item, NPC vendor) {
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == item.getObjectUUID());
|
||||
return ForgeManager.vendorItemLookup.get(vendor).contains(item);
|
||||
}
|
||||
|
||||
public synchronized boolean vaultContains(Item i) {
|
||||
if (i.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == i.getObjectUUID());
|
||||
return this.account.getVault().contains(i);
|
||||
public synchronized boolean vaultContains(Item item) {
|
||||
if (item.template.item_type.equals(ItemType.GOLD))
|
||||
return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == item.getObjectUUID());
|
||||
return this.account.getVault().contains(item);
|
||||
}
|
||||
|
||||
public synchronized boolean equippedContains(Item i) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,6 @@ import engine.gameManager.*;
|
||||
import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.UpgradeNPCJob;
|
||||
import engine.loot.WorkOrder;
|
||||
import engine.math.Bounds;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
@@ -24,8 +23,6 @@ import engine.mbEnums.*;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.ItemProductionMsg;
|
||||
import engine.net.client.msg.PetMsg;
|
||||
import engine.net.client.msg.PlaceAssetMsg;
|
||||
import engine.server.MBServerStatics;
|
||||
@@ -50,9 +47,7 @@ public class NPC extends AbstractCharacter {
|
||||
public static HashMap<Integer, ArrayList<String>> _pirateNames = new HashMap<>();
|
||||
// Used for thread safety
|
||||
public final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
private final ArrayList<MobLoot> rolling = new ArrayList<>();
|
||||
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
|
||||
public ArrayList<ProducedItem> forgedItems = new ArrayList<>();
|
||||
public int runeSetID = 0;
|
||||
public int extraRune2 = 0;
|
||||
protected int loadID;
|
||||
@@ -79,7 +74,6 @@ public class NPC extends AbstractCharacter {
|
||||
public int parentZoneUUID;
|
||||
public int equipmentSetID = 0;
|
||||
private int repairCost = 5;
|
||||
public ArrayList<WorkOrder> workOrders = new ArrayList<>();
|
||||
|
||||
// New NPC constructor. Fill in the blanks and then call
|
||||
// PERSIST.
|
||||
@@ -915,58 +909,6 @@ public class NPC extends AbstractCharacter {
|
||||
|
||||
this.charItemManager.equipped = loadEquipmentSet(this.equipmentSetID);
|
||||
|
||||
try {
|
||||
|
||||
DbManager.NPCQueries.LOAD_ALL_ITEMS_TO_PRODUCE(this);
|
||||
|
||||
for (ProducedItem producedItem : this.forgedItems) {
|
||||
MobLoot ml = new MobLoot(this, ItemTemplate.templates.get(producedItem.getTemplateID()), false);
|
||||
|
||||
DbManager.NPCQueries.UPDATE_ITEM_ID(producedItem.getID(), currentID, ml.getObjectUUID());
|
||||
|
||||
if (producedItem.isInForge()) {
|
||||
|
||||
if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) {
|
||||
ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true);
|
||||
ml.setPrefix(producedItem.getPrefix());
|
||||
}
|
||||
|
||||
if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) {
|
||||
ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false);
|
||||
ml.setSuffix(producedItem.getSuffix());
|
||||
}
|
||||
|
||||
if (!producedItem.isRandom())
|
||||
ml.flags.add(ItemFlags.Identified);
|
||||
|
||||
ml.loadEnchantments();
|
||||
|
||||
ml.setValue(producedItem.getValue());
|
||||
ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis());
|
||||
ml.containerType = mbEnums.ItemContainerType.FORGE;
|
||||
this.addItemToForge(ml);
|
||||
|
||||
} else {
|
||||
|
||||
if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) {
|
||||
ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true);
|
||||
ml.setPrefix(producedItem.getPrefix());
|
||||
}
|
||||
|
||||
if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) {
|
||||
ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false);
|
||||
ml.setSuffix(producedItem.getSuffix());
|
||||
}
|
||||
|
||||
ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis());
|
||||
ml.containerType = mbEnums.ItemContainerType.INVENTORY;
|
||||
ml.flags.add(ItemFlags.Identified);
|
||||
|
||||
this.charItemManager.addItemToInventory(ml);
|
||||
}
|
||||
ml.setValue(producedItem.getValue());
|
||||
}
|
||||
|
||||
// Create NPC bounds object
|
||||
Bounds npcBounds = Bounds.borrow();
|
||||
npcBounds.setBounds(this.getLoc());
|
||||
@@ -975,9 +917,6 @@ public class NPC extends AbstractCharacter {
|
||||
NPCManager.applyRunesForNPC(this);
|
||||
this.resists.setImmuneToAll(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromZone() {
|
||||
@@ -1008,30 +947,6 @@ public class NPC extends AbstractCharacter {
|
||||
this.upgradeDateTime = upgradeDateTime;
|
||||
}
|
||||
|
||||
public ArrayList<MobLoot> getRolling() {
|
||||
synchronized (rolling) {
|
||||
return rolling;
|
||||
}
|
||||
}
|
||||
|
||||
public int getRollingCount() {
|
||||
synchronized (this.rolling) {
|
||||
return rolling.size();
|
||||
}
|
||||
}
|
||||
|
||||
public void addItemToForge(MobLoot item) {
|
||||
synchronized (this.rolling) {
|
||||
this.rolling.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItemFromForge(Item item) {
|
||||
synchronized (this.rolling) {
|
||||
this.rolling.remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Guild getGuild() {
|
||||
if (this.building != null)
|
||||
@@ -1166,109 +1081,6 @@ public class NPC extends AbstractCharacter {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public synchronized Item produceItem(int playerID, int amount, boolean isRandom, int pToken, int sToken, String customName, int itemID) {
|
||||
|
||||
Zone serverZone;
|
||||
City city;
|
||||
Item item = null;
|
||||
|
||||
PlayerCharacter player = null;
|
||||
|
||||
if (playerID != 0)
|
||||
player = SessionManager.getPlayerCharacterByID(playerID);
|
||||
|
||||
try {
|
||||
|
||||
if (this.getRollingCount() >= this.getRank()) {
|
||||
|
||||
if (player != null)
|
||||
ChatManager.chatSystemInfo(player, this.getName() + " " + this.getContract().getName() + " slots are full");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cannot roll items without a warehouse.
|
||||
// Due to the fact fillForge references the
|
||||
// warehouse and early exits. *** Refactor???
|
||||
|
||||
serverZone = this.building.getParentZone();
|
||||
|
||||
if (serverZone == null)
|
||||
return null;
|
||||
|
||||
city = City.GetCityFromCache(serverZone.playerCityUUID);
|
||||
|
||||
if (city == null) {
|
||||
|
||||
if (player != null)
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Could not find city."); // Production denied: This building must be protected to gain access to warehouse resources.
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.building == null) {
|
||||
|
||||
if (player != null)
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Could not find building."); // Production denied: This building must be protected to gain ac
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//TODO create Normal Items.
|
||||
|
||||
if (amount == 0)
|
||||
amount = 1;
|
||||
|
||||
if (isRandom)
|
||||
item = ItemFactory.randomRoll(this, player, amount, itemID);
|
||||
else
|
||||
item = ItemFactory.fillForge(this, player, amount, itemID, pToken, sToken, customName);
|
||||
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, item, 8, true);
|
||||
DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, 700, false, false);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public synchronized boolean completeItem(int itemUUID) {
|
||||
|
||||
MobLoot targetItem;
|
||||
|
||||
try {
|
||||
targetItem = MobLoot.getFromCache(itemUUID);
|
||||
|
||||
if (targetItem == null)
|
||||
return false;
|
||||
|
||||
if (!this.charItemManager.forgeContains(targetItem, this))
|
||||
return false;
|
||||
|
||||
if (!DbManager.NPCQueries.UPDATE_ITEM_TO_INVENTORY(targetItem.getObjectUUID(), currentID))
|
||||
return false;
|
||||
|
||||
targetItem.flags.add(ItemFlags.Identified);
|
||||
|
||||
this.rolling.remove(targetItem);
|
||||
this.charItemManager.addItemToInventory(targetItem);
|
||||
|
||||
//remove from client forge window
|
||||
|
||||
ItemProductionMsg outMsg1 = new ItemProductionMsg(this.building, this, targetItem, 9, true);
|
||||
DispatchMessage.dispatchMsgToInterestArea(this, outMsg1, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false);
|
||||
ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, targetItem, 10, true);
|
||||
DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getEquipmentSetID() {
|
||||
return equipmentSetID;
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.objects;
|
||||
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.mbEnums.DispatchChannel;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.msg.ItemProductionMsg;
|
||||
import engine.powers.EffectsBase;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
public class ProducedItem {
|
||||
|
||||
private int ID;
|
||||
private int npcUID;
|
||||
private int templateID;
|
||||
private DateTime dateToUpgrade;
|
||||
private boolean isRandom;
|
||||
|
||||
private String prefix;
|
||||
private String suffix;
|
||||
private String name;
|
||||
private int amount;
|
||||
private int producedItemID = 0;
|
||||
private boolean inForge;
|
||||
private int value;
|
||||
|
||||
private int playerID;
|
||||
|
||||
|
||||
/**
|
||||
* ResultSet Constructor
|
||||
*/
|
||||
|
||||
public ProducedItem(ResultSet rs) throws SQLException {
|
||||
this.ID = rs.getInt("ID");
|
||||
this.npcUID = rs.getInt("npcUID");
|
||||
this.templateID = rs.getInt("templateID");
|
||||
|
||||
Date sqlDateTime = rs.getTimestamp("dateToUpgrade");
|
||||
|
||||
if (sqlDateTime != null)
|
||||
this.dateToUpgrade = new DateTime(sqlDateTime);
|
||||
else
|
||||
dateToUpgrade = null;
|
||||
this.isRandom = rs.getBoolean("isRandom");
|
||||
this.prefix = rs.getString("prefix");
|
||||
this.suffix = rs.getString("suffix");
|
||||
this.name = rs.getString("name");
|
||||
this.inForge = rs.getBoolean("inForge");
|
||||
this.value = rs.getInt("value");
|
||||
this.playerID = rs.getInt("playerID");
|
||||
}
|
||||
|
||||
public ProducedItem(int ID, int npcUID, int templateID, DateTime dateToUpgrade, boolean isRandom, String prefix, String suffix, String name, int playerID) {
|
||||
super();
|
||||
this.ID = ID;
|
||||
this.npcUID = npcUID;
|
||||
this.templateID = templateID;
|
||||
this.dateToUpgrade = dateToUpgrade;
|
||||
this.isRandom = isRandom;
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.name = name;
|
||||
this.value = 0;
|
||||
this.playerID = playerID;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int getNpcUID() {
|
||||
return npcUID;
|
||||
}
|
||||
|
||||
public DateTime getDateToUpgrade() {
|
||||
return dateToUpgrade;
|
||||
}
|
||||
|
||||
public int getTemplateID() {
|
||||
return templateID;
|
||||
}
|
||||
|
||||
public void setTemplateID(int templateID) {
|
||||
this.templateID = templateID;
|
||||
}
|
||||
|
||||
public boolean isRandom() {
|
||||
return isRandom;
|
||||
}
|
||||
|
||||
public void setRandom(boolean isRandom) {
|
||||
this.isRandom = isRandom;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public void setID(int iD) {
|
||||
ID = iD;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
|
||||
public int getProducedItemID() {
|
||||
return producedItemID;
|
||||
}
|
||||
|
||||
public void setProducedItemID(int producedItemID) {
|
||||
this.producedItemID = producedItemID;
|
||||
}
|
||||
|
||||
public boolean isInForge() {
|
||||
return inForge;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean finishProduction() {
|
||||
NPC npc = NPC.getFromCache(this.getNpcUID());
|
||||
|
||||
if (npc == null)
|
||||
return false;
|
||||
|
||||
|
||||
//update the client to ID the item in the window when item finishes rolling.
|
||||
//If there is more than 1 item left to roll, complete the item and throw it in inventory
|
||||
//and reproduce next item.
|
||||
|
||||
try {
|
||||
|
||||
if (this.getAmount() > 1) {
|
||||
this.setAmount(this.getAmount() - 1);
|
||||
npc.completeItem(this.getProducedItemID());
|
||||
|
||||
int pToken = 0;
|
||||
int sToken = 0;
|
||||
|
||||
if (!this.isRandom()) {
|
||||
EffectsBase eb = PowersManager.getEffectByIDString(this.getPrefix());
|
||||
if (eb != null)
|
||||
pToken = eb.getToken();
|
||||
eb = PowersManager.getEffectByIDString(this.getSuffix());
|
||||
if (eb != null)
|
||||
sToken = eb.getToken();
|
||||
|
||||
}
|
||||
|
||||
Item item = npc.produceItem(0, this.getAmount(), this.isRandom(), pToken, sToken, this.getName(), this.getTemplateID());
|
||||
|
||||
if (item == null)
|
||||
return false;
|
||||
|
||||
} else {
|
||||
|
||||
//update item to complete
|
||||
MobLoot targetItem = MobLoot.getFromCache(this.getProducedItemID());
|
||||
|
||||
if (targetItem == null)
|
||||
return false;
|
||||
|
||||
ItemProductionMsg outMsg = new ItemProductionMsg(npc.getBuilding(), npc, targetItem, 8, true);
|
||||
|
||||
|
||||
DispatchMessage.dispatchMsgToInterestArea(npc, outMsg, DispatchChannel.SECONDARY, 700, false, false);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getPlayerID() {
|
||||
return playerID;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user