forked from MagicBane/Server
More integration work
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user