package data.scripts.campaign.intel.bar.events;

import com.fs.starfarer.api.impl.campaign.intel.bar.PortsideBarEvent;
import com.fs.starfarer.api.impl.campaign.intel.bar.events.BaseBarEventCreator;
import data.scripts.campaign.intel.SWP_IBBTracker;

public class SWP_IBBBarEventCreator extends BaseBarEventCreator {

    public boolean createInstantly = false;
    public boolean debug = false;

    @Override
    public PortsideBarEvent createBarEvent() {
        return new SWP_IBBBarEvent();
    }

    @Override
    public float getBarEventFrequencyWeight() {
        /* Exponentially less likely to spawn additional bounties when you leave them laying around */
        if (createInstantly || debug) {
            return 1000f;
        }
        return super.getBarEventFrequencyWeight() / (float) Math.pow(2, Math.max(0, SWP_IBBTracker.getTracker().getPendingStages()));
    }

    @Override
    public float getBarEventActiveDuration() {
        return 15f + (float) Math.random() * 15f;
    }

    @Override
    public float getBarEventTimeoutDuration() {
        /* Short timeout with no active bounties, increases with more pending bounties */
        if (createInstantly || debug) {
            return 0f;
        }
        return (10f * Math.max(0, SWP_IBBTracker.getTracker().getPendingStages())) + (float) Math.random() * 20f;
    }

    @Override
    public float getBarEventAcceptedTimeoutDuration() {
        /* Moderate timeout with few active bounties, increases quickly with more pending bounties 
        NOTE: when this function is called, getPendingStages() has NOT been incremented yet! */
        if (createInstantly || debug) {
            return 0f;
        }
        return Math.max(0f, (15f * Math.max(0, 1 + SWP_IBBTracker.getTracker().getPendingStages())) + (float) Math.random() * 20f);
    }

    @Override
    public boolean isPriority() {
        return createInstantly;
    }
}
