reimplement resource merchant with 5mil stacks
This commit is contained in:
@@ -505,23 +505,17 @@ public class dbItemHandler extends dbHandlerBase {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_NUM_ITEMS(final Item item, int newValue, int oldValue) {
|
||||
|
||||
public boolean UPDATE_NUM_ITEMS(final Item item, int newValue) {
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newValue);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,13 +123,13 @@ public enum LootManager {
|
||||
case "LOOT":
|
||||
if (ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate))
|
||||
GenerateLootDrop(mob, bse.genTable); //generate normal loot drop
|
||||
if(ThreadLocalRandom.current().nextInt(1,250) == 100){
|
||||
if(ThreadLocalRandom.current().nextInt(1,100) == 50){
|
||||
MobLoot extraLoot = rollForContract(bse.genTable, mob);
|
||||
if (extraLoot != null) {
|
||||
mob.getCharItemManager().addItemToInventory(extraLoot);
|
||||
}
|
||||
}
|
||||
if(ThreadLocalRandom.current().nextInt(1,250) == 100){
|
||||
if(ThreadLocalRandom.current().nextInt(1,100) == 50){
|
||||
MobLoot extraLoot = rollForRune(bse.genTable, mob);
|
||||
if (extraLoot != null) {
|
||||
mob.getCharItemManager().addItemToInventory(extraLoot);
|
||||
|
||||
@@ -148,12 +148,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
pc.setActive(true);
|
||||
|
||||
pc.setLastTarget(GameObjectType.values()[msg.getTargetType()], msg.getTargetID());
|
||||
|
||||
if(!pc.getTimestamps().containsKey("lastTab"))
|
||||
pc.getTimestamps().put("lastTab",System.currentTimeMillis());
|
||||
|
||||
if(System.currentTimeMillis() - pc.getTimestamps().get("lastTab") < 100)
|
||||
Logger.error("USE OF /TAR SUSPECTED BY PLAYER: " + pc.getName());
|
||||
}
|
||||
|
||||
private static void social(SocialMsg msg, ClientConnection origin) throws MsgSendException {
|
||||
@@ -1385,33 +1379,24 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
}
|
||||
|
||||
private static void buyFromNPC(BuyFromNPCMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return;
|
||||
|
||||
if (origin.buyLock.tryLock()) {
|
||||
|
||||
try {
|
||||
CharacterItemManager itemMan = sourcePlayer.getCharItemManager();
|
||||
|
||||
if (itemMan == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
NPC npc = NPC.getFromCache(msg.getNPCID());
|
||||
|
||||
if (npc == null) {
|
||||
return;
|
||||
}
|
||||
Item gold = itemMan.getGoldInventory();
|
||||
|
||||
if (gold == null) {
|
||||
return;
|
||||
}
|
||||
Item buy = null;
|
||||
|
||||
if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) {
|
||||
ArrayList<MobEquipment> sellInventory = npc.getContract().getSellInventory();
|
||||
if (sellInventory == null) {
|
||||
@@ -1436,30 +1421,19 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
if(npc.contractUUID == 900 && me.getItemBase().getUUID() == 1705032){
|
||||
cost = 1000000;
|
||||
}
|
||||
|
||||
float bargain = sourcePlayer.getBargain();
|
||||
|
||||
float profit = npc.getSellPercent(sourcePlayer) - bargain;
|
||||
|
||||
if(me.getItemBase().getType().equals(ItemType.POTION))
|
||||
profit -= 1.0f;
|
||||
|
||||
if (profit < 1)
|
||||
profit = 1;
|
||||
|
||||
|
||||
|
||||
cost *= profit;
|
||||
|
||||
|
||||
if (gold.getNumOfItems() - cost < 0) {
|
||||
//dont' have enough goldItem exit!
|
||||
// chatMan.chatSystemInfo(pc, "" + "You dont have enough gold.");
|
||||
return;
|
||||
}
|
||||
|
||||
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
|
||||
|
||||
if (b != null && b.getProtectionState().equals(ProtectionState.NPC))
|
||||
b = null;
|
||||
int buildingDeposit = cost - me.getMagicValue();
|
||||
@@ -1467,7 +1441,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) {
|
||||
// chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item.");
|
||||
ChatManager.chatSystemError(sourcePlayer, "Failed To Buy Item");
|
||||
@@ -1487,7 +1460,7 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
item.setNumOfItems(item.getNumOfItems() + buystack);
|
||||
stacked = true;
|
||||
itemMan.updateInventory();
|
||||
DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems(),0);
|
||||
DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1498,7 +1471,7 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
me.transferEnchants(buy);
|
||||
itemMan.addItemToInventory(buy);
|
||||
buy.setNumOfItems(buystack);
|
||||
DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems(),0);
|
||||
DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
@@ -1508,7 +1481,7 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
itemMan.addItemToInventory(buy);
|
||||
if(npc.contractUUID == 900 && buy.getItemBaseID() == 1705032){
|
||||
buy.setNumOfItems(10);
|
||||
DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems(),0);
|
||||
DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems());
|
||||
}
|
||||
//itemMan.updateInventory();
|
||||
}
|
||||
@@ -1516,135 +1489,90 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
}
|
||||
}
|
||||
} else if (msg.getItemType() == GameObjectType.Item.ordinal()) {
|
||||
|
||||
CharacterItemManager npcCim = npc.getCharItemManager();
|
||||
|
||||
if (npcCim == null)
|
||||
return;
|
||||
|
||||
buy = Item.getFromCache(msg.getItemID());
|
||||
|
||||
if (buy == null)
|
||||
return;
|
||||
|
||||
ItemBase ib = buy.getItemBase();
|
||||
|
||||
if (ib == null)
|
||||
return;
|
||||
|
||||
if (!npcCim.inventoryContains(buy))
|
||||
return;
|
||||
|
||||
//test room available for item
|
||||
if (!itemMan.hasRoomInventory(ib.getWeight()))
|
||||
return;
|
||||
|
||||
//TODO test cost and subtract goldItem
|
||||
|
||||
//TODO CHnage this if we ever put NPc city npcs in buildings.
|
||||
int cost = buy.getBaseValue();
|
||||
|
||||
if (buy.isID() || buy.isCustomValue())
|
||||
cost = buy.getMagicValue();
|
||||
|
||||
float bargain = sourcePlayer.getBargain();
|
||||
|
||||
float profit = npc.getSellPercent(sourcePlayer) - bargain;
|
||||
|
||||
if (profit < 1)
|
||||
profit = 1;
|
||||
|
||||
if (!buy.isCustomValue())
|
||||
cost *= profit;
|
||||
else
|
||||
cost = buy.getValue();
|
||||
|
||||
|
||||
if (gold.getNumOfItems() - cost < 0) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold
|
||||
return;
|
||||
}
|
||||
|
||||
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
|
||||
|
||||
if (b != null)
|
||||
if (b.getProtectionState().equals(ProtectionState.NPC))
|
||||
b = null;
|
||||
|
||||
int buildingDeposit = cost;
|
||||
|
||||
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold() && !b.isOwnerIsNPC()) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110);
|
||||
return;
|
||||
}
|
||||
|
||||
if (buy != null)
|
||||
itemMan.buyFromNPC(buy, npc);
|
||||
|
||||
} else if (msg.getItemType() == GameObjectType.MobLoot.ordinal()) {
|
||||
|
||||
CharacterItemManager npcCim = npc.getCharItemManager();
|
||||
|
||||
if (npcCim == null)
|
||||
return;
|
||||
|
||||
buy = MobLoot.getFromCache(msg.getItemID());
|
||||
|
||||
if (buy == null)
|
||||
return;
|
||||
|
||||
ItemBase ib = buy.getItemBase();
|
||||
|
||||
if (ib == null)
|
||||
return;
|
||||
|
||||
if (!npcCim.inventoryContains(buy))
|
||||
return;
|
||||
|
||||
//test room available for item
|
||||
if (!itemMan.hasRoomInventory(ib.getWeight()))
|
||||
return;
|
||||
|
||||
//TODO test cost and subtract goldItem
|
||||
|
||||
//TODO CHnage this if we ever put NPc city npcs in buildings.
|
||||
|
||||
int cost = buy.getMagicValue();
|
||||
cost *= npc.getSellPercent(sourcePlayer);
|
||||
|
||||
|
||||
if (gold.getNumOfItems() - cost < 0) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold
|
||||
return;
|
||||
}
|
||||
|
||||
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
|
||||
|
||||
if (b != null && b.getProtectionState().equals(ProtectionState.NPC))
|
||||
b = null;
|
||||
int buildingDeposit = cost;
|
||||
|
||||
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold() && !b.isOwnerIsNPC()) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemMan.buyFromNPC(b, cost, buildingDeposit))
|
||||
return;
|
||||
|
||||
if (buy != null)
|
||||
itemMan.buyFromNPC(buy, npc);
|
||||
|
||||
} else
|
||||
return;
|
||||
|
||||
if (buy != null) {
|
||||
|
||||
msg.setItem(buy);
|
||||
//send the buy message back to update player
|
||||
// msg.setItemType(buy.getObjectType().ordinal());
|
||||
@@ -1653,14 +1581,12 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
itemMan.updateInventory();
|
||||
}
|
||||
|
||||
} finally {
|
||||
origin.buyLock.unlock();
|
||||
}
|
||||
} else {
|
||||
ErrorPopupMsg.sendErrorPopup(origin.getPlayerCharacter(), 12); // All production slots taken
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void Repair(RepairMsg msg, ClientConnection origin) {
|
||||
@@ -1890,9 +1816,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static void handlePetToggle(PetMsg msg){
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean handleClientMsg(ClientNetMsg msg) {
|
||||
|
||||
@@ -1923,9 +1846,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
protocolMsg = msg.getProtocolMsg();
|
||||
|
||||
switch (protocolMsg) {
|
||||
case PET:
|
||||
handlePetToggle((PetMsg)msg);
|
||||
break;
|
||||
case SETSELECTEDOBECT:
|
||||
ClientMessagePump.targetObject((TargetObjectMsg) msg, origin);
|
||||
break;
|
||||
|
||||
@@ -129,43 +129,46 @@ public class Warehouse extends AbstractWorldObject {
|
||||
|
||||
public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) {
|
||||
|
||||
Building warehouseBuilding = npc.getBuilding();
|
||||
if (warehouseBuilding == null) {
|
||||
Building warehouseBuilding;
|
||||
Warehouse warehouse;
|
||||
int depositAmount;
|
||||
Dispatch dispatch;
|
||||
|
||||
Item resource = Item.getFromCache(msg.getItemID());
|
||||
|
||||
if (resource == null)
|
||||
return;
|
||||
|
||||
depositAmount = msg.getAmount();
|
||||
CharacterItemManager itemMan = player.getCharItemManager();
|
||||
|
||||
if (itemMan.doesCharOwnThisItem(resource.getObjectUUID()) == false)
|
||||
return;
|
||||
|
||||
warehouseBuilding = npc.getBuilding();
|
||||
|
||||
if (warehouseBuilding == null)
|
||||
return;
|
||||
|
||||
warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID());
|
||||
|
||||
if (warehouse == null)
|
||||
return;
|
||||
|
||||
ItemBase ib = resource.getItemBase();
|
||||
|
||||
if (!warehouse.deposit(player, resource, depositAmount, true, true)) {
|
||||
// ChatManager.chatGuildError(player, "Failed to deposit " + ib.getName() +".");
|
||||
// Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
player.getTimestamps().put("lastDepositWarehouse", System.currentTimeMillis());
|
||||
player.depositingWarehouse = true;
|
||||
player.warehouseBuilding = warehouseBuilding;
|
||||
player.getCharItemManager().updateLock = true;
|
||||
Item resource = Item.getFromCache(msg.getItemID());
|
||||
|
||||
if (resource == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int depositAmount = msg.getAmount();
|
||||
CharacterItemManager itemMan = player.getCharItemManager();
|
||||
|
||||
if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Warehouse warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID());
|
||||
if (warehouse == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!warehouse.deposit(player, resource, depositAmount, true, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
//vrm.setGuild(player.getGuild());
|
||||
//vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
//vrm.configure();
|
||||
//Dispatch dispatch = Dispatch.borrow(player, vrm);
|
||||
//DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
vrm.setGuild(player.getGuild());
|
||||
vrm.setWarehouseBuilding(warehouseBuilding);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) {
|
||||
@@ -459,59 +462,6 @@ public class Warehouse extends AbstractWorldObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean removeFromInventory(CharacterItemManager itemMan, ItemBase ib, int amount, PlayerCharacter pc) {
|
||||
if (ib.getUUID() == 7) {
|
||||
if (!itemMan.modifyInventoryGold(-amount)) {
|
||||
// ChatManager.chatSystemError(pc, "You do not have this Gold.");
|
||||
return false;
|
||||
}
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(pc);
|
||||
ugm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(pc, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
} else {
|
||||
Item resource = itemMan.getItemByUUID(ib.getUUID());
|
||||
if (resource == null) return false;
|
||||
itemMan.delete(resource);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean updateDatabase(int itemID, int newAmount) {
|
||||
switch (itemID) {
|
||||
case 7: return DbManager.WarehouseQueries.updateGold(this, newAmount);
|
||||
case 1580000: return DbManager.WarehouseQueries.updateStone(this, newAmount);
|
||||
case 1580001: return DbManager.WarehouseQueries.updateTruesteel(this, newAmount);
|
||||
case 1580002: return DbManager.WarehouseQueries.updateIron(this, newAmount);
|
||||
case 1580003: return DbManager.WarehouseQueries.updateAdamant(this, newAmount);
|
||||
case 1580004: return DbManager.WarehouseQueries.updateLumber(this, newAmount);
|
||||
case 1580005: return DbManager.WarehouseQueries.updateOak(this, newAmount);
|
||||
case 1580006: return DbManager.WarehouseQueries.updateBronzewood(this, newAmount);
|
||||
case 1580007: return DbManager.WarehouseQueries.updateMandrake(this, newAmount);
|
||||
case 1580008: return DbManager.WarehouseQueries.updateCoal(this, newAmount);
|
||||
case 1580009: return DbManager.WarehouseQueries.updateAgate(this, newAmount);
|
||||
case 1580010: return DbManager.WarehouseQueries.updateDiamond(this, newAmount);
|
||||
case 1580011: return DbManager.WarehouseQueries.updateOnyx(this, newAmount);
|
||||
case 1580012: return DbManager.WarehouseQueries.updateAzoth(this, newAmount);
|
||||
case 1580013: return DbManager.WarehouseQueries.updateOrichalk(this, newAmount);
|
||||
case 1580014: return DbManager.WarehouseQueries.updateAntimony(this, newAmount);
|
||||
case 1580015: return DbManager.WarehouseQueries.updateSulfur(this, newAmount);
|
||||
case 1580016: return DbManager.WarehouseQueries.updateQuicksilver(this, newAmount);
|
||||
case 1580017: return DbManager.WarehouseQueries.updateGalvor(this, newAmount);
|
||||
case 1580018: return DbManager.WarehouseQueries.updateWormwood(this, newAmount);
|
||||
case 1580019: return DbManager.WarehouseQueries.updateObsidian(this, newAmount);
|
||||
case 1580020: return DbManager.WarehouseQueries.updateBloodstone(this, newAmount);
|
||||
case 1580021: return DbManager.WarehouseQueries.updateMithril(this, newAmount);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Resource getResourceType(Item resource) {
|
||||
return resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)
|
||||
? Resource.GOLD
|
||||
: Resource.valueOf(resource.getItemBase().getName().toUpperCase());
|
||||
}
|
||||
|
||||
//for mine deposit
|
||||
public synchronized boolean depositFromMine(Mine mine, ItemBase resource, int amount) {
|
||||
|
||||
@@ -1455,8 +1405,8 @@ public class Warehouse extends AbstractWorldObject {
|
||||
|
||||
return newCost;
|
||||
}
|
||||
public static int getSellStackSize(int id){
|
||||
|
||||
return (int)500000 / (getCostForResource(id));
|
||||
public static int getSellStackSize(int id){
|
||||
return (int)(5000000 / (getCostForResource(id)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user