package com.zivilon.cinder_loe.world.event;

import com.zivilon.cinder_loe.CinderLoE_Config;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;

public class WarbandTickHandler {

    public int tick_counter = 0;
    public static int INTERVAL_TICKS = 12000; // 10 minutes at 20 TPS

    @SubscribeEvent
    public void onServerTick(ServerTickEvent event) {
        if (event.phase == TickEvent.Phase.END) {
            tick_counter++;
            if (tick_counter >= INTERVAL_TICKS) {
                tick_counter = 0;
                run_task();
            }
        }
    }

    public void run_task() {
        if (Warband.last_warband_timestamp > (System.currentTimeMillis() / 1000L) - (60*60*4)) return; // Do not spawn warband if less than 4 hours since last one
        if (Warband.random.nextInt(10) != 0) return;
        if (!CinderLoE_Config.warbands_enabled) return;
        Warband.initialize_warband();
    }
}
