package projectzombie.items.modifier;

import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import projectzombie.time.GameTimer;

public class ItemModifierTimer extends ItemModifier
{
	long end;
	long start;
	
	public long getLeft() {
		return end - GameTimer.getTime();
	}
	
	public double getDamage() {
		return 1 - (double)(end - GameTimer.getTime()) / (double)(end - start);
	}
	
	public ItemModifierTimer(long time) {
		start = GameTimer.getTime();
		end = start + time;
	}
	
	public ItemModifierTimer(BdfObject bdf) {
		BdfClassLoad(bdf);
	}

	@Override
	public void BdfClassLoad(BdfObject bdf)
	{
		BdfNamedList nl = bdf.getNamedList();
		start = nl.get("start").getLong();
		end = nl.get("end").getLong();
	}

	@Override
	public void BdfClassSave(BdfObject bdf)
	{
		BdfNamedList nl = bdf.getNamedList();
		nl.set("start", bdf.newObject().setLong(start));
		nl.set("end", bdf.newObject().setLong(end));
	}

	@Override
	public boolean isEqual(ItemModifier other) {
		return ((ItemModifierTimer)other).start == start &&
				((ItemModifierTimer)other).end == end;
	}

	@Override
	public ItemModifier copy() {
		ItemModifierTimer timer = new ItemModifierTimer(0);
		timer.start = this.start;
		timer.end = this.end;
		return timer;
	}

	public ItemModifierTimerPaused pause() {
		return new ItemModifierTimerPaused(end - start, getLeft());
	}
}
