forked from MagicBane/Server
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
4.4 KiB
127 lines
4.4 KiB
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . |
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· |
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ |
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ |
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ |
|
// Magicbane Emulator Project © 2013 - 2022 |
|
// www.magicbane.com |
|
|
|
package engine.gameManager; |
|
|
|
import engine.loot.WorkOrder; |
|
import engine.objects.Item; |
|
import engine.objects.PlayerCharacter; |
|
import org.pmw.tinylog.Logger; |
|
|
|
import java.util.HashMap; |
|
import java.util.concurrent.BlockingQueue; |
|
import java.util.concurrent.DelayQueue; |
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
public enum ForgeManager implements Runnable { |
|
|
|
FORGE_MANAGER; |
|
|
|
private static final BlockingQueue<WorkOrder> workOrders = new DelayQueue(); |
|
public static final AtomicInteger wordOrderCounter = new AtomicInteger(0); |
|
public static HashMap<Item, WorkOrder> oven = new HashMap<Item, WorkOrder>(); |
|
|
|
@Override |
|
public void run() { |
|
|
|
while (true) { |
|
|
|
try { |
|
|
|
WorkOrder workOrder = workOrders.take(); |
|
|
|
// Fulfill workOrder |
|
|
|
for (int i = 0; i < workOrder.slotCount; ++i) { |
|
|
|
// Create workOrder items; one for each slot |
|
// assigned to this workOrder. |
|
|
|
// if Prefix and suffix are null random roll item |
|
// otherwise roll what was asked for |
|
} |
|
|
|
if (workOrder.total_produced >= workOrder.total_to_produce) { |
|
|
|
Logger.info("Workorder has completed: " + workOrder.workOrderID); |
|
|
|
workOrder.runCompleted = true; |
|
workOrder.vendor.workOrders.remove(workOrder); |
|
continue; |
|
} |
|
|
|
// Resubmit workOrder |
|
|
|
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; |
|
workOrder.total_produced = workOrder.total_produced + 1; |
|
workOrders.add(workOrder); |
|
|
|
Logger.info("workOrder cycled:" + workOrder.workOrderID + " (" + workOrder.total_produced + "/" + workOrder.total_to_produce + ")"); |
|
} catch (InterruptedException e) { |
|
e.printStackTrace(); |
|
} |
|
} |
|
} |
|
|
|
public static void start() { |
|
|
|
Thread forgeManager; |
|
forgeManager = new Thread(FORGE_MANAGER); |
|
|
|
forgeManager.setName("Forge Manager"); |
|
forgeManager.start(); |
|
} |
|
|
|
public static void submit(WorkOrder workOrder) { |
|
workOrder.workOrderID = wordOrderCounter.incrementAndGet(); |
|
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; |
|
|
|
// Single item rolls are total_to_produce of 0; |
|
|
|
if (workOrder.slotCount > 0 && workOrder.total_to_produce == 0) |
|
workOrder.slotCount = 1; |
|
|
|
Logger.info(workOrder.toString()); |
|
|
|
workOrder.vendor.workOrders.add(workOrder); |
|
workOrders.add(workOrder); |
|
} |
|
|
|
public static boolean validate(PlayerCharacter playerCharacter, WorkOrder workOrder) { |
|
|
|
return true; |
|
} |
|
|
|
public static long calcRollingDuration(WorkOrder workOrder) { |
|
|
|
long rollingDuration; |
|
float rank = workOrder.vendor.getBuilding().getRank() - 1; |
|
float rate = (float) (2.5 * rank); |
|
float baseTime = (20 - rate) * 60000; |
|
|
|
// Bane circles |
|
|
|
if (workOrder.templateID > 910010 && workOrder.templateID < 910019) { |
|
rank = workOrder.templateID - 910010; |
|
baseTime = rank * 60 * 60 * 3 * 1000; |
|
} |
|
|
|
rollingDuration = (long) (baseTime * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); |
|
return rollingDuration; |
|
} |
|
|
|
public static int getAvailableSlots(WorkOrder workOrder) { |
|
|
|
int availableSlots = workOrder.vendor.getRank(); |
|
|
|
for (WorkOrder npcWorkOrder : workOrder.vendor.workOrders) |
|
availableSlots = availableSlots - npcWorkOrder.slotCount; |
|
|
|
return availableSlots; |
|
} |
|
}
|
|
|