2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects ;
import engine.Enum ;
import engine.Enum.ItemContainerType ;
import engine.Enum.ItemType ;
import engine.Enum.OwnerType ;
2023-02-24 09:48:15 -05:00
import engine.gameManager.* ;
2023-08-07 12:12:52 -04:00
import engine.loot.ModTableEntry ;
import engine.loot.ModTypeTableEntry ;
2022-04-30 09:41:17 -04:00
import engine.net.ItemProductionManager ;
import engine.net.ItemQueue ;
import engine.net.client.ClientConnection ;
import engine.net.client.msg.ErrorPopupMsg ;
import engine.powers.EffectsBase ;
import engine.server.MBServerStatics ;
import org.joda.time.DateTime ;
import org.pmw.tinylog.Logger ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ThreadLocalRandom ;
public class ItemFactory {
2024-03-03 15:06:44 -05:00
public static void fillInventory ( PlayerCharacter pc , int templateID , int count ) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( pc == null )
return ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
int max = 20 ;
CharacterItemManager itemManager = pc . getCharItemManager ();
2024-03-03 15:06:44 -05:00
ItemTemplate template = ItemTemplate . itemTemplates . get ( templateID );
2023-07-15 09:23:48 -04:00
if ( count > max )
count = max ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ClientConnection cc = pc . getClientConnection ();
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
if ( itemManager == null || template == null || cc == null )
2023-07-15 09:23:48 -04:00
return ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
boolean worked ;
2024-03-03 15:06:44 -05:00
2023-07-15 09:23:48 -04:00
for ( int i = 0 ; i < count ; i ++ ) {
worked = false ;
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
if ( ! itemManager . hasRoomInventory ( template . item_wt )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
ChatManager . chatSystemInfo ( pc , "You can not carry any more of that item." );
break ;
}
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
Item item = new Item ( templateID );
2024-03-02 11:07:07 -05:00
item . ownerID = pc . getObjectUUID ();
item . ownerType = OwnerType . PlayerCharacter ;
item . containerType = ItemContainerType . INVENTORY ;
2023-07-15 09:23:48 -04:00
try {
2024-03-02 09:55:30 -05:00
item = DbManager . ItemQueries . PERSIST ( item );
2023-07-15 09:23:48 -04:00
worked = true ;
} catch ( Exception e ) {
Logger . error ( e );
}
if ( worked ) {
itemManager . addItemToInventory ( item );
}
}
itemManager . updateInventory ();
}
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
public static Item fillForge ( NPC npc , PlayerCharacter pc , int itemsToRoll , int templateID , int pToken , int sToken , String customName ) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
String prefixString = "" ;
String suffixString = "" ;
if ( npc == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
boolean useWarehouse = false ;
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
ItemBase ib = ItemBase . getItemBase ( templateID );
ItemTemplate template = ItemTemplate . itemTemplates . get ( templateID );
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
if ( template == null )
2023-07-15 09:23:48 -04:00
return null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Building forge = npc . getBuilding ();
if ( forge == null )
return null ;
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
if ( ! npc . getCharItemManager (). hasRoomInventory ( template . item_wt )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
ErrorPopupMsg . sendErrorPopup ( pc , 21 );
return null ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Zone zone = npc . getBuilding (). getParentZone ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( zone == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-09-20 15:53:41 -04:00
City city = City . getCity ( zone . playerCityUUID );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( city == null )
return null ;
MobLoot ml = null ;
city . transactionLock . writeLock (). lock ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
try {
Warehouse cityWarehouse = city . getWarehouse ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( cityWarehouse != null && forge . assetIsProtected ())
useWarehouse = true ;
// ROLL BANE SCROLL.
2022-04-30 09:41:17 -04:00
2024-03-03 15:06:44 -05:00
if ( templateID > 910010 && templateID < 910019 ) {
2024-01-24 20:03:27 -06:00
ConcurrentHashMap < ItemBase , Integer > resources = cityWarehouse . resources ;
2022-04-30 09:41:17 -04:00
2024-03-03 13:18:16 -05:00
int buildingWithdraw = BuildingManager . GetWithdrawAmountForRolling ( forge , template . item_value );
int overdraft = BuildingManager . GetOverdraft ( forge , template . item_value );
2024-03-03 15:06:44 -05:00
2023-07-15 09:23:48 -04:00
if ( overdraft > 0 && ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + " " + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2022-04-30 09:41:17 -04:00
2024-01-24 20:21:41 -06:00
if ( overdraft > 0 && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( overdraft > resources . get ( ItemBase . GOLD_ITEM_BASE )) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + " " + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( ! forge . transferGold ( - buildingWithdraw , false )) {
overdraft += buildingWithdraw ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Building does not have enough gold to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
} else {
if ( overdraft > resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( overdraft > 0 )
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ItemBase . GOLD_ITEM_BASE , overdraft , true )) {
2024-02-28 16:31:09 -05:00
Logger . error ( "Warehouse With UID of " + cityWarehouse . UID + " Failed to Create Item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ml = new MobLoot ( npc , ib , false );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ml . containerType = Enum . ItemContainerType . FORGE ;
ml . setValue ( 0 );
ml . loadEnchantments ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
float time ;
float rank = npc . getBuilding (). getRank () - 1 ;
float rate = ( float ) ( 2 . 5 * rank );
time = ( 20 - rate );
time *= MBServerStatics . ONE_MINUTE ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( ml . getItemBase (). getUUID () > 910010 && ml . getItemBase (). getUUID () < 910019 ) {
2024-03-01 21:32:51 -05:00
rank = ml . getTemplsteID () - 910010 ;
2023-07-15 09:23:48 -04:00
time = rank * 60 * 60 * 3 * 1000 ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
// No job is submitted, as object's upgradetime field
// is used to determin whether or not an object has
// compelted rolling. The game object exists previously
// to this, not when 'compelte' is pressed.
long upgradeTime = System . currentTimeMillis () + ( long ) ( time * Float . parseFloat ( ConfigManager . MB_PRODUCTION_RATE . getValue ()));
DateTime dateTime = new DateTime ();
dateTime = dateTime . withMillis ( upgradeTime );
ml . setDateToUpgrade ( upgradeTime );
npc . addItemToForge ( ml );
int playerID = 0 ;
if ( pc != null )
playerID = pc . getObjectUUID ();
2024-03-01 21:32:51 -05:00
DbManager . NPCQueries . ADD_TO_PRODUCTION_LIST ( ml . getObjectUUID (), npc . getObjectUUID (), ml . getTemplsteID (), dateTime , "" , "" , "" , false , playerID );
ProducedItem pi = new ProducedItem ( ml . getObjectUUID (), npc . getObjectUUID (), ml . getTemplsteID (), dateTime , false , "" , "" , "" , playerID );
2023-07-15 09:23:48 -04:00
pi . setProducedItemID ( ml . getObjectUUID ());
pi . setAmount ( itemsToRoll );
pi . setRandom ( false );
ItemQueue produced = ItemQueue . borrow ( pi , ( long ) ( time * Float . parseFloat ( ConfigManager . MB_PRODUCTION_RATE . getValue ())));
ItemProductionManager . send ( produced );
return ml ;
}
int galvorAmount = 0 ;
int wormwoodAmount = 0 ;
int prefixCost = 0 ;
int suffixCost = 0 ;
2024-03-10 13:34:24 -04:00
if ( template . item_type . equals ( ItemType . WEAPON ) && ib . getPercentRequired () == 110 ) {
2024-03-10 14:10:51 -04:00
switch ( template . item_skill_used ) {
2023-07-15 09:23:48 -04:00
case "Bow" :
case "Crossbow" :
case "Spear" :
case "Pole Arm" :
case "Staff" :
wormwoodAmount = 20 ;
break ;
case "Axe" :
case "Dagger" :
case "Sword" :
case "Hammer" :
case "Unarmed Combat" :
if ( ib . isTwoHanded ())
galvorAmount = 20 ;
else
galvorAmount = 10 ;
break ;
}
}
ItemBase galvor = ItemBase . getItemBase ( 1580017 );
ItemBase wormwood = ItemBase . getItemBase ( 1580018 );
if ( galvorAmount > 0 || wormwoodAmount > 0 )
if ( ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "This item requires resources to roll! Please make sure the forge is protected to access the warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
if ( galvorAmount > 0 ) {
2024-01-24 20:21:41 -06:00
if ( Warehouse . isResourceLocked ( cityWarehouse , galvor )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Galvor is locked." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( cityWarehouse . resources . get ( galvor ) < galvorAmount ) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Galvor in warehouse to roll this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
if ( wormwoodAmount > 0 ) {
2024-01-24 20:21:41 -06:00
if ( Warehouse . isResourceLocked ( cityWarehouse , wormwood )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Wormwood is locked." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( cityWarehouse . resources . get ( wormwood ) < wormwoodAmount ) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Wormwood in warehouse to roll this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
ConcurrentHashMap < ItemBase , Integer > suffixResourceCosts = null ;
ConcurrentHashMap < ItemBase , Integer > prefixResourceCosts = null ;
EffectsBase prefix = null ;
if ( pToken != 0 ) {
if ( ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Forge cannot access warehouse! Check to make sure forge is protected." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
prefix = PowersManager . getEffectByToken ( pToken );
if ( prefix == null )
return null ;
EffectsBase prefixValue = PowersManager . getEffectByIDString ( prefix . getIDString () + 'A' );
if ( prefixValue == null )
return null ;
2024-03-03 13:18:16 -05:00
int baseCost = template . item_value ;
2023-07-15 09:23:48 -04:00
int effectCost = ( int ) prefixValue . getValue ();
int total = baseCost * 10 + effectCost ;
prefixCost = effectCost ;
int buildingWithdraw = BuildingManager . GetWithdrawAmountForRolling ( forge , total );
int overdraft = BuildingManager . GetOverdraft ( forge , total );
if ( overdraft > 0 && ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:21:41 -06:00
if ( overdraft > 0 && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( overdraft > cityWarehouse . resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
prefixResourceCosts = prefix . getResourcesForEffect ();
for ( ItemBase ibResources : prefixResourceCosts . keySet ()) {
2024-01-24 20:03:27 -06:00
int warehouseAmount = cityWarehouse . resources . get ( ibResources );
2023-07-15 09:23:48 -04:00
int creationAmount = prefixResourceCosts . get ( ibResources );
//ChatManager.chatInfoError(pc, "Prefix : " + ibResources.getName() + " / " + creationAmount);
if ( warehouseAmount < creationAmount ) {
//ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item.");
return null ;
}
}
}
EffectsBase suffix = null ;
if ( sToken != 0 ) {
if ( ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Forge cannot access warehouse! Check to make sure forge is protected." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
suffix = PowersManager . getEffectByToken ( sToken );
if ( suffix == null )
return null ;
EffectsBase suffixValue = PowersManager . getEffectByIDString ( suffix . getIDString () + 'A' );
if ( suffixValue == null )
return null ;
suffixResourceCosts = suffix . getResourcesForEffect ();
2024-03-03 13:18:16 -05:00
int baseCost = template . item_value ;
2023-07-15 09:23:48 -04:00
int effectCost = ( int ) suffixValue . getValue ();
suffixCost = effectCost ;
int total = baseCost * 10 + effectCost ;
// int buildingWithdraw = Building.GetWithdrawAmountForRolling(forge, total);
int overdraft = BuildingManager . GetOverdraft ( forge , total );
if ( overdraft > 0 && ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:21:41 -06:00
if ( overdraft > 0 && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( overdraft > cityWarehouse . resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
for ( ItemBase ibResources : suffixResourceCosts . keySet ()) {
2024-01-24 20:03:27 -06:00
int warehouseAmount = cityWarehouse . resources . get ( ibResources );
2023-07-15 09:23:48 -04:00
int creationAmount = suffixResourceCosts . get ( ibResources );
if ( warehouseAmount < creationAmount ) {
// if (pc != null)
// ChatManager.chatInfoError(pc, "You need at least " + creationAmount + " " + ibResources.getName() + " to Create this item.");
return null ;
}
}
}
//Check if Total suffix and prefix costs + itemCost can be withdrawn.
2024-03-03 13:18:16 -05:00
int costToCreate = suffixCost + prefixCost + template . item_value ;
2023-07-15 09:23:48 -04:00
int buildingWithdraw = BuildingManager . GetWithdrawAmountForRolling ( forge , costToCreate );
int overdraft = BuildingManager . GetOverdraft ( forge , costToCreate );
if ( overdraft > 0 && ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:21:41 -06:00
if ( overdraft > 0 && useWarehouse && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( useWarehouse && overdraft > cityWarehouse . resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
// if (pc != null){
// ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw);
// ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft);
//
// ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw));
// }
if ( ! forge . transferGold ( - buildingWithdraw , false )) {
overdraft += buildingWithdraw ;
if ( ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Building does not have enough gold to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
} else {
2024-01-24 20:03:27 -06:00
if ( overdraft > cityWarehouse . resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
if ( overdraft > 0 && useWarehouse )
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ItemBase . GOLD_ITEM_BASE , overdraft , true )) {
2023-07-15 09:23:48 -04:00
//ChatManager.chatGuildError(pc, "Failed to create Item");
2024-02-28 16:31:09 -05:00
Logger . error ( "Warehouse With UID of " + cityWarehouse . UID + " Failed to Create Item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
if ( prefix != null ) {
if ( ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Cannot Resource Roll without access to the warehouse! Make sure the forge is currently protected." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
for ( ItemBase ibResources : prefixResourceCosts . keySet ()) {
int creationAmount = prefixResourceCosts . get ( ibResources );
2024-01-24 20:21:41 -06:00
if ( Warehouse . isResourceLocked ( cityWarehouse , ibResources ) == true )
2023-07-15 09:23:48 -04:00
return null ;
2024-01-24 20:03:27 -06:00
int oldAmount = cityWarehouse . resources . get ( ibResources );
2023-07-15 09:23:48 -04:00
int amount = creationAmount ;
if ( oldAmount < amount )
amount = oldAmount ;
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ibResources , amount , true )) {
2023-07-15 09:23:48 -04:00
//ChatManager.chatGuildError(pc, "Failed to create Item");
2024-02-28 16:31:09 -05:00
Logger . error ( "Warehouse With UID of " + cityWarehouse . UID + " Failed to Create Item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
if ( suffix != null ) {
for ( ItemBase ibResources : suffixResourceCosts . keySet ()) {
int creationAmount = suffixResourceCosts . get ( ibResources );
2024-01-24 20:21:41 -06:00
if ( Warehouse . isResourceLocked ( cityWarehouse , ibResources ) == true ) {
2024-02-28 16:42:07 -05:00
ChatManager . chatSystemError ( pc , "Resource is locked!" + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
int oldAmount = cityWarehouse . resources . get ( ibResources );
2023-07-15 09:23:48 -04:00
int amount = creationAmount ;
if ( oldAmount < amount )
amount = oldAmount ;
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ibResources , amount , true )) {
2023-07-15 09:23:48 -04:00
//ChatManager.chatGuildError(pc, "Failed to create Item");
2024-02-28 16:31:09 -05:00
Logger . error ( "Warehouse With UID of " + cityWarehouse . UID + " Failed to Create Item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
if ( prefix == null && suffix == null ) {
2024-03-03 13:18:16 -05:00
int baseCost = template . item_value ;
2023-07-15 09:23:48 -04:00
int total = ( int ) ( baseCost + baseCost * ( float ) . 10 );
buildingWithdraw = BuildingManager . GetWithdrawAmountForRolling ( forge , total );
overdraft = BuildingManager . GetOverdraft ( forge , total );
if ( overdraft > 0 && ! useWarehouse ) {
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:21:41 -06:00
if ( overdraft > 0 && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( useWarehouse && overdraft > cityWarehouse . resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
if ( ! forge . transferGold ( - buildingWithdraw , false )) {
overdraft += buildingWithdraw ;
if ( ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Building does not have enough gold to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
} else {
2024-01-24 20:03:27 -06:00
if ( overdraft > cityWarehouse . resources . get ( ItemBase . GOLD_ITEM_BASE )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
if ( overdraft > 0 )
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ItemBase . GOLD_ITEM_BASE , overdraft , true )) {
2023-07-15 09:23:48 -04:00
//ChatManager.chatGuildError(pc, "Failed to create Item");
2024-02-28 16:31:09 -05:00
Logger . error ( "Warehouse With UID of " + cityWarehouse . UID + " Failed to Create Item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
// ChatManager.chatGuildInfo(pc, "Gold Cost = " + total);
if ( galvorAmount > 0 ) {
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , galvor , galvorAmount , true )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Failed to withdraw Galvor from warehouse!" + template . item_base_name );
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
}
if ( wormwoodAmount > 0 ) {
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , wormwood , wormwoodAmount , true )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Failed to withdraw Wormwood from warehouse!" + template . item_base_name );
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
}
ml = new MobLoot ( npc , ib , false );
ml . containerType = Enum . ItemContainerType . FORGE ;
ml . setName ( customName );
if ( prefix != null ) {
ml . addPermanentEnchantment ( prefix . getIDString (), 0 , 0 , true );
ml . setPrefix ( prefix . getIDString ());
prefixString = prefix . getIDString ();
}
if ( suffix != null ) {
ml . addPermanentEnchantment ( suffix . getIDString (), 0 , 0 , false );
ml . setSuffix ( suffix . getIDString ());
suffixString = suffix . getIDString ();
}
ml . loadEnchantments ();
//set value to 0 so magicvalue can be recalculated in getValue.
ml . setValue ( 0 );
float time ;
float rank = npc . getBuilding (). getRank () - 1 ;
float rate = ( float ) ( 2 . 5 * rank );
time = ( 20 - rate );
2022-04-30 09:41:17 -04:00
time *= MBServerStatics . ONE_MINUTE ;
2023-07-15 09:23:48 -04:00
if ( ml . getItemBase (). getUUID () > 910010 && ml . getItemBase (). getUUID () < 910019 ) {
2024-03-01 21:32:51 -05:00
rank = ml . getTemplsteID () - 910010 ;
2023-07-15 09:23:48 -04:00
time = rank * 60 * 60 * 3 * 1000 ;
}
// No job is submitted, as object's upgradetime field
// is used to determin whether or not an object has
// compelted rolling. The game object exists previously
// to this, not when 'compelte' is pressed.
long upgradeTime = System . currentTimeMillis () + ( long ) ( time * Float . parseFloat ( ConfigManager . MB_PRODUCTION_RATE . getValue ()));
DateTime dateTime = new DateTime ();
dateTime = dateTime . withMillis ( upgradeTime );
ml . setDateToUpgrade ( upgradeTime );
npc . addItemToForge ( ml );
int playerID = 0 ;
if ( pc != null )
playerID = pc . getObjectUUID ();
2024-03-01 21:32:51 -05:00
DbManager . NPCQueries . ADD_TO_PRODUCTION_LIST ( ml . getObjectUUID (), npc . getObjectUUID (), ml . getTemplsteID (), dateTime , prefixString , suffixString , ml . getCustomName (), false , playerID );
ProducedItem pi = new ProducedItem ( npc . getRolling (). size (), npc . getObjectUUID (), ml . getTemplsteID (), dateTime , false , prefixString , suffixString , ml . getCustomName (), playerID );
2023-07-15 09:23:48 -04:00
pi . setProducedItemID ( ml . getObjectUUID ());
pi . setAmount ( itemsToRoll );
ItemQueue produced = ItemQueue . borrow ( pi , ( long ) ( time * Float . parseFloat ( ConfigManager . MB_PRODUCTION_RATE . getValue ())));
ItemProductionManager . send ( produced );
} catch ( Exception e ) {
Logger . error ( e );
} finally {
city . transactionLock . writeLock (). unlock ();
}
// npc.addItemToForge(item);
return ml ;
}
2023-08-07 15:52:50 -04:00
public static Item randomRoll ( NPC vendor , PlayerCharacter playerCharacter , int itemsToRoll , int itemBaseID ) {
2023-07-15 09:23:48 -04:00
byte itemModTable ;
int prefixMod = 0 ;
int suffixMod = 0 ;
String prefix = "" ;
2023-08-07 12:12:52 -04:00
String suffix = "" ;
ModTableEntry prefixEntry = null ;
ModTableEntry suffixEntry = null ;
2023-07-15 09:23:48 -04:00
2023-08-07 15:52:50 -04:00
ItemBase ib = ItemBase . getItemBase ( itemBaseID );
2024-02-28 16:31:09 -05:00
ItemTemplate template = ItemTemplate . itemTemplates . get ( itemBaseID );
2023-07-15 09:23:48 -04:00
2024-03-03 15:06:44 -05:00
if ( template == null )
2023-07-15 09:23:48 -04:00
return null ;
2024-03-03 15:06:44 -05:00
if ( ! vendor . getCharItemManager (). hasRoomInventory ( template . item_wt )) {
2023-08-07 15:52:50 -04:00
if ( playerCharacter != null )
ChatManager . chatSystemInfo ( playerCharacter , vendor . getName () + " " + vendor . getContract (). getName () + " Inventory is full." );
2023-07-15 09:23:48 -04:00
return null ;
}
itemModTable = ( byte ) ib . getModTable ();
if ( ! vendor . getItemModTable (). contains ( itemModTable )) {
2023-08-07 15:52:50 -04:00
if ( playerCharacter != null )
ErrorPopupMsg . sendErrorPopup ( playerCharacter , 59 );
2023-07-15 09:23:48 -04:00
return null ;
}
for ( byte temp : vendor . getItemModTable ()) {
2023-08-07 15:52:50 -04:00
2023-07-15 09:23:48 -04:00
if ( itemModTable != temp )
continue ;
2023-08-07 15:52:50 -04:00
2023-07-15 09:23:48 -04:00
prefixMod = vendor . getModTypeTable (). get ( vendor . getItemModTable (). indexOf ( temp ));
suffixMod = vendor . getModSuffixTable (). get ( vendor . getItemModTable (). indexOf ( temp ));
}
if ( prefixMod == 0 && suffixMod == 0 ) {
2024-02-28 16:31:09 -05:00
Logger . info ( "Failed to find modTables for item " + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2023-08-07 13:36:16 -04:00
// Roll on the tables for this vendor
ModTypeTableEntry prefixTypeTable = ModTypeTableEntry . rollTable ( prefixMod , ThreadLocalRandom . current (). nextInt ( 1 , 100 + 1 ));
ModTypeTableEntry suffixTypeTable = ModTypeTableEntry . rollTable ( suffixMod , ThreadLocalRandom . current (). nextInt ( 1 , 100 + 1 ));
// Sanity check.
if ( prefixTypeTable == null || suffixTypeTable == null )
return null ;
2023-07-15 09:23:48 -04:00
2023-08-07 12:12:52 -04:00
int rollPrefix = ThreadLocalRandom . current (). nextInt ( 1 , 100 + 1 );
2023-07-15 09:23:48 -04:00
if ( rollPrefix < 80 ) {
2023-08-07 13:55:22 -04:00
int randomPrefix = LootManager . TableRoll ( vendor . getLevel (), false );
2023-08-07 13:36:16 -04:00
prefixEntry = ModTableEntry . rollTable ( prefixTypeTable . modTableID , randomPrefix );
2023-07-15 09:23:48 -04:00
2023-08-07 12:12:52 -04:00
if ( prefixEntry != null )
prefix = prefixEntry . action ;
2023-07-15 09:23:48 -04:00
}
2023-08-07 12:12:52 -04:00
int rollSuffix = ThreadLocalRandom . current (). nextInt ( 1 , 100 + 1 );
2023-07-15 09:23:48 -04:00
2023-08-07 15:52:50 -04:00
// Always have at least one mod on a magic rolled item.
// Suffix will be our backup plan.
2023-08-07 15:00:18 -04:00
if ( rollSuffix < 80 || prefixEntry == null ) {
2023-07-15 09:23:48 -04:00
2023-08-07 13:55:22 -04:00
int randomSuffix = LootManager . TableRoll ( vendor . getLevel (), false );
2023-08-07 13:36:16 -04:00
suffixEntry = ModTableEntry . rollTable ( suffixTypeTable . modTableID , randomSuffix );
2023-07-15 09:23:48 -04:00
2023-08-07 12:12:52 -04:00
if ( suffixEntry != null )
suffix = suffixEntry . action ;
2023-07-15 09:23:48 -04:00
}
2023-08-07 15:52:50 -04:00
MobLoot toRoll = ItemFactory . produceRandomRoll ( vendor , playerCharacter , prefix , suffix , itemBaseID );
2023-07-15 09:23:48 -04:00
if ( toRoll == null )
return null ;
toRoll . setValue ( 0 );
float time ;
float rank = vendor . getBuilding (). getRank () - 1 ;
float rate = ( float ) ( 2 . 5 * rank );
time = ( 20 - rate );
2022-04-30 09:41:17 -04:00
time *= MBServerStatics . ONE_MINUTE ;
2023-07-15 09:23:48 -04:00
if ( toRoll . getItemBase (). getUUID () > 910010 && toRoll . getItemBase (). getUUID () < 910019 ) {
2024-03-01 21:32:51 -05:00
rank = toRoll . getTemplsteID () - 910010 ;
2023-07-15 09:23:48 -04:00
time = rank * 60 * 60 * 3 * 1000 ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// No job is submitted, as object's upgradetime field
2023-08-07 15:52:50 -04:00
// is used to determine whether an object has
// completed rolling. The game object exists previously
// to this, not when 'complete' is pressed.
2023-07-15 09:23:48 -04:00
long upgradeTime = System . currentTimeMillis () + ( long ) ( time * Float . parseFloat ( ConfigManager . MB_PRODUCTION_RATE . getValue ()));
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
DateTime dateTime = new DateTime ();
dateTime = dateTime . withMillis ( upgradeTime );
toRoll . setDateToUpgrade ( upgradeTime );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
int playerID = 0 ;
2022-04-30 09:41:17 -04:00
2023-08-07 15:52:50 -04:00
if ( playerCharacter != null )
playerID = playerCharacter . getObjectUUID ();
2024-03-01 21:32:51 -05:00
DbManager . NPCQueries . ADD_TO_PRODUCTION_LIST ( toRoll . getObjectUUID (), vendor . getObjectUUID (), toRoll . getTemplsteID (), dateTime , prefix , suffix , toRoll . getCustomName (), true , playerID );
2023-08-07 15:52:50 -04:00
2024-03-01 21:32:51 -05:00
ProducedItem pi = new ProducedItem ( toRoll . getObjectUUID (), vendor . getObjectUUID (), toRoll . getTemplsteID (), dateTime , true , prefix , suffix , toRoll . getCustomName (), playerID );
2023-07-15 09:23:48 -04:00
pi . setProducedItemID ( toRoll . getObjectUUID ());
pi . setAmount ( itemsToRoll );
ItemQueue produced = ItemQueue . borrow ( pi , ( long ) ( time * Float . parseFloat ( ConfigManager . MB_PRODUCTION_RATE . getValue ())));
ItemProductionManager . send ( produced );
2023-08-07 15:52:50 -04:00
2023-07-15 09:23:48 -04:00
return toRoll ;
}
public static MobLoot produceRandomRoll ( NPC npc , PlayerCharacter pc , String prefixString , String suffixString , int itemID ) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
boolean useWarehouse = false ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( npc == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ItemBase ib = ItemBase . getItemBase ( itemID );
2024-02-28 16:31:09 -05:00
ItemTemplate template = ItemTemplate . itemTemplates . get ( itemID );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( ib == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Building forge = npc . getBuilding ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( forge == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Zone zone = npc . getBuilding (). getParentZone ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( zone == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-09-20 15:53:41 -04:00
City city = City . getCity ( zone . playerCityUUID );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( city == null )
return null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
MobLoot ml = null ;
city . transactionLock . writeLock (). lock ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
try {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Warehouse cityWarehouse = city . getWarehouse ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( cityWarehouse != null && forge . assetIsProtected ())
useWarehouse = true ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ConcurrentHashMap < ItemBase , Integer > resources = null ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( useWarehouse )
2024-01-24 20:03:27 -06:00
resources = cityWarehouse . resources ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
int galvorAmount = 0 ;
int wormwoodAmount = 0 ;
2022-04-30 09:41:17 -04:00
2024-03-10 13:34:24 -04:00
if ( template . item_type . equals ( ItemType . WEAPON ) && ib . getPercentRequired () == 110 ) {
2024-03-10 14:10:51 -04:00
switch ( template . item_skill_used ) {
2023-07-15 09:23:48 -04:00
case "Bow" :
case "Crossbow" :
case "Spear" :
case "Pole Arm" :
case "Staff" :
wormwoodAmount = 22 ;
break ;
case "Axe" :
case "Dagger" :
case "Sword" :
case "Hammer" :
case "Unarmed Combat" :
if ( ib . isTwoHanded ())
galvorAmount = 22 ;
else
galvorAmount = 11 ;
break ;
}
}
ItemBase galvor = ItemBase . getItemBase ( 1580017 );
ItemBase wormwood = ItemBase . getItemBase ( 1580018 );
//Cant roll 110% weapons that require resources if not allowed to use warehouse.
if ( galvorAmount > 0 || wormwoodAmount > 0 )
if ( ! useWarehouse )
return null ;
if ( galvorAmount > 0 ) {
2024-01-24 20:21:41 -06:00
if ( Warehouse . isResourceLocked ( cityWarehouse , galvor )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Galvor is locked." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( cityWarehouse . resources . get ( galvor ) < galvorAmount ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Galvor in warehouse to roll this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
if ( wormwoodAmount > 0 ) {
2024-01-24 20:21:41 -06:00
if ( Warehouse . isResourceLocked ( cityWarehouse , wormwood )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Galvor is locked." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:03:27 -06:00
if ( cityWarehouse . resources . get ( wormwood ) < wormwoodAmount ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Galvor in warehouse to roll this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
EffectsBase prefix = null ;
if ( ! prefixString . isEmpty ()) {
prefix = PowersManager . getEffectByIDString ( prefixString );
if ( prefix == null )
return null ;
}
ItemBase goldIB = ItemBase . getGoldItemBase ();
2024-03-03 13:18:16 -05:00
int baseCost = template . item_value ;
2023-07-15 09:23:48 -04:00
int total = ( int ) ( baseCost + baseCost * . 10 );
EffectsBase suffix = null ;
if ( ! suffixString . isEmpty ()) {
suffix = PowersManager . getEffectByIDString ( suffixString );
if ( suffix == null )
return null ;
}
//calculate gold costs and remove from the warehouse
if ( prefix != null || suffix != null ) {
2024-03-03 13:18:16 -05:00
int costToCreate = ( int ) ( template . item_value + template . item_value * . 10f );
2023-07-15 09:23:48 -04:00
int buildingWithdraw = BuildingManager . GetWithdrawAmountForRolling ( forge , costToCreate );
int overdraft = BuildingManager . GetOverdraft ( forge , costToCreate );
if ( overdraft > 0 && ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:21:41 -06:00
if ( useWarehouse && overdraft > 0 && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
if ( useWarehouse && overdraft > resources . get ( goldIB )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
if ( ! forge . transferGold ( - buildingWithdraw , false )) {
overdraft += buildingWithdraw ;
if ( ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Building does not have enough gold to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
} else {
if ( overdraft > resources . get ( goldIB )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
// there was an overdraft, withdraw the rest from warehouse.
if ( overdraft > 0 ) {
if ( pc != null ) {
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , pc , ItemBase . GOLD_ITEM_BASE , overdraft , false , true )) {
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
} else {
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ItemBase . GOLD_ITEM_BASE , overdraft , true )) {
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
}
}
}
if ( prefix == null && suffix == null ) {
int buildingWithdraw = BuildingManager . GetWithdrawAmountForRolling ( forge , total );
int overdraft = BuildingManager . GetOverdraft ( forge , total );
if ( overdraft > 0 && ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough gold in building strongbox." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
2024-01-24 20:21:41 -06:00
if ( useWarehouse && overdraft > 0 && Warehouse . isResourceLocked ( cityWarehouse , ItemBase . GOLD_ITEM_BASE )) {
2023-07-15 09:23:48 -04:00
if ( pc != null )
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
if ( useWarehouse && overdraft > resources . get ( goldIB )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse for overdraft." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
if ( ! forge . transferGold ( - buildingWithdraw , false )) {
overdraft += buildingWithdraw ;
if ( ! useWarehouse ) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Building does not have enough gold to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
} else {
if ( overdraft > resources . get ( goldIB )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Not enough Gold in Warehouse to produce this item." + template . item_base_name );
2023-07-15 09:23:48 -04:00
return null ;
}
}
}
if ( overdraft > 0 && useWarehouse ) {
if ( pc != null ) {
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , pc , ItemBase . GOLD_ITEM_BASE , overdraft , false , true )) {
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
} else {
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , ItemBase . GOLD_ITEM_BASE , overdraft , true )) {
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
}
}
}
if ( galvorAmount > 0 && useWarehouse ) {
//ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse");
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , galvor , galvorAmount , true )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Failed to withdraw Galvor from warehouse!" + template . item_base_name );
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
}
if ( wormwoodAmount > 0 && useWarehouse ) {
//ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse");
2024-01-24 20:21:41 -06:00
if ( ! Warehouse . withdraw ( cityWarehouse , npc , wormwood , wormwoodAmount , true )) {
2024-02-28 16:31:09 -05:00
ErrorPopupMsg . sendErrorMsg ( pc , "Failed to withdraw Wormwood from warehouse for " + template . item_base_name );
2023-07-15 09:23:48 -04:00
Logger . error ( "Warehouse with UID of" + cityWarehouse . getObjectUUID () + "Failed to Withdrawl " );
return null ;
}
}
ml = new MobLoot ( npc , ib , false );
ml . containerType = Enum . ItemContainerType . FORGE ;
if ( prefix != null ) {
ml . addPermanentEnchantment ( prefix . getIDString (), 0 , 0 , true );
ml . setPrefix ( prefix . getIDString ());
}
if ( suffix != null ) {
ml . addPermanentEnchantment ( suffix . getIDString (), 0 , 0 , false );
ml . setSuffix ( suffix . getIDString ());
}
ml . loadEnchantments ();
ml . setValue ( 0 );
ml . setRandom ( true );
npc . addItemToForge ( ml );
} catch ( Exception e ) {
Logger . error ( e );
} finally {
city . transactionLock . writeLock (). unlock ();
}
return ml ;
}
2022-04-30 09:41:17 -04:00
}