package projectzombie.items.modifier;

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

public class ItemModifierTimerPaused extends ItemModifier
{
	long left;
	long total;
	
	public ItemModifierTimerPaused(BdfObject bdf) {
		BdfClassLoad(bdf);
	}
	
	public ItemModifierTimerPaused(long total, long left) {
		this.total = total;
		this.left = left;
	}

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

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

	@Override
	public boolean isEqual(ItemModifier other) {
		return true;
	}

	@Override
	public ItemModifier copy() {
		return new ItemModifierTimerPaused(total, left);
	}
	
	public ItemModifierTimer resume()
	{
		long now = GameTimer.getTime();
		long end = now + left;
		
		ItemModifierTimer timer = new ItemModifierTimer(0);
		timer.start = end - total;
		timer.end = end;
		
		return timer;
	}
	
	public long getLeft() {
		return left;
	}
	
	public double getDamage() {
		return 1 - (double)left / (double)total;
	}

}
