<?php

include_once("internal/task_sequencer.php");

// --------------------------------------------
class TimeAnnouncerTask {
	protected $metagame = NULL;
	protected $time = 30;
	protected $next_boundary = 0;
	protected $say_countdown = true;

	// float
	protected $time_left = 30.0;
	
	// --------------------------------------------
	function __construct($metagame, $time, $say_countdown = true) {
		$this->metagame = $metagame;
		$this->time = $time;
		$this->say_countdown = $say_countdown;
	}

	// --------------------------------------------
	function start() {
		_log("waiting " . $this->time . " seconds in total");

		$this->time_left = (double)($this->time);
		$this->next_boundary = $this->time;
	}

	// --------------------------------------------
	function update($time) {
		$this->time_left -= $time;

		if ($this->time_left < $this->next_boundary &&
			$this->next_boundary > 0) // don't say starting in 0 s
		{
			_log("to go: " . $this->next_boundary);
			if ($this->say_countdown) {
				$this->metagame->comms->send("say starting in " . $this->next_boundary . " seconds");
			}

			// 10 interval
			$this->next_boundary -= 10;
		}
	}

	// --------------------------------------------
	function has_ended() {
		if ($this->time_left < 0.0) {
			return true;
		}
		return false;
	}
}

?>