Browse Source

resource purchasing

lakebane-master
FatBoy-DOTC 5 months ago
parent
commit
02aafc9274
  1. 66
      src/engine/net/client/ClientMessagePump.java

66
src/engine/net/client/ClientMessagePump.java

@ -1415,18 +1415,15 @@ public class ClientMessagePump implements NetMsgHandler {
int cost = me.magicValue; int cost = me.magicValue;
if(npc.getContractID() == 1201 && me.getItemBase().getName().equals("Prospector")) if(npc.getContractID() == 1201 && me.getItemBase().getName().equals("Prospector"))
cost = 50; cost = 50;
int resourceCost = (Warehouse.getSellStackSize(me.getItemBase().getUUID()) * Warehouse.getCostForResource(me.getItemBase().getUUID()));
if (resourceCost != 0)
cost = resourceCost;
if(npc.contractUUID == 900 && me.getItemBase().getUUID() == 1705032){
cost = 1000000;
}
float bargain = sourcePlayer.getBargain(); float bargain = sourcePlayer.getBargain();
float profit = npc.getSellPercent(sourcePlayer) - bargain; float profit = npc.getSellPercent(sourcePlayer) - bargain;
if(me.getItemBase().getType().equals(ItemType.POTION)) if(me.getItemBase().getType().equals(ItemType.POTION))
profit -= 1.0f; profit -= 1.0f;
if (profit < 1) if (profit < 1)
profit = 1; profit = 1;
if(npc.getContractID() == 900){
cost = Warehouse.getCostForResource(ib.getUUID()) * Warehouse.getSellStackSize(ib.getUUID());
}
cost *= profit; cost *= profit;
if (gold.getNumOfItems() - cost < 0) { if (gold.getNumOfItems() - cost < 0) {
//dont' have enough goldItem exit! //dont' have enough goldItem exit!
@ -1447,33 +1444,7 @@ public class ClientMessagePump implements NetMsgHandler {
return; return;
} }
if(me.getItemBase().getType().equals(ItemType.RESOURCE) && npc.getContractID() == 900){ if(me.getItemBase().getType().equals(ItemType.RESOURCE) && npc.getContractID() == 900){
boolean stacked = false; handleResourcePurchase(me,itemMan,npc,buy,sourcePlayer,ib);
int buystack = Warehouse.getSellStackSize(me.getItemBase().getUUID());
for(Item item : itemMan.getInventory()){
int itemID = item.getItemBaseID();
int meID = me.getItemBase().getUUID();
if(itemID == meID){
if(Warehouse.maxResources.isEmpty())
Warehouse.getMaxResources();
int maxStack = Warehouse.maxResources.get(itemID);
if(maxStack > item.getNumOfItems() + buystack){
item.setNumOfItems(item.getNumOfItems() + buystack);
stacked = true;
itemMan.updateInventory();
DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems());
break;
}
}
}
if(!stacked){
buy = Item.createItemForPlayer(sourcePlayer, ib);
if (buy != null) {
me.transferEnchants(buy);
itemMan.addItemToInventory(buy);
buy.setNumOfItems(buystack);
DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems());
}
}
}else { }else {
buy = Item.createItemForPlayer(sourcePlayer, ib); buy = Item.createItemForPlayer(sourcePlayer, ib);
if (buy != null) { if (buy != null) {
@ -1589,6 +1560,35 @@ public class ClientMessagePump implements NetMsgHandler {
} }
} }
public static void handleResourcePurchase(MobEquipment me, CharacterItemManager itemMan, NPC npc, Item buy, PlayerCharacter sourcePlayer, ItemBase ib){
boolean stacked = false;
int buystack = Warehouse.getSellStackSize(me.getItemBase().getUUID());
for(Item item : itemMan.getInventory()){
int itemID = item.getItemBaseID();
int meID = me.getItemBase().getUUID();
if(itemID == meID){
if(Warehouse.maxResources.isEmpty())
Warehouse.getMaxResources();
int maxStack = Warehouse.maxResources.get(itemID);
if(maxStack > item.getNumOfItems() + buystack){
item.setNumOfItems(item.getNumOfItems() + buystack);
stacked = true;
itemMan.updateInventory();
DbManager.ItemQueries.UPDATE_NUM_ITEMS(item,item.getNumOfItems());
break;
}
}
}
if(!stacked){
buy = Item.createItemForPlayer(sourcePlayer, ib);
if (buy != null) {
me.transferEnchants(buy);
itemMan.addItemToInventory(buy);
buy.setNumOfItems(buystack);
DbManager.ItemQueries.UPDATE_NUM_ITEMS(buy,buy.getNumOfItems());
}
}
}
private static void Repair(RepairMsg msg, ClientConnection origin) { private static void Repair(RepairMsg msg, ClientConnection origin) {
PlayerCharacter player = SessionManager.getPlayerCharacter(origin); PlayerCharacter player = SessionManager.getPlayerCharacter(origin);

Loading…
Cancel
Save