Originally Posted by
Akitheone
Would you recommend using the one that was released with skills or this one? OR is it the same minus skills?
the skills are horrible lol, should just use this and write your own
Originally Posted by
Tha Don
anyone know what this is from?
Code:
java.lang.ArithmeticException: / by zero
at com.elvarg.engine.task.impl.ShopRestockTask.getRestockAmount(ShopRest
ockTask.java:62)
at com.elvarg.engine.task.impl.ShopRestockTask.execute(ShopRestockTask.j
ava:46)
at com.elvarg.engine.task.Task.tick(Task.java:142)
at com.elvarg.engine.task.TaskManager.sequence(TaskManager.java:32)
at com.elvarg.engine.GameEngine.run(GameEngine.java:21)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:51
1)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617)
at java.lang.Thread.run(Thread.java:748)
Use this:
Code:
package com.elvarg.engine.task.impl;
import com.elvarg.engine.task.Task;
import com.elvarg.world.model.Item;
import com.elvarg.world.model.container.impl.Shop;
public class ShopRestockTask extends Task {
public ShopRestockTask(Shop shop) {
super(4);
this.shop = shop;
}
private final Shop shop;
@Override
protected void execute() {
if(shop.fullyRestocked()) {
stop();
return;
}
if(shop.getDefinition().getId() == Shop.GENERAL_SHOP) {
//General shop, simply delete items from the stock.
for(Item item : shop.getValidItems()) {
shop.delete(item.getId(), getDeleteRatio(item.getAmount()), false);
}
} else {
//Other shops, add or delete items.
for(int shopItemIndex = 0; shopItemIndex < shop.getDefinition().getOriginalStock().length; shopItemIndex++) {
int originalStockAmount = shop.getDefinition().getOriginalStock()[shopItemIndex].getAmount();
int currentStockAmount = shop.getItems()[shopItemIndex].getAmount();
//Check if we have too many items in the shop.
//If that's the case, delete them step by step.
if(currentStockAmount > originalStockAmount) {
int toDelete = getDeleteRatio(shop.getItems()[shopItemIndex].getAmount());
shop.delete(shop.getItems()[shopItemIndex].getId(), toDelete, false);
}
//Check if we have too few items in the shop.
//If that's the case, restock them step by step.
else if(currentStockAmount < originalStockAmount) {
int toRestock = getRestockAmount(originalStockAmount, currentStockAmount);
shop.add(new Item(shop.getItems()[shopItemIndex].getId(), toRestock), false);
}
}
}
shop.refreshItems();
}
@Override
public void stop() {
setEventRunning(false);
shop.setRestockingItems(false);
}
private static int getRestockAmount(int originalStockAmount, int currentStockAmount) {
int calc = originalStockAmount / currentStockAmount;
if(calc < 1) {
calc = 1;
} else if(calc > originalStockAmount) {
calc = originalStockAmount;
}
return calc;
}
private static int getDeleteRatio(int currentStock) {
int calc = currentStock / 10;
if(calc < 1) {
calc = 1;
}
return calc;
}
}