CITY_MODULE wave counter timer is off. Found bug.

Have you created a module that you would like to submit to BudaBot? Post it here, and it might make it into the next release.
Aierys
Member
Posts: 9
Joined: Thu Sep 12, 2013 1:27 am
antispam: Rimor

CITY_MODULE wave counter timer is off. Found bug.

Postby Aierys » Thu Sep 12, 2013 1:36 am

After installing Budabot for the first time I noticed that Wave 1 and Wave 2 were very timely, but all the following waves were off. The wait between waves should be 2 min, 2.5 min and then back to 2 min until General spawns. The additional 30 seconds added to wave 2 is not factored into waves 3 to General which results in notifications at 2 min, 2.5 min, 1.5 min (30 seconds too early) and 2 min afterwards (these are all shifted by 30 seconds as well).

I found the math bug and fixed it if someone would like to confirm the alerts are now 13 seconds before each wave's spawn.

<?php

/**
* Authors:
* - Funkman (RK2)
* - Tyrence (RK2)
*
* @Instance
*
* Commands this class contains:
* @DefineCommand(
* command = 'startwave',
* accessLevel = 'guild',
* description = 'Manually start wave counter',
* help = 'wavecounter.txt'
* )
* @DefineCommand(
* command = 'stopwave',
* accessLevel = 'guild',
* description = 'Manually stops wave counter',
* help = 'wavecounter.txt'
* )
* @DefineCommand(
* command = 'citywave',
* accessLevel = 'guild',
* description = 'Show the current city wave',
* help = 'wavecounter.txt'
* )
*/
class WaveCounterController {

/**
* Name of the module.
* Set automatically by module loader.
*/
public $moduleName;

/** @Inject */
public $chatBot;

private $wave = null;

/**
* @HandlesCommand("startwave")
* @Matches("/^startwave$/i")
*/
public function startwaveCommand($message, $channel, $sender, $sendto, $args) {
if (isset($this->wave)) {
$this->chatBot->sendGuild("A raid is already in progress.");
} else {
$this->chatBot->sendGuild("Wave counter started by $sender.");
$this->wave['time'] = time();
$this->wave['wave'] = 1;
}
}

/**
* @HandlesCommand("stopwave")
* @Matches("/^stopwave$/i")
*/
public function stopwaveCommand($message, $channel, $sender, $sendto, $args) {
unset($this->wave);
$this->chatBot->sendGuild("Wave counter stopped by $sender.");
}

/**
* @HandlesCommand("citywave")
* @Matches("/^citywave$/i")
*/
public function citywaveCommand($message, $channel, $sender, $sendto, $args) {
if (!isset($this->wave)) {
$msg = "There is no raid in progress at this time.";
} else if ($this->wave['wave'] == 1) {
$msg = "Waiting for the first wave.";
} else {
$msg = "Current wave: " . ($this->wave['wave'] - 1);
}
$sendto->reply($msg);
}

/**
* @Event("guild")
* @Description("Starts a wave counter when cloak is lowered")
*/
public function autoStartWaveCounterEvent($eventObj) {
if (preg_match("/^Your city in (.+) has been targeted by hostile forces.$/i", $eventObj->message)) {
$this->chatBot->sendGuild("Wave counter started.");
$this->wave['time'] = time();
$this->wave['wave'] = 1;
}
}

/**
* @Event("2sec")
* @Description("Checks timer to see when next wave should come")
*/

public function checkWaveCounterTimerEvent($eventObj) {
if (isset($this->wave)) {
$stime = $this->wave['time'];
$now = time();
$wave = $this->wave['wave'];
if ($wave == 1) {
if ($stime >= $now + 13 - $wave * 120 && $stime <= $now + 17 - $wave * 120) {
$this->chatBot->sendGuild("Wave $wave Incoming.");
$wave++;
$this->wave['wave'] = $wave;
}
} else if ($stime >= $now - 17 - $wave * 120 && $stime <= $now - 13 - $wave * 120 ) {
if ($wave != 9) {
$this->chatBot->sendGuild("Wave $wave Incoming.");
} else {
$this->chatBot->sendGuild("General Incoming.");
}
$wave++;
$this->wave['wave'] = $wave;
if ($wave == 10) {
// if raid is over, delete wave data
unset($this->wave);
}
}
if ($stime < $now - 10 * 120) {
unset($this->wave);
}
}
}
}

?>
Tyrence
The Team
Posts: 1875
Joined: Sat Jan 09, 2010 1:32 am

Re: CITY_MODULE wave counter timer is off. Found bug.

Postby Tyrence » Fri Sep 13, 2013 4:26 pm

Thanks for posting that.

We actually addressed this here: viewtopic.php?f=5&t=1151
New wave schedule:
1: 105s
2: 150s
3: 90s
4: 120s
5: 120s
6: 120s
7: 120s
8: 120s
General: 120s


Additionally, we added a way for people to specify their own wave schedule using the bot settings in case they have a unique circumstance.

Unfortunately this was added after we released 3.0. So it's in Github, but never released. So for anyone who is not running a nightly build, they can use the code you posted to fix this.
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases

Return to “User Modules”

Who is online

Users browsing this forum: No registered users and 1 guest