Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Created October 30, 2017 07:47
Show Gist options
  • Save mlebkowski/1099e8fb41c126452a96b31014ab47be to your computer and use it in GitHub Desktop.
Save mlebkowski/1099e8fb41c126452a96b31014ab47be to your computer and use it in GitHub Desktop.
<?php
namespace Nassau\CartoonBattle\Services\Farming\Chores;
use Nassau\CartoonBattle\Entity\Game\Farming\UserFarming;
use Nassau\CartoonBattle\Services\Farming\FarmingChore;
use Nassau\CartoonBattle\Services\Game\Game;
class WatchAdsChore implements FarmingChore
{
public function make(Game $game, UserFarming $configuration, \Closure $logWriter)
{
$ads = 0;
while ($this->shouldWatchAds($game) && $ads++ < 3) {
$logWriter('Watching an ad to Boost your chances');
$game->recordAdBoost();
sleep(8);
}
}
private function shouldWatchAds(Game $game)
{
if ($game->isVIP()) {
return false;
}
$result = $game('getBoostLevel');
$userData = isset($result['user_data']) ? $result['user_data'] : null;
if ((int)$userData['boost_level'] === 3 && $userData['boost_end_time'] > time() + 60 * 60 * 1.5) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment