Browse Source

Class cleanup

combat-2
MagicBot 7 months ago
parent
commit
b9627e1643
  1. 140
      src/engine/objects/CharacterItemManager.java

140
src/engine/objects/CharacterItemManager.java

@ -9,7 +9,10 @@ @@ -9,7 +9,10 @@
package engine.objects;
import engine.gameManager.*;
import engine.gameManager.BuildingManager;
import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import engine.gameManager.ItemManager;
import engine.math.Vector3fImmutable;
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
@ -152,9 +155,7 @@ public class CharacterItemManager { @@ -152,9 +155,7 @@ public class CharacterItemManager {
i.junk();
break;
}
}
this.goldVault = this.account.vaultGold;
//check all gold is created
@ -305,11 +306,9 @@ public class CharacterItemManager { @@ -305,11 +306,9 @@ public class CharacterItemManager {
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203);
return false;
}
}
break;
}
return true;
}
@ -370,44 +369,6 @@ public class CharacterItemManager { @@ -370,44 +369,6 @@ public class CharacterItemManager {
return success;
}
public synchronized boolean tradeRequest(TradeRequestMsg msg) {
PlayerCharacter source = (PlayerCharacter) this.getOwner();
PlayerCharacter target = PlayerCharacter.getFromCache(msg.getPlayerID());
Dispatch dispatch;
if (!canTrade(source, target)) {
ChatManager.chatSystemError(source, "Can't currently trade with target player");
return false;
}
// TODO uncomment this block after we determine when we
// setBankOpen(false) and setVaultOpen(false)
CharacterItemManager cim1 = source.charItemManager;
CharacterItemManager cim2 = target.charItemManager;
if (cim1 == null)
return false;
if (cim2 == null)
return false;
dispatch = Dispatch.borrow(target, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
return true;
}
public synchronized boolean invalidTradeRequest(InvalidTradeRequestMsg msg) {
PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID());
Dispatch dispatch;
dispatch = Dispatch.borrow(requester, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
return true;
}
public static synchronized boolean canTrade(PlayerCharacter playerA, PlayerCharacter playerB) {
if (playerA == null || playerB == null)
@ -449,6 +410,7 @@ public class CharacterItemManager { @@ -449,6 +410,7 @@ public class CharacterItemManager {
if (this.getTradingWith().getPlayerCharacter() == null)
return false;
CharacterItemManager man2 = this.getTradingWith().getPlayerCharacter().charItemManager;
Dispatch dispatch;
@ -469,11 +431,10 @@ public class CharacterItemManager { @@ -469,11 +431,10 @@ public class CharacterItemManager {
}
public synchronized boolean closeTradeWindow(CloseTradeWindowMsg msg, boolean sourceTrade) {
Dispatch dispatch;
PlayerCharacter source = (PlayerCharacter) this.getOwner();
if (source == null)
return false;
@ -501,11 +462,8 @@ public class CharacterItemManager { @@ -501,11 +462,8 @@ public class CharacterItemManager {
}
sourceItemMan.endTrade();
cc2.getPlayerCharacter().charItemManager.closeTradeWindow(msg, false);
return true;
}
@ -697,17 +655,19 @@ public class CharacterItemManager { @@ -697,17 +655,19 @@ public class CharacterItemManager {
// add to Bank
this.bank.add(i);
i.addToCache();
calculateWeights();
return true;
}
public synchronized boolean moveGoldToBank(Item from, int amt) {
if (from == null)
return false;
if (from.getNumOfItems() - amt < 0)
return false;
if (this.goldBank.getNumOfItems() + amt > MBServerStatics.BANK_GOLD_LIMIT) {
if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) {
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
@ -719,26 +679,33 @@ public class CharacterItemManager { @@ -719,26 +679,33 @@ public class CharacterItemManager {
if (!DbManager.ItemQueries.MOVE_GOLD(from, this.getGoldBank(), amt))
return false;
from.setNumOfItems(from.getNumOfItems() - amt);
this.goldBank.setNumOfItems(this.goldBank.getNumOfItems() + amt);
return true;
}
public synchronized boolean moveGoldToVault(Item from, int amt) {
if (from == null)
return false;
if (from.getNumOfItems() - amt < 0)
return false;
if (!DbManager.ItemQueries.MOVE_GOLD(from, this.account.vaultGold, amt))
return false;
from.setNumOfItems(from.getNumOfItems() - amt);
this.account.vaultGold.setNumOfItems(this.goldVault.getNumOfItems() + amt);
return true;
}
public synchronized boolean moveGoldToInventory(Item from, int amt) {
if (from == null)
return false;
if (from.getNumOfItems() - amt < 0 || amt < 1)
return false;
@ -841,7 +808,6 @@ public class CharacterItemManager { @@ -841,7 +808,6 @@ public class CharacterItemManager {
// add to Vault
i.addToCache();
calculateWeights();
return true;
@ -893,20 +859,12 @@ public class CharacterItemManager { @@ -893,20 +859,12 @@ public class CharacterItemManager {
this.inventory.add(i);
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
if (i.template != null)
this.inventoryWeight += i.template.item_wt;
return true;
}
//called for adding gold of a specified amount
public synchronized boolean addItemToInventory(Item i, int amount) {
if (i.template.item_type.equals(ItemType.GOLD))
return DbManager.ItemQueries.UPDATE_GOLD(this.getGoldInventory(), this.goldInventory.getNumOfItems() + amount);
return false;
}
public boolean equipItem(Item i, mbEnums.EquipSlotType slot) {
synchronized (this) {
@ -955,6 +913,7 @@ public class CharacterItemManager { @@ -955,6 +913,7 @@ public class CharacterItemManager {
}
//Apply Bonuses and update player
if (this.absCharacter != null) {
this.absCharacter.applyBonuses();
if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter))
@ -971,7 +930,6 @@ public class CharacterItemManager { @@ -971,7 +930,6 @@ public class CharacterItemManager {
if (cost <= 0 || (gold.getNumOfItems() - cost) < 0)
return false;
if (this.getOwner() != null && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) {
if (this.goldTradingAmount > 0) {
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.getOwner(), 195);
@ -982,25 +940,20 @@ public class CharacterItemManager { @@ -982,25 +940,20 @@ public class CharacterItemManager {
// Create gold from screatch instead of building strongbox
// if the NPC is not slotted.
if (vendorBuilding == null) {
if (vendorBuilding == null)
return this.modifyInventoryGold(-cost);
}
if (vendorBuilding.getStrongboxValue() + cost > vendorBuilding.getMaxGold()) {
if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) {
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
if (pc.getClientConnection() != null)
ErrorPopupMsg.sendErrorPopup(pc, 206);
}
return false;
}
// Update strongbox and inventory gold
if (!this.modifyInventoryGold(-cost))
return false;
@ -1026,7 +979,7 @@ public class CharacterItemManager { @@ -1026,7 +979,7 @@ public class CharacterItemManager {
//Used for selling items to NPC
public synchronized boolean sellToNPC(Building building, int cost, Item item) {
// Create gold from screatch instead of building strongbox
// Create gold from scratch instead of building strongbox
// if the NPC is not slotted.
if (this.getGoldInventory().getNumOfItems() + cost < 0)
@ -1063,11 +1016,6 @@ public class CharacterItemManager { @@ -1063,11 +1016,6 @@ public class CharacterItemManager {
return this.modifyInventoryGold(cost);
}
/**
* This sells an item to an npc
*
* @return True on success
*/
public synchronized boolean sellToNPC(Item itemToSell, NPC npc) {
CharacterItemManager itemMan;
@ -1127,12 +1075,6 @@ public class CharacterItemManager { @@ -1127,12 +1075,6 @@ public class CharacterItemManager {
return true;
}
/**
* This buys an item from an npc
* Handles transfer of item.
*
* @return True on success
*/
public synchronized boolean buyFromNPC(Item purchasedItem, NPC npc) {
CharacterItemManager itemMan;
@ -1162,45 +1104,27 @@ public class CharacterItemManager { @@ -1162,45 +1104,27 @@ public class CharacterItemManager {
// attempt to transfer item in db
if (purchasedItem.getObjectType() == GameObjectType.MobLoot) {
Item newItem = ((MobLoot) purchasedItem).promoteToItem((PlayerCharacter) this.absCharacter);
if (newItem == null)
return false;
if (!itemMan.removeItemFromInventory(purchasedItem))
return false;
if (!addItemToInventory(newItem))
return false;
//Item was created and still a mobloot item, remove from npc production list in db.
DbManager.NPCQueries.REMOVE_FROM_PRODUCTION_LIST(purchasedItem.getObjectUUID(), npc.getObjectUUID());
} else {
if (!purchasedItem.moveItemToInventory((PlayerCharacter) this.absCharacter))
return false;
// Reset value
if (!purchasedItem.moveItemToInventory((PlayerCharacter) this.absCharacter))
return false;
purchasedItem.value = (int) (purchasedItem.template.item_value * (purchasedItem.combat_health_current / purchasedItem.template.combat_health_full));
// Reset value
// db transfer successfully, remove from this character
// skip this check if this is a mobLoot item (which is not in any inventory)
if (!itemMan.removeItemFromInventory(purchasedItem))
return false;
purchasedItem.value = (int) (purchasedItem.template.item_value * (purchasedItem.combat_health_current / purchasedItem.template.combat_health_full));
// add item to looter.
// db transfer successfully, remove from this character
// skip this check if this is a mobLoot item (which is not in any inventory)
if (!itemMan.removeItemFromInventory(purchasedItem))
return false;
if (!addItemToInventory(purchasedItem))
return false;
}
// add item to looter.
if (!addItemToInventory(purchasedItem))
return false;
}
}
// calculate new weights
calculateInventoryWeight();
itemMan.calculateInventoryWeight();
return true;

Loading…
Cancel
Save