package custom.TimeRewards;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Map;
import java.util.HashMap;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.Location;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.commons.util.Rnd;
/**
* TomAlko
*/
public class TimeRewards
{
private static Logger LOGGER = Logger.getLogger(TimeRewards.class.getName());
private static boolean RewardEnable = true; // true - включен, false - выключен
private static int RewardTime = 60; // время (в минутах), через которое будет выдан итем
private static int RewardId = 4037; // ID итема
private static int MinLvl = 1; // минимальный левел, с которого можно получать итем
private static int MaxLvl = 85; // максимальный левел, до которого можно получать итем
private static int MinCount = 1; // минимальное кол-во итемов
private static int MaxCount = 2; // максимальное кол-во итемов
public TimeRewards() {
LOGGER.info("=================================================");
LOGGER.info("========= Time Rewards by Seidhe LOADED =========");
LOGGER.info("=================================================");
ThreadPool.schedule(new RunnableTimeRewards(), RewardTime * 60000);
}
private class RunnableTimeRewards implements Runnable
{
private Map<Integer,Location> _lastLoc = new HashMap<Integer, Location>();
public void run()
{
for(Player player : World.getInstance().getPlayers()) {
if(player == null || player.isInOfflineMode() || player.isAlikeDead() || player.getLevel() < MinLvl || player.getLevel() > MaxLvl)
continue;
if(_lastLoc.containsKey(player.getObjectId())) try {
Location l = _lastLoc.get(player.getObjectId());
Location l2 = player.getLocation();
if(Math.abs((l.getX()*l.getX() + l.getY()*l.getY())-(l2.getX()*l2.getX()+l2.getY()+l2.getY())) < 200)
continue;
} finally {
_lastLoc.put(player.getObjectId(), player.getLocation());
}
int score = MinCount+Rnd.get(MaxCount-MinCount);
if(score <= 0)
continue;
player.addItem("TimeReward", RewardId, score, player, true);
}
ThreadPool.schedule(new RunnableTimeRewards(), RewardTime * 60000);
}
}
public static void main(String[] args)
{
if (RewardEnable) {
new TimeRewards();
}
}
}