@ -9,9 +9,7 @@
package engine.objects ;
package engine.objects ;
import ch.claude_martin.enumbitset.EnumBitSet ;
import engine.Enum ;
import engine.Enum ;
import engine.gameManager.BuildingManager ;
import engine.gameManager.ChatManager ;
import engine.gameManager.ChatManager ;
import engine.gameManager.DbManager ;
import engine.gameManager.DbManager ;
import engine.net.Dispatch ;
import engine.net.Dispatch ;
@ -20,56 +18,33 @@ import engine.net.client.ClientConnection;
import engine.net.client.msg.* ;
import engine.net.client.msg.* ;
import engine.server.MBServerStatics ;
import engine.server.MBServerStatics ;
import org.joda.time.DateTime ;
import org.joda.time.DateTime ;
import org.json.simple.JSONObject ;
import org.pmw.tinylog.Logger ;
import org.pmw.tinylog.Logger ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.sql.SQLException ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.EnumSet ;
import java.util.EnumSet ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
public class Warehouse extends AbstractWorldObject {
public class Warehouse {
public static ConcurrentHashMap < Integer , Warehouse > warehouseByBuildingUUID = new ConcurrentHashMap < > ( ) ;
public EnumSet < Enum . ResourceType > lockedResourceTypes ;
public EnumBitSet < Enum . ResourceType > lockedResourceTypes ;
public int UID ;
public int buildingUID ;
public int buildingUID ;
public City city ;
public ArrayList < Transaction > transactions = new ArrayList < > ( ) ;
public ArrayList < Transaction > transactions = new ArrayList < > ( ) ;
public ConcurrentHashMap < Enum . ResourceType , Integer > resources = new ConcurrentHashMap < > ( ) ;
public ConcurrentHashMap < Enum . ResourceType , Integer > resources = new ConcurrentHashMap < > ( ) ;
public Warehouse ( JSONObject warehouse ) throws SQLException {
JSONObject resources = ( JSONObject ) warehouse . get ( "resources" ) ;
for ( Object key : resources . keySet ( ) ) {
Enum . ResourceType resourceType = Enum . ResourceType . valueOf ( ( String ) key ) ;
float value = ( ( Long ) resources . get ( key ) ) . intValue ( ) ;
resources . put ( resourceType , value ) ;
}
/ * *
* ResultSet Constructor
* /
public Warehouse ( ResultSet rs ) throws SQLException {
super ( rs ) ;
this . UID = rs . getInt ( "UID" ) ;
this . resources . put ( Enum . ResourceType . STONE , rs . getInt ( "warehouse_stone" ) ) ;
this . resources . put ( Enum . ResourceType . TRUESTEEL , rs . getInt ( "warehouse_truesteel" ) ) ;
this . resources . put ( Enum . ResourceType . IRON , rs . getInt ( "warehouse_iron" ) ) ;
this . resources . put ( Enum . ResourceType . ADAMANT , rs . getInt ( "warehouse_adamant" ) ) ;
this . resources . put ( Enum . ResourceType . LUMBER , rs . getInt ( "warehouse_lumber" ) ) ;
this . resources . put ( Enum . ResourceType . OAK , rs . getInt ( "warehouse_oak" ) ) ;
this . resources . put ( Enum . ResourceType . BRONZEWOOD , rs . getInt ( "warehouse_bronzewood" ) ) ;
this . resources . put ( Enum . ResourceType . MANDRAKE , rs . getInt ( "warehouse_mandrake" ) ) ;
this . resources . put ( Enum . ResourceType . COAL , rs . getInt ( "warehouse_coal" ) ) ;
this . resources . put ( Enum . ResourceType . AGATE , rs . getInt ( "warehouse_agate" ) ) ;
this . resources . put ( Enum . ResourceType . DIAMOND , rs . getInt ( "warehouse_diamond" ) ) ;
this . resources . put ( Enum . ResourceType . ONYX , rs . getInt ( "warehouse_onyx" ) ) ;
this . resources . put ( Enum . ResourceType . AZOTH , rs . getInt ( "warehouse_azoth" ) ) ;
this . resources . put ( Enum . ResourceType . ORICHALK , rs . getInt ( "warehouse_orichalk" ) ) ;
this . resources . put ( Enum . ResourceType . ANTIMONY , rs . getInt ( "warehouse_antimony" ) ) ;
this . resources . put ( Enum . ResourceType . SULFUR , rs . getInt ( "warehouse_sulfur" ) ) ;
this . resources . put ( Enum . ResourceType . QUICKSILVER , rs . getInt ( "warehouse_quicksilver" ) ) ;
this . resources . put ( Enum . ResourceType . GALVOR , rs . getInt ( "warehouse_galvor" ) ) ;
this . resources . put ( Enum . ResourceType . WORMWOOD , rs . getInt ( "warehouse_wormwood" ) ) ;
this . resources . put ( Enum . ResourceType . OBSIDIAN , rs . getInt ( "warehouse_obsidian" ) ) ;
this . resources . put ( Enum . ResourceType . BLOODSTONE , rs . getInt ( "warehouse_bloodstone" ) ) ;
this . resources . put ( Enum . ResourceType . MITHRIL , rs . getInt ( "warehouse_mithril" ) ) ;
this . resources . put ( Enum . ResourceType . GOLD , rs . getInt ( "warehouse_gold" ) ) ;
this . lockedResourceTypes = EnumBitSet . asEnumBitSet ( rs . getLong ( "warehouse_locks" ) , Enum . ResourceType . class ) ;
this . buildingUID = rs . getInt ( "parent" ) ;
warehouseByBuildingUUID . put ( this . buildingUID , this ) ;
}
}
public static void warehouseDeposit ( MerchantMsg msg , PlayerCharacter player , NPC npc ) {
public static void warehouseDeposit ( MerchantMsg msg , PlayerCharacter player , NPC npc ) {
@ -95,7 +70,7 @@ public class Warehouse extends AbstractWorldObject {
if ( warehouseBuilding = = null )
if ( warehouseBuilding = = null )
return ;
return ;
warehouse = warehouseByB uildingUUID . get ( warehouseBuilding . getObjectUUID ( ) ) ;
warehouse = warehouseBuilding . getCity ( ) . warehouse ;
if ( warehouse = = null )
if ( warehouse = = null )
return ;
return ;
@ -129,7 +104,13 @@ public class Warehouse extends AbstractWorldObject {
if ( player . getGuild ( ) ! = warehouseBuilding . getGuild ( ) | | ! GuildStatusController . isInnerCouncil ( player . getGuildStatus ( ) ) )
if ( player . getGuild ( ) ! = warehouseBuilding . getGuild ( ) | | ! GuildStatusController . isInnerCouncil ( player . getGuildStatus ( ) ) )
return ;
return ;
warehouse = warehouseByBuildingUUID . get ( warehouseBuilding . getObjectUUID ( ) ) ;
City city = warehouseBuilding . getCity ( ) ;
if ( city = = null )
return ;
;
warehouse = city . warehouse ;
if ( warehouse = = null )
if ( warehouse = = null )
return ;
return ;
@ -155,60 +136,65 @@ public class Warehouse extends AbstractWorldObject {
}
}
public static void warehouseLock ( MerchantMsg msg , PlayerCharacter player , NPC npc ) {
public static void warehouseLock ( MerchantMsg msg , PlayerCharacter player , NPC npc ) {
Building warehouse ;
Building warehouseBuilding ;
Warehouse warehouse ;
int hashID ;
int hashID ;
Dispatch dispatch ;
Dispatch dispatch ;
hashID = msg . getHashID ( ) ;
hashID = msg . getHashID ( ) ;
warehouse = npc . getBuilding ( ) ;
warehouseBuilding = npc . getBuilding ( ) ;
if ( warehouse = = null )
if ( warehouseBuilding = = null )
return ;
return ;
if ( player . getGuild ( ) ! = warehouse . getGuild ( ) | | ! GuildStatusController . isInnerCouncil ( player . getGuildStatus ( ) ) )
if ( player . getGuild ( ) ! = warehouseBuilding . getGuild ( ) | | ! GuildStatusController . isInnerCouncil ( player . getGuildStatus ( ) ) )
return ;
return ;
Warehouse wh = warehouseBy BuildingUUID . get ( warehouse . getObjectUUID ( ) ) ;
City city = warehouseBuilding . getCity ( ) ;
if ( wh = = null )
if ( city = = null )
return ;
return ;
;
warehouse = city . warehouse ;
Enum . ResourceType resourceType = Enum . ResourceType . hashLookup . get ( hashID ) ;
Enum . ResourceType resourceType = Enum . ResourceType . hashLookup . get ( hashID ) ;
if ( isResourceLocked ( wh , resourceType ) ) {
// toggle lock
boolean worked ;
EnumBitSet < Enum . ResourceType > bitSet = EnumBitSet . asEnumBitSet ( wh . lockedResourceTypes . toLong ( ) , Enum . ResourceType . class ) ;
bitSet . remove ( resourceType ) ;
if ( warehouse . lockedResourceTypes . contains ( resourceType ) ) {
worked = DbManager . WarehouseQueries . updateLocks ( wh , bitSet . toLong ( ) ) ;
boolean worked ;
warehouse . lockedResourceTypes . remove ( resourceType ) ;
worked = DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ;
if ( worked ) {
if ( worked ) {
wh . lockedResourceTypes . remove ( resourceType ) ;
ViewResourcesMessage vrm = new ViewResourcesMessage ( player ) ;
ViewResourcesMessage vrm = new ViewResourcesMessage ( player ) ;
vrm . setGuild ( player . getGuild ( ) ) ;
vrm . setGuild ( player . getGuild ( ) ) ;
vrm . setWarehouseBuilding ( warehouse ) ;
vrm . setWarehouseBuilding ( warehouseBuilding ) ;
vrm . configure ( ) ;
vrm . configure ( ) ;
dispatch = Dispatch . borrow ( player , vrm ) ;
dispatch = Dispatch . borrow ( player , vrm ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , Enum . DispatchChannel . SECONDARY ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , Enum . DispatchChannel . SECONDARY ) ;
}
} else
warehouse . lockedResourceTypes . add ( resourceType ) ;
return ;
return ;
}
}
EnumBitSet < Enum . ResourceType > bitSet = EnumBitSet . asEnumBitSet ( wh . lockedResourceTypes . toLong ( ) , Enum . ResourceType . class ) ;
boolean worked ;
warehouse . lockedResourceTypes . add ( resourceType ) ;
bitSet . add ( resourceType ) ;
worked = DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ;
if ( ! DbManager . WarehouseQueries . updateLocks ( wh , bitSet . toLong ( ) ) )
return ;
wh . lockedResourceTypes . add ( resourceType ) ;
if ( worked ) {
warehouse . lockedResourceTypes . add ( resourceType ) ;
ViewResourcesMessage vrm = new ViewResourcesMessage ( player ) ;
ViewResourcesMessage vrm = new ViewResourcesMessage ( player ) ;
vrm . setGuild ( player . getGuild ( ) ) ;
vrm . setGuild ( player . getGuild ( ) ) ;
vrm . setWarehouseBuilding ( warehouse ) ;
vrm . setWarehouseBuilding ( warehouseBuilding ) ;
vrm . configure ( ) ;
vrm . configure ( ) ;
dispatch = Dispatch . borrow ( player , vrm ) ;
dispatch = Dispatch . borrow ( player , vrm ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , Enum . DispatchChannel . SECONDARY ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , Enum . DispatchChannel . SECONDARY ) ;
} else
warehouse . lockedResourceTypes . remove ( resourceType ) ;
}
}
@ -252,11 +238,8 @@ public class Warehouse extends AbstractWorldObject {
int newAmount = oldAmount + amount ;
int newAmount = oldAmount + amount ;
if ( newAmount > Enum . ResourceType . resourceLookup . get ( resource . templateID ) . deposit_limit ) {
if ( newAmount > Enum . ResourceType . resourceLookup . get ( resource . templateID ) . deposit_limit )
//ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource.");
return false ;
return false ;
}
if ( removeFromInventory ) {
if ( removeFromInventory ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
@ -267,10 +250,8 @@ public class Warehouse extends AbstractWorldObject {
if ( itemMan . getGoldInventory ( ) . getNumOfItems ( ) - amount > MBServerStatics . PLAYER_GOLD_LIMIT )
if ( itemMan . getGoldInventory ( ) . getNumOfItems ( ) - amount > MBServerStatics . PLAYER_GOLD_LIMIT )
return false ;
return false ;
if ( ! itemMan . modifyInventoryGold ( - amount ) ) {
if ( ! itemMan . modifyInventoryGold ( - amount ) )
//ChatManager.chatSystemError(pc, "You do not have this Gold.");
return false ;
return false ;
}
UpdateGoldMsg ugm = new UpdateGoldMsg ( pc ) ;
UpdateGoldMsg ugm = new UpdateGoldMsg ( pc ) ;
ugm . configure ( ) ;
ugm . configure ( ) ;
@ -284,13 +265,19 @@ public class Warehouse extends AbstractWorldObject {
itemMan . updateInventory ( ) ;
itemMan . updateInventory ( ) ;
}
}
}
}
itemMan . updateInventory ( ) ;
itemMan . updateInventory ( ) ;
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
if ( newAmount > resourceType . deposit_limit )
return false ;
return false ;
warehouse . resources . put ( resourceType , newAmount ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( ! DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ) {
warehouse . resources . put ( resourceType , oldAmount ) ;
return false ;
}
if ( resource . template . item_type . equals ( Enum . ItemType . GOLD ) )
if ( resource . template . item_type . equals ( Enum . ItemType . GOLD ) )
resourceType = Enum . ResourceType . GOLD ;
resourceType = Enum . ResourceType . GOLD ;
else
else
@ -310,114 +297,30 @@ public class Warehouse extends AbstractWorldObject {
if ( newAmount > resourceType . deposit_limit )
if ( newAmount > resourceType . deposit_limit )
return false ;
return false ;
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return false ;
warehouse . resources . put ( resourceType , newAmount ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( ! DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ) {
warehouse . resources . put ( resourceType , oldAmount ) ;
return false ;
}
if ( mine ! = null )
if ( mine ! = null )
AddTransactionToWarehouse ( warehouse , Enum . GameObjectType . Building , mine . getBuildingID ( ) , Enum . TransactionType . MINE , resourceType , amount ) ;
AddTransactionToWarehouse ( warehouse , Enum . GameObjectType . Building , mine . getBuildingID ( ) , Enum . TransactionType . MINE , resourceType , amount ) ;
return true ;
return true ;
}
}
public static boolean DepositApproved ( Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
if ( newAmount > resourceType . deposit_limit )
return false ;
boolean worked = false ;
switch ( resourceType ) {
case GOLD :
worked = DbManager . WarehouseQueries . updateGold ( warehouse , newAmount ) ;
break ;
case STONE :
worked = DbManager . WarehouseQueries . updateStone ( warehouse , newAmount ) ;
break ;
case TRUESTEEL :
worked = DbManager . WarehouseQueries . updateTruesteel ( warehouse , newAmount ) ;
break ;
case IRON :
worked = DbManager . WarehouseQueries . updateIron ( warehouse , newAmount ) ;
break ;
case ADAMANT :
worked = DbManager . WarehouseQueries . updateAdamant ( warehouse , newAmount ) ;
break ;
case LUMBER :
worked = DbManager . WarehouseQueries . updateLumber ( warehouse , newAmount ) ;
break ;
case OAK :
worked = DbManager . WarehouseQueries . updateOak ( warehouse , newAmount ) ;
break ;
case BRONZEWOOD :
worked = DbManager . WarehouseQueries . updateBronzewood ( warehouse , newAmount ) ;
break ;
case MANDRAKE :
worked = DbManager . WarehouseQueries . updateMandrake ( warehouse , newAmount ) ;
break ;
case COAL :
worked = DbManager . WarehouseQueries . updateCoal ( warehouse , newAmount ) ;
break ;
case AGATE :
worked = DbManager . WarehouseQueries . updateAgate ( warehouse , newAmount ) ;
break ;
case DIAMOND :
worked = DbManager . WarehouseQueries . updateDiamond ( warehouse , newAmount ) ;
break ;
case ONYX :
worked = DbManager . WarehouseQueries . updateOnyx ( warehouse , newAmount ) ;
break ;
case AZOTH :
worked = DbManager . WarehouseQueries . updateAzoth ( warehouse , newAmount ) ;
break ;
case ORICHALK :
worked = DbManager . WarehouseQueries . updateOrichalk ( warehouse , newAmount ) ;
break ;
case ANTIMONY :
worked = DbManager . WarehouseQueries . updateAntimony ( warehouse , newAmount ) ;
break ;
case SULFUR :
worked = DbManager . WarehouseQueries . updateSulfur ( warehouse , newAmount ) ;
break ;
case QUICKSILVER :
worked = DbManager . WarehouseQueries . updateQuicksilver ( warehouse , newAmount ) ;
break ;
case GALVOR :
worked = DbManager . WarehouseQueries . updateGalvor ( warehouse , newAmount ) ;
break ;
case WORMWOOD :
worked = DbManager . WarehouseQueries . updateWormwood ( warehouse , newAmount ) ;
break ;
case OBSIDIAN :
worked = DbManager . WarehouseQueries . updateObsidian ( warehouse , newAmount ) ;
break ;
case BLOODSTONE :
worked = DbManager . WarehouseQueries . updateBloodstone ( warehouse , newAmount ) ;
break ;
case MITHRIL :
worked = DbManager . WarehouseQueries . updateMithril ( warehouse , newAmount ) ;
break ;
}
return worked ;
}
public static synchronized void depositRealmTaxes ( PlayerCharacter taxer , Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
public static synchronized void depositRealmTaxes ( PlayerCharacter taxer , Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
int newAmount = oldAmount + amount ;
warehouse . resources . put ( resourceType , newAmount ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( ! DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ) {
warehouse . resources . put ( resourceType , oldAmount ) ;
return ;
}
AddTransactionToWarehouse ( warehouse , taxer . getObjectType ( ) , taxer . getObjectUUID ( ) , Enum . TransactionType . TAXRESOURCEDEPOSIT , resourceType , amount ) ;
AddTransactionToWarehouse ( warehouse , taxer . getObjectType ( ) , taxer . getObjectUUID ( ) , Enum . TransactionType . TAXRESOURCEDEPOSIT , resourceType , amount ) ;
}
}
@ -433,18 +336,23 @@ public class Warehouse extends AbstractWorldObject {
if ( newAmount > resourceType . deposit_limit )
if ( newAmount > resourceType . deposit_limit )
return ;
return ;
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return ;
warehouse . resources . put ( resourceType , newAmount ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( ! DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ) {
warehouse . resources . put ( resourceType , oldAmount ) ;
return ;
}
if ( building ! = null )
if ( building ! = null )
AddTransactionToWarehouse ( warehouse , Enum . GameObjectType . Building , building . getObjectUUID ( ) , Enum . TransactionType . DEPOSIT , resourceType , amount ) ;
AddTransactionToWarehouse ( warehouse , Enum . GameObjectType . Building , building . getObjectUUID ( ) , Enum . TransactionType . DEPOSIT , resourceType , amount ) ;
}
}
public static boolean WithdrawApproved ( Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
public static synchronized boolean withdraw ( Warehouse warehouse , NPC npc , Enum . ResourceType resourceType , int amount , boolean transaction ) {
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount - amount ;
if ( warehouse . resources . get ( resourceType ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
return false ;
@ -452,98 +360,15 @@ public class Warehouse extends AbstractWorldObject {
if ( amount < = 0 )
if ( amount < = 0 )
return false ;
return false ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
if ( oldAmount < amount )
if ( oldAmount < amount )
return false ;
return false ;
int newAmount = oldAmount - amount ;
warehouse . resources . put ( resourceType , newAmount ) ;
boolean worked = false ;
switch ( resourceType ) {
case GOLD :
worked = DbManager . WarehouseQueries . updateGold ( warehouse , newAmount ) ;
break ;
case STONE :
worked = DbManager . WarehouseQueries . updateStone ( warehouse , newAmount ) ;
break ;
case TRUESTEEL :
worked = DbManager . WarehouseQueries . updateTruesteel ( warehouse , newAmount ) ;
break ;
case IRON :
worked = DbManager . WarehouseQueries . updateIron ( warehouse , newAmount ) ;
break ;
case ADAMANT :
worked = DbManager . WarehouseQueries . updateAdamant ( warehouse , newAmount ) ;
break ;
case LUMBER :
worked = DbManager . WarehouseQueries . updateLumber ( warehouse , newAmount ) ;
break ;
case OAK :
worked = DbManager . WarehouseQueries . updateOak ( warehouse , newAmount ) ;
break ;
case BRONZEWOOD :
worked = DbManager . WarehouseQueries . updateBronzewood ( warehouse , newAmount ) ;
break ;
case MANDRAKE :
worked = DbManager . WarehouseQueries . updateMandrake ( warehouse , newAmount ) ;
break ;
case COAL :
worked = DbManager . WarehouseQueries . updateCoal ( warehouse , newAmount ) ;
break ;
case AGATE :
worked = DbManager . WarehouseQueries . updateAgate ( warehouse , newAmount ) ;
break ;
case DIAMOND :
worked = DbManager . WarehouseQueries . updateDiamond ( warehouse , newAmount ) ;
break ;
case ONYX :
worked = DbManager . WarehouseQueries . updateOnyx ( warehouse , newAmount ) ;
break ;
case AZOTH :
worked = DbManager . WarehouseQueries . updateAzoth ( warehouse , newAmount ) ;
break ;
case ORICHALK :
worked = DbManager . WarehouseQueries . updateOrichalk ( warehouse , newAmount ) ;
break ;
case ANTIMONY :
worked = DbManager . WarehouseQueries . updateAntimony ( warehouse , newAmount ) ;
break ;
case SULFUR :
worked = DbManager . WarehouseQueries . updateSulfur ( warehouse , newAmount ) ;
break ;
case QUICKSILVER :
worked = DbManager . WarehouseQueries . updateQuicksilver ( warehouse , newAmount ) ;
break ;
case GALVOR :
worked = DbManager . WarehouseQueries . updateGalvor ( warehouse , newAmount ) ;
break ;
case WORMWOOD :
worked = DbManager . WarehouseQueries . updateWormwood ( warehouse , newAmount ) ;
break ;
case OBSIDIAN :
worked = DbManager . WarehouseQueries . updateObsidian ( warehouse , newAmount ) ;
break ;
case BLOODSTONE :
worked = DbManager . WarehouseQueries . updateBloodstone ( warehouse , newAmount ) ;
break ;
case MITHRIL :
worked = DbManager . WarehouseQueries . updateMithril ( warehouse , newAmount ) ;
break ;
}
return worked ;
}
public static synchronized boolean withdraw ( Warehouse warehouse , NPC npc , Enum . ResourceType resourceType , int amount , boolean transaction ) {
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount - amount ;
if ( ! WithdrawApproved ( resourceType , amount , warehouse ) )
if ( ! DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ) {
warehouse . resources . put ( resourceType , oldAmount ) ;
return false ;
return false ;
}
warehouse . resources . put ( resourceType , newAmount ) ;
if ( transaction )
if ( transaction )
AddTransactionToWarehouse ( warehouse , npc . getObjectType ( ) , npc . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , resourceType , amount ) ;
AddTransactionToWarehouse ( warehouse , npc . getObjectType ( ) , npc . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , resourceType , amount ) ;
@ -629,11 +454,12 @@ public class Warehouse extends AbstractWorldObject {
int newAmount = oldAmount - amount ;
int newAmount = oldAmount - amount ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( ! WithdrawApproved ( resourceType , amount , warehouse ) )
if ( ! DbManager . WarehouseQueries . updateWarehouse ( warehouse ) ) {
warehouse . resources . put ( resourceType , oldAmount ) ;
return false ;
return false ;
}
warehouse . resources . put ( resourceType , newAmount ) ;
if ( addToInventory ) {
if ( addToInventory ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
@ -782,41 +608,7 @@ public class Warehouse extends AbstractWorldObject {
public void updateDatabase ( ) {
public void updateDatabase ( ) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
@Override
public void runAfterLoad ( ) {
try {
Building warehouseBuilding = BuildingManager . getBuilding ( this . buildingUID ) ;
Logger . info ( "configuring warehouse " + UID + " for city " + warehouseBuilding . getCity ( ) . getCityName ( ) + " structure UUID " + this . buildingUID ) ;
//Building is gone, but Warehouse still in DB?? Should never happen, sanity check anyway.
if ( warehouseBuilding = = null ) {
Logger . error ( "Failed to load Building for Warehouse" ) ;
return ;
}
Zone cityZone = warehouseBuilding . getParentZone ( ) ;
if ( cityZone = = null ) {
Logger . error ( "Failed to load Zone for Warehouse with UUID " + this . getObjectUUID ( ) ) ;
return ;
}
City city = City . getCity ( cityZone . playerCityUUID ) ;
if ( city = = null ) {
Logger . error ( "Failed to load City for Warehouse with UUID " + this . getObjectUUID ( ) ) ;
return ;
}
warehouseByBuildingUUID . put ( this . buildingUID , this ) ;
city . setWarehouseBuildingID ( this . buildingUID ) ;
} catch ( Exception E ) {
Logger . info ( this . getObjectUUID ( ) + " failed" ) ;
}
}
}
}
}