forked from MagicBane/Server
Class cleanup
This commit is contained in:
@@ -9,7 +9,10 @@
|
|||||||
|
|
||||||
package engine.objects;
|
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.math.Vector3fImmutable;
|
||||||
import engine.mbEnums;
|
import engine.mbEnums;
|
||||||
import engine.mbEnums.GameObjectType;
|
import engine.mbEnums.GameObjectType;
|
||||||
@@ -152,9 +155,7 @@ public class CharacterItemManager {
|
|||||||
i.junk();
|
i.junk();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.goldVault = this.account.vaultGold;
|
this.goldVault = this.account.vaultGold;
|
||||||
|
|
||||||
//check all gold is created
|
//check all gold is created
|
||||||
@@ -305,11 +306,9 @@ public class CharacterItemManager {
|
|||||||
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203);
|
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -370,44 +369,6 @@ public class CharacterItemManager {
|
|||||||
return success;
|
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) {
|
public static synchronized boolean canTrade(PlayerCharacter playerA, PlayerCharacter playerB) {
|
||||||
|
|
||||||
if (playerA == null || playerB == null)
|
if (playerA == null || playerB == null)
|
||||||
@@ -449,6 +410,7 @@ public class CharacterItemManager {
|
|||||||
|
|
||||||
if (this.getTradingWith().getPlayerCharacter() == null)
|
if (this.getTradingWith().getPlayerCharacter() == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CharacterItemManager man2 = this.getTradingWith().getPlayerCharacter().charItemManager;
|
CharacterItemManager man2 = this.getTradingWith().getPlayerCharacter().charItemManager;
|
||||||
Dispatch dispatch;
|
Dispatch dispatch;
|
||||||
|
|
||||||
@@ -469,11 +431,10 @@ public class CharacterItemManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean closeTradeWindow(CloseTradeWindowMsg msg, boolean sourceTrade) {
|
public synchronized boolean closeTradeWindow(CloseTradeWindowMsg msg, boolean sourceTrade) {
|
||||||
|
|
||||||
|
|
||||||
Dispatch dispatch;
|
Dispatch dispatch;
|
||||||
|
|
||||||
PlayerCharacter source = (PlayerCharacter) this.getOwner();
|
PlayerCharacter source = (PlayerCharacter) this.getOwner();
|
||||||
|
|
||||||
if (source == null)
|
if (source == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -501,11 +462,8 @@ public class CharacterItemManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceItemMan.endTrade();
|
sourceItemMan.endTrade();
|
||||||
|
|
||||||
|
|
||||||
cc2.getPlayerCharacter().charItemManager.closeTradeWindow(msg, false);
|
cc2.getPlayerCharacter().charItemManager.closeTradeWindow(msg, false);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -697,17 +655,19 @@ public class CharacterItemManager {
|
|||||||
// add to Bank
|
// add to Bank
|
||||||
this.bank.add(i);
|
this.bank.add(i);
|
||||||
i.addToCache();
|
i.addToCache();
|
||||||
|
|
||||||
calculateWeights();
|
calculateWeights();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean moveGoldToBank(Item from, int amt) {
|
public synchronized boolean moveGoldToBank(Item from, int amt) {
|
||||||
|
|
||||||
if (from == null)
|
if (from == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (from.getNumOfItems() - amt < 0)
|
if (from.getNumOfItems() - amt < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (this.goldBank.getNumOfItems() + amt > MBServerStatics.BANK_GOLD_LIMIT) {
|
if (this.goldBank.getNumOfItems() + amt > MBServerStatics.BANK_GOLD_LIMIT) {
|
||||||
if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) {
|
if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) {
|
||||||
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
|
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
|
||||||
@@ -719,26 +679,33 @@ public class CharacterItemManager {
|
|||||||
|
|
||||||
if (!DbManager.ItemQueries.MOVE_GOLD(from, this.getGoldBank(), amt))
|
if (!DbManager.ItemQueries.MOVE_GOLD(from, this.getGoldBank(), amt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
from.setNumOfItems(from.getNumOfItems() - amt);
|
from.setNumOfItems(from.getNumOfItems() - amt);
|
||||||
this.goldBank.setNumOfItems(this.goldBank.getNumOfItems() + amt);
|
this.goldBank.setNumOfItems(this.goldBank.getNumOfItems() + amt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean moveGoldToVault(Item from, int amt) {
|
public synchronized boolean moveGoldToVault(Item from, int amt) {
|
||||||
|
|
||||||
if (from == null)
|
if (from == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (from.getNumOfItems() - amt < 0)
|
if (from.getNumOfItems() - amt < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!DbManager.ItemQueries.MOVE_GOLD(from, this.account.vaultGold, amt))
|
if (!DbManager.ItemQueries.MOVE_GOLD(from, this.account.vaultGold, amt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
from.setNumOfItems(from.getNumOfItems() - amt);
|
from.setNumOfItems(from.getNumOfItems() - amt);
|
||||||
this.account.vaultGold.setNumOfItems(this.goldVault.getNumOfItems() + amt);
|
this.account.vaultGold.setNumOfItems(this.goldVault.getNumOfItems() + amt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean moveGoldToInventory(Item from, int amt) {
|
public synchronized boolean moveGoldToInventory(Item from, int amt) {
|
||||||
|
|
||||||
if (from == null)
|
if (from == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (from.getNumOfItems() - amt < 0 || amt < 1)
|
if (from.getNumOfItems() - amt < 0 || amt < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -841,7 +808,6 @@ public class CharacterItemManager {
|
|||||||
|
|
||||||
// add to Vault
|
// add to Vault
|
||||||
i.addToCache();
|
i.addToCache();
|
||||||
|
|
||||||
calculateWeights();
|
calculateWeights();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -893,20 +859,12 @@ public class CharacterItemManager {
|
|||||||
this.inventory.add(i);
|
this.inventory.add(i);
|
||||||
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
|
this.itemIDtoType.put(i.getObjectUUID(), i.getObjectType().ordinal());
|
||||||
|
|
||||||
|
|
||||||
if (i.template != null)
|
if (i.template != null)
|
||||||
this.inventoryWeight += i.template.item_wt;
|
this.inventoryWeight += i.template.item_wt;
|
||||||
|
|
||||||
return true;
|
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) {
|
public boolean equipItem(Item i, mbEnums.EquipSlotType slot) {
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -955,6 +913,7 @@ public class CharacterItemManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Apply Bonuses and update player
|
//Apply Bonuses and update player
|
||||||
|
|
||||||
if (this.absCharacter != null) {
|
if (this.absCharacter != null) {
|
||||||
this.absCharacter.applyBonuses();
|
this.absCharacter.applyBonuses();
|
||||||
if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter))
|
if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter))
|
||||||
@@ -971,7 +930,6 @@ public class CharacterItemManager {
|
|||||||
if (cost <= 0 || (gold.getNumOfItems() - cost) < 0)
|
if (cost <= 0 || (gold.getNumOfItems() - cost) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (this.getOwner() != null && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) {
|
if (this.getOwner() != null && this.getOwner().getObjectType().equals(GameObjectType.PlayerCharacter)) {
|
||||||
if (this.goldTradingAmount > 0) {
|
if (this.goldTradingAmount > 0) {
|
||||||
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.getOwner(), 195);
|
ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.getOwner(), 195);
|
||||||
@@ -982,25 +940,20 @@ public class CharacterItemManager {
|
|||||||
// Create gold from screatch instead of building strongbox
|
// Create gold from screatch instead of building strongbox
|
||||||
// if the NPC is not slotted.
|
// if the NPC is not slotted.
|
||||||
|
|
||||||
if (vendorBuilding == null) {
|
if (vendorBuilding == null)
|
||||||
|
|
||||||
return this.modifyInventoryGold(-cost);
|
return this.modifyInventoryGold(-cost);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (vendorBuilding.getStrongboxValue() + cost > vendorBuilding.getMaxGold()) {
|
if (vendorBuilding.getStrongboxValue() + cost > vendorBuilding.getMaxGold()) {
|
||||||
|
|
||||||
if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) {
|
if (this.absCharacter.getObjectType() == GameObjectType.PlayerCharacter) {
|
||||||
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
|
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
|
||||||
if (pc.getClientConnection() != null)
|
if (pc.getClientConnection() != null)
|
||||||
ErrorPopupMsg.sendErrorPopup(pc, 206);
|
ErrorPopupMsg.sendErrorPopup(pc, 206);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update strongbox and inventory gold
|
// Update strongbox and inventory gold
|
||||||
|
|
||||||
if (!this.modifyInventoryGold(-cost))
|
if (!this.modifyInventoryGold(-cost))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1026,7 +979,7 @@ public class CharacterItemManager {
|
|||||||
//Used for selling items to NPC
|
//Used for selling items to NPC
|
||||||
public synchronized boolean sellToNPC(Building building, int cost, Item item) {
|
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 the NPC is not slotted.
|
||||||
|
|
||||||
if (this.getGoldInventory().getNumOfItems() + cost < 0)
|
if (this.getGoldInventory().getNumOfItems() + cost < 0)
|
||||||
@@ -1063,11 +1016,6 @@ public class CharacterItemManager {
|
|||||||
return this.modifyInventoryGold(cost);
|
return this.modifyInventoryGold(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This sells an item to an npc
|
|
||||||
*
|
|
||||||
* @return True on success
|
|
||||||
*/
|
|
||||||
public synchronized boolean sellToNPC(Item itemToSell, NPC npc) {
|
public synchronized boolean sellToNPC(Item itemToSell, NPC npc) {
|
||||||
|
|
||||||
CharacterItemManager itemMan;
|
CharacterItemManager itemMan;
|
||||||
@@ -1127,12 +1075,6 @@ public class CharacterItemManager {
|
|||||||
return true;
|
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) {
|
public synchronized boolean buyFromNPC(Item purchasedItem, NPC npc) {
|
||||||
|
|
||||||
CharacterItemManager itemMan;
|
CharacterItemManager itemMan;
|
||||||
@@ -1162,23 +1104,6 @@ public class CharacterItemManager {
|
|||||||
|
|
||||||
// attempt to transfer item in db
|
// 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))
|
if (!purchasedItem.moveItemToInventory((PlayerCharacter) this.absCharacter))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1196,11 +1121,10 @@ public class CharacterItemManager {
|
|||||||
if (!addItemToInventory(purchasedItem))
|
if (!addItemToInventory(purchasedItem))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate new weights
|
// calculate new weights
|
||||||
|
|
||||||
calculateInventoryWeight();
|
calculateInventoryWeight();
|
||||||
itemMan.calculateInventoryWeight();
|
itemMan.calculateInventoryWeight();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user