@ -34,7 +34,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -34,7 +34,7 @@ public class Warehouse extends AbstractWorldObject {
public int UID ;
public int buildingUID ;
public ArrayList < Transaction > transactions = new ArrayList < > ( ) ;
public ConcurrentHashMap < ItemBas e, Integer > resources = new ConcurrentHashMap < > ( ) ;
public ConcurrentHashMap < Enum . ResourceTyp e, Integer > resources = new ConcurrentHashMap < > ( ) ;
/ * *
@ -43,29 +43,29 @@ public class Warehouse extends AbstractWorldObject {
@@ -43,29 +43,29 @@ public class Warehouse extends AbstractWorldObject {
public Warehouse ( ResultSet rs ) throws SQLException {
super ( rs ) ;
this . UID = rs . getInt ( "UID" ) ;
this . resources . put ( ItemBase . getItemBase ( 1580000 ) , rs . getInt ( "warehouse_stone" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580001 ) , rs . getInt ( "warehouse_truesteel" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580002 ) , rs . getInt ( "warehouse_iron" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580003 ) , rs . getInt ( "warehouse_adamant" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580004 ) , rs . getInt ( "warehouse_lumber" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580005 ) , rs . getInt ( "warehouse_oak" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580006 ) , rs . getInt ( "warehouse_bronzewood" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580007 ) , rs . getInt ( "warehouse_mandrake" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580008 ) , rs . getInt ( "warehouse_coal" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580009 ) , rs . getInt ( "warehouse_agate" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580010 ) , rs . getInt ( "warehouse_diamond" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580011 ) , rs . getInt ( "warehouse_onyx" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580012 ) , rs . getInt ( "warehouse_azoth" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580013 ) , rs . getInt ( "warehouse_orichalk" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580014 ) , rs . getInt ( "warehouse_antimony" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580015 ) , rs . getInt ( "warehouse_sulfur" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580016 ) , rs . getInt ( "warehouse_quicksilver" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580017 ) , rs . getInt ( "warehouse_galvor" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580018 ) , rs . getInt ( "warehouse_wormwood" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580019 ) , rs . getInt ( "warehouse_obsidian" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580020 ) , rs . getInt ( "warehouse_bloodstone" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 1580021 ) , rs . getInt ( "warehouse_mithril" ) ) ;
this . resources . put ( ItemBase . getItemBase ( 7 ) , rs . getInt ( "warehouse_gold" ) ) ;
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 ) ;
@ -133,24 +133,15 @@ public class Warehouse extends AbstractWorldObject {
@@ -133,24 +133,15 @@ public class Warehouse extends AbstractWorldObject {
if ( warehouse = = null )
return ;
int hashID = msg . getHashID ( ) ;
int itemBaseID = ItemBase . getItemHashIDMap ( ) . get ( hashID ) ;
ItemBase ib = ItemBase . getItemBase ( itemBaseID ) ;
Enum . ResourceType resourceType = Enum . ResourceType . hashLookup . get ( msg . getHashID ( ) ) ;
if ( ib = = null ) {
Logger . debug ( "Failed to find Resource ItemBaseID with Hash ID = " + hashID ) ;
return ;
}
ItemTemplate template = ItemTemplate . itemTemplates . get ( itemBaseID ) ;
if ( isResourceLocked ( warehouse , ib ) ) {
if ( isResourceLocked ( warehouse , resourceType ) ) {
ChatManager . chatSystemInfo ( player , "You cannot withdrawl a locked resource." ) ;
return ;
}
if ( ! withdraw ( warehouse , player , ib , withdrawAmount , true , true ) ) {
ChatManager . chatGuildError ( player , "Failed to withdrawl " + template . item_base_name + '.' ) ;
Logger . debug ( player . getName ( ) + " Failed to withdrawl =" + template . item_base_name + " from Warehouse With ID = " + warehouseBuilding . getObjectUUID ( ) ) ;
if ( ! withdraw ( warehouse , player , resourceType , withdrawAmount , true , true ) ) {
ChatManager . chatGuildError ( player , "Failed to withdrawl " + resourceType . name ( ) + '.' ) ;
Logger . debug ( player . getName ( ) + " Failed to withdrawl =" + resourceType . name ( ) + " from Warehouse With ID = " + warehouseBuilding . getObjectUUID ( ) ) ;
return ;
}
@ -183,7 +174,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -183,7 +174,7 @@ public class Warehouse extends AbstractWorldObject {
Enum . ResourceType resourceType = Enum . ResourceType . hashLookup . get ( hashID ) ;
if ( isResourceLocked ( wh , ItemBase . getItemBase ( resourceType . templateID ) ) ) {
if ( isResourceLocked ( wh , resourceType ) ) {
boolean worked ;
EnumBitSet < Enum . ResourceType > bitSet = EnumBitSet . asEnumBitSet ( wh . lockedResourceTypes . toLong ( ) , Enum . ResourceType . class ) ;
@ -223,6 +214,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -223,6 +214,7 @@ public class Warehouse extends AbstractWorldObject {
public static synchronized boolean deposit ( PlayerCharacter pc , Item resource , int amount , boolean removeFromInventory , boolean transaction , Warehouse warehouse ) {
ClientConnection origin = pc . getClientConnection ( ) ;
if ( origin = = null )
return false ;
@ -231,12 +223,9 @@ public class Warehouse extends AbstractWorldObject {
@@ -231,12 +223,9 @@ public class Warehouse extends AbstractWorldObject {
return false ;
}
ItemBase ib = resource . getItemBase ( ) ;
Enum . ResourceType resourceType = Enum . ResourceType . resourceLookup . get ( resource . templsteID ) ;
if ( ib = = null )
return false ;
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
CharacterItemManager itemMan = pc . getCharItemManager ( ) ;
@ -244,7 +233,6 @@ public class Warehouse extends AbstractWorldObject {
@@ -244,7 +233,6 @@ public class Warehouse extends AbstractWorldObject {
if ( itemMan = = null )
return false ;
if ( itemMan . getGoldTrading ( ) > 0 ) {
ErrorPopupMsg . sendErrorPopup ( pc , 195 ) ;
return false ;
@ -259,7 +247,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -259,7 +247,7 @@ public class Warehouse extends AbstractWorldObject {
if ( resource . getNumOfItems ( ) < amount )
return false ;
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
@ -270,7 +258,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -270,7 +258,7 @@ public class Warehouse extends AbstractWorldObject {
if ( removeFromInventory ) {
if ( ib . getUUID ( ) = = 7 ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
if ( itemMan . getGoldInventory ( ) . getNumOfItems ( ) - amount < 0 )
return false ;
@ -297,12 +285,10 @@ public class Warehouse extends AbstractWorldObject {
@@ -297,12 +285,10 @@ public class Warehouse extends AbstractWorldObject {
}
itemMan . updateInventory ( ) ;
if ( ! DepositApproved ( ib , amount , warehouse ) )
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return false ;
warehouse . resources . put ( ib , newAmount ) ;
Enum . ResourceType resourceType ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( resource . template . item_type . equals ( Enum . ItemType . GOLD ) )
resourceType = Enum . ResourceType . GOLD ;
@ -315,26 +301,18 @@ public class Warehouse extends AbstractWorldObject {
@@ -315,26 +301,18 @@ public class Warehouse extends AbstractWorldObject {
return true ;
}
public static synchronized boolean depositFromMine ( Mine mine , ItemBase resourc e, int amount , Warehouse warehouse ) {
public static synchronized boolean depositFromMine ( Mine mine , Enum . ResourceType resourceTyp e, int amount , Warehouse warehouse ) {
int oldAmount = warehouse . resources . get ( resource ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
if ( newAmount > Enum . ResourceType . resourceLookup . get ( resource . getUUID ( ) ) . deposit_limit )
if ( newAmount > resourceType . deposit_limit )
return false ;
if ( ! DepositApproved ( resource , amount , warehouse ) )
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return false ;
warehouse . resources . put ( resource , newAmount ) ;
Enum . ResourceType resourceType ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( resource . getUUID ( ) ) ;
if ( resource . getUUID ( ) = = 7 )
resourceType = Enum . ResourceType . GOLD ;
else
resourceType = Enum . ResourceType . valueOf ( template . item_base_name . toUpperCase ( ) ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( mine ! = null )
AddTransactionToWarehouse ( warehouse , Enum . GameObjectType . Building , mine . getBuildingID ( ) , Enum . TransactionType . MINE , resourceType , amount ) ;
@ -342,262 +320,229 @@ public class Warehouse extends AbstractWorldObject {
@@ -342,262 +320,229 @@ public class Warehouse extends AbstractWorldObject {
return true ;
}
public static boolean DepositApproved ( ItemBase ib , int amount , Warehouse warehouse ) {
if ( ib = = null )
return false ;
public static boolean DepositApproved ( Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
if ( newAmount > Enum . ResourceType . resourceLookup . get ( ib . getUUID ( ) ) . deposit_limit )
if ( newAmount > resourceType . deposit_limit )
return false ;
int itemID = ib . getUUID ( ) ;
boolean worked = false ;
switch ( itemID ) {
case 7 :
switch ( resourceType ) {
case GOLD :
worked = DbManager . WarehouseQueries . updateGold ( warehouse , newAmount ) ;
break ;
case 1580000 :
case STONE :
worked = DbManager . WarehouseQueries . updateStone ( warehouse , newAmount ) ;
break ;
case 1580001 :
case TRUESTEEL :
worked = DbManager . WarehouseQueries . updateTruesteel ( warehouse , newAmount ) ;
break ;
case 1580002 :
case IRON :
worked = DbManager . WarehouseQueries . updateIron ( warehouse , newAmount ) ;
break ;
case 1580003 :
case ADAMANT :
worked = DbManager . WarehouseQueries . updateAdamant ( warehouse , newAmount ) ;
break ;
case 1580004 :
case LUMBER :
worked = DbManager . WarehouseQueries . updateLumber ( warehouse , newAmount ) ;
break ;
case 1580005 :
case OAK :
worked = DbManager . WarehouseQueries . updateOak ( warehouse , newAmount ) ;
break ;
case 1580006 :
case BRONZEWOOD :
worked = DbManager . WarehouseQueries . updateBronzewood ( warehouse , newAmount ) ;
break ;
case 1580007 :
case MANDRAKE :
worked = DbManager . WarehouseQueries . updateMandrake ( warehouse , newAmount ) ;
break ;
case 1580008 :
case COAL :
worked = DbManager . WarehouseQueries . updateCoal ( warehouse , newAmount ) ;
break ;
case 1580009 :
case AGATE :
worked = DbManager . WarehouseQueries . updateAgate ( warehouse , newAmount ) ;
break ;
case 1580010 :
case DIAMOND :
worked = DbManager . WarehouseQueries . updateDiamond ( warehouse , newAmount ) ;
break ;
case 1580011 :
case ONYX :
worked = DbManager . WarehouseQueries . updateOnyx ( warehouse , newAmount ) ;
break ;
case 1580012 :
case AZOTH :
worked = DbManager . WarehouseQueries . updateAzoth ( warehouse , newAmount ) ;
break ;
case 1580013 :
case ORICHALK :
worked = DbManager . WarehouseQueries . updateOrichalk ( warehouse , newAmount ) ;
break ;
case 1580014 :
case ANTIMONY :
worked = DbManager . WarehouseQueries . updateAntimony ( warehouse , newAmount ) ;
break ;
case 1580015 :
case SULFUR :
worked = DbManager . WarehouseQueries . updateSulfur ( warehouse , newAmount ) ;
break ;
case 1580016 :
case QUICKSILVER :
worked = DbManager . WarehouseQueries . updateQuicksilver ( warehouse , newAmount ) ;
break ;
case 1580017 :
case GALVOR :
worked = DbManager . WarehouseQueries . updateGalvor ( warehouse , newAmount ) ;
break ;
case 1580018 :
case WORMWOOD :
worked = DbManager . WarehouseQueries . updateWormwood ( warehouse , newAmount ) ;
break ;
case 1580019 :
case OBSIDIAN :
worked = DbManager . WarehouseQueries . updateObsidian ( warehouse , newAmount ) ;
break ;
case 1580020 :
case BLOODSTONE :
worked = DbManager . WarehouseQueries . updateBloodstone ( warehouse , newAmount ) ;
break ;
case 1580021 :
case MITHRIL :
worked = DbManager . WarehouseQueries . updateMithril ( warehouse , newAmount ) ;
break ;
}
return worked ;
}
public static synchronized void depositRealmTaxes ( PlayerCharacter taxer , ItemBase ib , int amount , Warehouse warehouse ) {
public static synchronized void depositRealmTaxes ( PlayerCharacter taxer , Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
if ( ! DepositApproved ( ib , amount , warehouse ) )
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return ;
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
warehouse . resources . put ( ib , newAmount ) ;
Enum . ResourceType resourceType ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( ib . getUUID ( ) ) ;
if ( ib . getUUID ( ) = = 7 )
resourceType = Enum . ResourceType . GOLD ;
else
resourceType = Enum . ResourceType . valueOf ( template . item_base_name . toUpperCase ( ) ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
AddTransactionToWarehouse ( warehouse , taxer . getObjectType ( ) , taxer . getObjectUUID ( ) , Enum . TransactionType . TAXRESOURCEDEPOSIT , resourceType , amount ) ;
}
public static synchronized void depositProfitTax ( ItemBase ib , int amount , Building building , Warehouse warehouse ) {
if ( ib = = null )
return ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( ib . getUUID ( ) ) ;
public static synchronized void depositProfitTax ( Enum . ResourceType resourceType , int amount , Building building , Warehouse warehouse ) {
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return ;
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount + amount ;
if ( newAmount > Enum . ResourceType . resourceLookup . get ( ib . getUUID ( ) ) . deposit_limit )
if ( newAmount > resourceType . deposit_limit )
return ;
if ( ! DepositApproved ( ib , amount , warehouse ) )
if ( ! DepositApproved ( resourceType , amount , warehouse ) )
return ;
warehouse . resources . put ( ib , newAmount ) ;
Enum . ResourceType resourceType ;
if ( ib . getUUID ( ) = = 7 )
resourceType = Enum . ResourceType . GOLD ;
else
resourceType = Enum . ResourceType . valueOf ( template . item_base_name . toUpperCase ( ) ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( building ! = null )
AddTransactionToWarehouse ( warehouse , Enum . GameObjectType . Building , building . getObjectUUID ( ) , Enum . TransactionType . DEPOSIT , resourceType , amount ) ;
}
public static boolean WithdrawApproved ( ItemBase ib , int amount , Warehouse warehouse ) {
public static boolean WithdrawApproved ( Enum . ResourceType resourceType , int amount , Warehouse warehouse ) {
if ( ib = = null )
return false ;
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
if ( amount < = 0 )
return false ;
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
if ( oldAmount < amount )
return false ;
Enum . ResourceType resourceType = Enum . ResourceType . resourceLookup . get ( ib . getUUID ( ) ) ;
int hashID = resourceType . hash ;
int newAmount = oldAmount - amount ;
boolean worked = false ;
switch ( hashID ) {
case 2308551 :
switch ( resourceType ) {
case GOLD :
worked = DbManager . WarehouseQueries . updateGold ( warehouse , newAmount ) ;
break ;
case 74856115 :
case STONE :
worked = DbManager . WarehouseQueries . updateStone ( warehouse , newAmount ) ;
break ;
case - 317484979 :
case TRUESTEEL :
worked = DbManager . WarehouseQueries . updateTruesteel ( warehouse , newAmount ) ;
break ;
case 2504297 :
case IRON :
worked = DbManager . WarehouseQueries . updateIron ( warehouse , newAmount ) ;
break ;
case - 1741189964 :
case ADAMANT :
worked = DbManager . WarehouseQueries . updateAdamant ( warehouse , newAmount ) ;
break ;
case - 1603256692 :
case LUMBER :
worked = DbManager . WarehouseQueries . updateLumber ( warehouse , newAmount ) ;
break ;
case 74767 :
case OAK :
worked = DbManager . WarehouseQueries . updateOak ( warehouse , newAmount ) ;
break ;
case 1334770447 :
case BRONZEWOOD :
worked = DbManager . WarehouseQueries . updateBronzewood ( warehouse , newAmount ) ;
break ;
case 1191391799 :
case MANDRAKE :
worked = DbManager . WarehouseQueries . updateMandrake ( warehouse , newAmount ) ;
break ;
case 2559427 :
case COAL :
worked = DbManager . WarehouseQueries . updateCoal ( warehouse , newAmount ) ;
break ;
case 75173057 :
case AGATE :
worked = DbManager . WarehouseQueries . updateAgate ( warehouse , newAmount ) ;
break ;
case - 1730704107 :
case DIAMOND :
worked = DbManager . WarehouseQueries . updateDiamond ( warehouse , newAmount ) ;
break ;
case 2977263 :
case ONYX :
worked = DbManager . WarehouseQueries . updateOnyx ( warehouse , newAmount ) ;
break ;
case 78329697 :
case AZOTH :
worked = DbManager . WarehouseQueries . updateAzoth ( warehouse , newAmount ) ;
break ;
case - 2036290524 :
case ORICHALK :
worked = DbManager . WarehouseQueries . updateOrichalk ( warehouse , newAmount ) ;
break ;
case 452320058 :
case ANTIMONY :
worked = DbManager . WarehouseQueries . updateAntimony ( warehouse , newAmount ) ;
break ;
case - 1586349421 :
case SULFUR :
worked = DbManager . WarehouseQueries . updateSulfur ( warehouse , newAmount ) ;
break ;
case - 472884509 :
case QUICKSILVER :
worked = DbManager . WarehouseQueries . updateQuicksilver ( warehouse , newAmount ) ;
break ;
case - 1596311545 :
case GALVOR :
worked = DbManager . WarehouseQueries . updateGalvor ( warehouse , newAmount ) ;
break ;
case 1532478436 :
case WORMWOOD :
worked = DbManager . WarehouseQueries . updateWormwood ( warehouse , newAmount ) ;
break ;
case - 697973233 :
case OBSIDIAN :
worked = DbManager . WarehouseQueries . updateObsidian ( warehouse , newAmount ) ;
break ;
case - 1569826353 :
case BLOODSTONE :
worked = DbManager . WarehouseQueries . updateBloodstone ( warehouse , newAmount ) ;
break ;
case - 1761257186 :
case MITHRIL :
worked = DbManager . WarehouseQueries . updateMithril ( warehouse , newAmount ) ;
break ;
}
return worked ;
}
public static synchronized boolean withdraw ( Warehouse warehouse , NPC npc , ItemBase ib , int amount , boolean transaction ) {
public static synchronized boolean withdraw ( Warehouse warehouse , NPC npc , Enum . ResourceType resourceType , int amount , boolean transaction ) {
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
int newAmount = oldAmount - amount ;
if ( ! WithdrawApproved ( ib , amount , warehouse ) )
if ( ! WithdrawApproved ( resourceType , amount , warehouse ) )
return false ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( ib . getUUID ( ) ) ;
warehouse . resources . put ( ib , newAmount ) ;
Enum . ResourceType resourceType ;
if ( ib . getUUID ( ) = = 7 )
resourceType = Enum . ResourceType . GOLD ;
else
resourceType = Enum . ResourceType . valueOf ( template . item_base_name . toUpperCase ( ) ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( transaction )
AddTransactionToWarehouse ( warehouse , npc . getObjectType ( ) , npc . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , resourceType , amount ) ;
@ -607,27 +552,22 @@ public class Warehouse extends AbstractWorldObject {
@@ -607,27 +552,22 @@ public class Warehouse extends AbstractWorldObject {
public static synchronized void transferResources ( Warehouse warehouse , PlayerCharacter taxer , TaxResourcesMsg msg , ArrayList < Integer > realmResources , float taxPercent ) {
for ( int ibID : realmResources ) {
ItemBase ib = ItemBase . getItemBase ( ibID ) ;
if ( ib = = null )
return ;
for ( int templateID : realmResources ) {
ItemTemplate template = ItemTemplate . itemTemplates . get ( ib . getUUID ( ) ) ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( templateID ) ;
Enum . ResourceType resourceType = Enum . ResourceType . resourceLookup . get ( templateID ) ;
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return ;
int amount = ( int ) ( warehouse . resources . get ( ib ) * taxPercent ) ;
int amount = ( int ) ( warehouse . resources . get ( resourceType ) * taxPercent ) ;
if ( amount < = 0 ) {
Enum . ResourceType resourceType = Enum . ResourceType . resourceLookup . get ( ib . getUUID ( ) ) ;
msg . getResources ( ) . put ( resourceType . hash , 0 ) ;
continue ;
}
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
if ( oldAmount < amount )
amount = oldAmount ;
@ -637,17 +577,15 @@ public class Warehouse extends AbstractWorldObject {
@@ -637,17 +577,15 @@ public class Warehouse extends AbstractWorldObject {
if ( newAmount < amount )
continue ;
Enum . ResourceType resourceType = Enum . ResourceType . resourceLookup . get ( ib . getUUID ( ) ) ;
if ( ! WithdrawApproved ( ib , amount , warehouse ) ) {
if ( ! WithdrawApproved ( resourceType , amount , warehouse ) ) {
msg . getResources ( ) . put ( resourceType . hash , 0 ) ;
continue ;
}
msg . getResources ( ) . put ( resourceType . hash , amount ) ;
warehouse . resources . put ( ib , newAmount ) ;
depositRealmTaxes ( taxer , ib , amount , warehouse ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
depositRealmTaxes ( taxer , resourceType , amount , warehouse ) ;
Enum . ResourceType resource ;
if ( resourceType . equals ( Enum . ResourceType . GOLD ) )
@ -660,17 +598,14 @@ public class Warehouse extends AbstractWorldObject {
@@ -660,17 +598,14 @@ public class Warehouse extends AbstractWorldObject {
}
}
public static synchronized boolean withdraw ( Warehouse warehouse , PlayerCharacter pc , ItemBase ib , int amount , boolean addToInventory , boolean transaction ) {
public static synchronized boolean withdraw ( Warehouse warehouse , PlayerCharacter pc , Enum . ResourceType resourceType , int amount , boolean addToInventory , boolean transaction ) {
if ( pc = = null )
return false ;
if ( ib = = null )
return false ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( ib . getUUID ( ) ) ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( resourceType . templateID ) ;
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
if ( amount < = 0 )
@ -687,15 +622,14 @@ public class Warehouse extends AbstractWorldObject {
@@ -687,15 +622,14 @@ public class Warehouse extends AbstractWorldObject {
return false ;
}
if ( addToInventory & & ib . getUUID ( ) = = ItemBase . GOLD_BASE_ID ) {
if ( pc . getCharItemManager ( ) . getGoldInventory ( ) . getNumOfItems ( ) + amount > MBServerStatics . PLAYER_GOLD_LIMIT ) {
if ( addToInventory & & resourceType . equals ( Enum . ResourceType . GOLD ) ) {
if ( pc . getCharItemManager ( ) . getGoldInventory ( ) . getNumOfItems ( ) + amount > MBServerStatics . PLAYER_GOLD_LIMIT )
return false ;
}
if ( pc . getCharItemManager ( ) . getGoldInventory ( ) . getNumOfItems ( ) + amount < 0 )
return false ;
}
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
if ( oldAmount < amount )
return false ;
@ -703,13 +637,13 @@ public class Warehouse extends AbstractWorldObject {
@@ -703,13 +637,13 @@ public class Warehouse extends AbstractWorldObject {
int newAmount = oldAmount - amount ;
if ( ! WithdrawApproved ( ib , amount , warehouse ) )
if ( ! WithdrawApproved ( resourceType , amount , warehouse ) )
return false ;
warehouse . resources . put ( ib , newAmount ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( addToInventory ) {
if ( ib . getUUID ( ) = = 7 ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
itemMan . addGoldToInventory ( amount , false ) ;
UpdateGoldMsg ugm = new UpdateGoldMsg ( pc ) ;
@ -721,7 +655,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -721,7 +655,7 @@ public class Warehouse extends AbstractWorldObject {
} else {
boolean itemWorked = false ;
Item item = new Item ( ib . getUUID ( ) ) ;
Item item = new Item ( resourceType . templateID ) ;
item . ownerID = pc . getObjectUUID ( ) ;
item . ownerType = Enum . OwnerType . PlayerCharacter ;
item . containerType = Enum . ItemContainerType . INVENTORY ;
@ -739,12 +673,6 @@ public class Warehouse extends AbstractWorldObject {
@@ -739,12 +673,6 @@ public class Warehouse extends AbstractWorldObject {
}
}
}
Enum . ResourceType resourceType ;
if ( ib . getUUID ( ) = = 7 )
resourceType = Enum . ResourceType . GOLD ;
else
resourceType = Enum . ResourceType . valueOf ( template . item_base_name . toUpperCase ( ) ) ;
if ( transaction )
AddTransactionToWarehouse ( warehouse , pc . getObjectType ( ) , pc . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , resourceType , amount ) ;
@ -752,17 +680,17 @@ public class Warehouse extends AbstractWorldObject {
@@ -752,17 +680,17 @@ public class Warehouse extends AbstractWorldObject {
return true ;
}
public static synchronized boolean loot ( Warehouse warehouse , PlayerCharacter pc , ItemBase ib , int amount , boolean addToInventory ) {
public static synchronized boolean loot ( Warehouse warehouse , PlayerCharacter pc , Enum . ResourceType resourceType , int amount , boolean addToInventory ) {
if ( pc = = null )
return false ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( ib . getUUID ( ) ) ;
ItemTemplate template = ItemTemplate . itemTemplates . get ( resourceType ) ;
if ( template = = null )
return false ;
if ( warehouse . resources . get ( ib ) = = null )
if ( warehouse . resources . get ( resourceType ) = = null )
return false ;
if ( amount < = 0 )
@ -778,17 +706,17 @@ public class Warehouse extends AbstractWorldObject {
@@ -778,17 +706,17 @@ public class Warehouse extends AbstractWorldObject {
return false ;
}
int oldAmount = warehouse . resources . get ( ib ) ;
int oldAmount = warehouse . resources . get ( resourceType ) ;
if ( oldAmount < amount )
return false ;
int newAmount = oldAmount - amount ;
warehouse . resources . put ( ib , newAmount ) ;
warehouse . resources . put ( resourceType , newAmount ) ;
if ( addToInventory ) {
if ( ib . getUUID ( ) = = 7 ) {
if ( resourceType . equals ( Enum . ResourceType . GOLD ) ) {
itemMan . addGoldToInventory ( amount , false ) ;
UpdateGoldMsg ugm = new UpdateGoldMsg ( pc ) ;
@ -799,7 +727,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -799,7 +727,7 @@ public class Warehouse extends AbstractWorldObject {
itemMan . updateInventory ( ) ;
} else {
boolean itemWorked = false ;
Item item = new Item ( ib . getUUID ( ) ) ;
Item item = new Item ( resourceType . templateID ) ;
item . ownerID = pc . getObjectUUID ( ) ;
item . ownerType = Enum . OwnerType . PlayerCharacter ;
item . containerType = Enum . ItemContainerType . INVENTORY ;
@ -851,12 +779,7 @@ public class Warehouse extends AbstractWorldObject {
@@ -851,12 +779,7 @@ public class Warehouse extends AbstractWorldObject {
}
public static boolean isResourceLocked ( Warehouse warehouse , ItemBase itemBase ) {
Enum . ResourceType resourceType ;
resourceType = Enum . ResourceType . resourceLookup . get ( itemBase . getUUID ( ) ) ;
public static boolean isResourceLocked ( Warehouse warehouse , Enum . ResourceType resourceType ) {
return resourceType . elementOf ( warehouse . lockedResourceTypes ) ;
}