= 0) && (($number = $difference / $lengths[$val]) <= 1); $val--); // Ensure the script has found a match if ($val < 0) $val = 0; // Determine the minor value, to recurse through $new_time = $current_time - ($difference % $lengths[$val]); // Set the current value to be floored $number = floor($number); // If required create a plural if($number != 1) $periods[$val].= "s"; // Return text $text = sprintf("%d %s ", $number, $periods[$val]); // Ensure there is still something to recurse through, and we have not found 1 minute and 0 seconds. if (($val >= 1) && (($current_time - $new_time) > 0)){ $text .= TimeAgo($new_time); } return $text; } function do_updates($type, $nextrun) { global $dblink, $update_halfhour_nextrun, $update_day_nextrun; if ($type == 'halfhour') { $numupdates = floor((time()-$nextrun)/1800)+1; $result = zoopz_query('SELECT * FROM `accounts`'); while ($line = $result->fetch_assoc()) { $newattackturns = $line['attackturns'] + ($numupdates * 5); if ($newattackturns > 400) { $newattackturns = 400; } $maxhp = calculateMaxHP($line['zoop_level'], $line['zoop_stamina']); if ($line['zoop_hp'] < $maxhp) { $newhp = min(floor($line['zoop_hp'] + ($maxhp / 3)), $maxhp); } else { $newhp = $line['zoop_hp']; } $potatoesmined = $line['potatoesmined']; if ($line['potatominers'] > 0) { $potatoesmined += $line['potatominers'] * $numupdates; $newpotatoes = $line['potatoes'] + ($line['potatominers'] * $numupdates); } else { $newpotatoes = $line['potatoes']; } zoopz_query('UPDATE `accounts` SET `potatoes` = ' . $newpotatoes . ' , `attackturns` = ' . $newattackturns . ' , `zoop_hp` = ' . $newhp . ' , `potatoesmined` = ' . $potatoesmined . ' WHERE `id` = ' . $line['id']); } $newnextrun = $nextrun+($numupdates*1800); zoopz_query("UPDATE `updates` SET `nextrun` = '".$newnextrun."' WHERE `name` = '".$type."'"); $update_halfhour_nextrun = $newnextrun; } elseif ($type=='day') { $numupdates = floor((time()-$nextrun)/86400)+1; $result = zoopz_query("SELECT * FROM `accounts`"); while ($line = $result->fetch_assoc()) { $newtrainingpoints = $line['trainingpoints']+($numupdates*10); if ($newtrainingpoints>100) { $newtrainingpoints = 100; } $newpeopleabletobehired = min(100,$line['peopleabletobehired']+1); zoopz_query("UPDATE `accounts` SET `trainingpoints` = '".$newtrainingpoints."' , `peopleabletobehired` = ".$newpeopleabletobehired." WHERE `id` = '".$line['id']."'"); } zoopz_query("DELETE FROM `attacks`"); zoopz_query("DELETE FROM `votes`"); zoopz_query("UPDATE `accounts` SET `bank_deposits` = '0', `potato_sells` = '0'"); // Lint collection zoopz_query('UPDATE `accounts` SET `zoop_lint` = `zoop_lint` + FLOOR(1 + (RAND() * 5))'); // Old accounts deletion - TODO: Reactivate? no //zoopz_query('DELETE FROM `accounts` WHERE (' . time() . ' - `lastactive`) > 15778463'); // Week old events deletion zoopz_query('DELETE FROM `events` WHERE (' . time() . ' - `timestamp`) > 604800'); $newnextrun = $nextrun+($numupdates*86400); zoopz_query("UPDATE `updates` SET `nextrun` = '".$newnextrun."' WHERE `name` = '".$type."'"); $update_day_nextrun = $newnextrun; } } function calculateLint($lint) { return str_pad(($lint * 0.09991) + ($lint * 0.001327), 8, '0'); } function userInfo($userid) { global $dblink; $result = zoopz_query("SELECT * FROM `accounts` WHERE `id` = '".mysqli_real_escape_string($dblink, $userid)."'"); $rows = $result->num_rows; if ($rows>0) { while ($line = $result->fetch_assoc()) { return $line; } } return false; } function zoopImage($user, $flip = false) { $return = '' . $user['zoop_name'] . ''; return $return; } function itemImage($item) { return '' . $item['name'] . ''; } function itemInformation($item) { $return = '' . $item['name'] . '
' . "\n" . $item['desc']; if ($item['offense'] > 0) { $return .= '
Offense: +' . $item['offense'] . ''; } if ($item['defense'] > 0) { $return .= '
Defense: +' . $item['defense'] . ''; } return $return; } function itemEquip($user, $itemid) { global $dblink; zoopz_query('UPDATE `inventory` SET `equipped` = 1 WHERE `userid` = ' . $user['id'] . ' AND `itemid` = ' . mysqli_real_escape_string($dblink, $itemid) . ' LIMIT 1'); } function itemUnequip($user, $itemid) { global $dblink; zoopz_query('UPDATE `inventory` SET `equipped` = 0 WHERE `userid` = ' . $user['id'] . ' AND `itemid` = ' . mysqli_real_escape_string($dblink, $itemid) . ' LIMIT 1'); } function getUserItems($user, $onlyequipped = false, $type = '') { $query = 'SELECT * FROM `inventory` WHERE `userid` = ' . $user['id']; if ($onlyequipped) { $query .= ' AND `equipped` = 1'; } $query .= ' ORDER BY `equipped` DESC'; $result = zoopz_query($query); $rows = $result->num_rows; if ($rows>0) { $return = array(); if ($type != '') { while ($line = $result->fetch_assoc()) { $item = getItem($line['itemid']); if ($item['type'] == $type) { $return[] = $line; } } } else { while ($line = $result->fetch_assoc()) { $return[] = $line; } } return $return; } return array(); } function getItem($itemid) { global $dblink; $result = zoopz_query('SELECT * FROM `items` WHERE `id` = ' . mysqli_real_escape_string($dblink, $itemid) . ' LIMIT 1'); $rows = $result->num_rows; if ($rows>0) { while ($line = $result->fetch_assoc()) { return $line; } } return false; } function hasItem($user, $itemid) { global $dblink; $result = zoopz_query('SELECT * FROM `inventory` WHERE `itemid` = ' . mysqli_real_escape_string($dblink, $itemid) . ' AND `userid` = ' . $user['id'] . ' LIMIT 1'); $itemsheld = $result->num_rows; if ($itemsheld > 0) { return true; } else { return false; } } function hasItemTypeEquipped($user, $itemtype) { $result = zoopz_query('SELECT * FROM `inventory` JOIN `items` ON `inventory`.`itemid` = `items`.`id` AND `items`.`type` = \'' . $itemtype . '\' WHERE `inventory`.`userid` = ' . $user['id'] . ' AND `inventory`.`equipped` = 1 LIMIT 1'); $itemsheld = $result->num_rows; if ($itemsheld > 0) { return true; } else { return false; } } function giveItem($user, $itemid) { zoopz_query('INSERT INTO `inventory` ( `userid`, `itemid` ) VALUES ( \'' . $user['id'] . '\', \'' . $itemid . '\' )'); } function deleteItem($user, $itemid) { zoopz_query('DELETE FROM `inventory` WHERE `userid` = \'' . $user['id'] . '\' AND `itemid` = \'' . $itemid . '\' LIMIT 1'); } function insertEvent($user, $message, $category = 0) { global $dblink; /* 1 - ? 2 - Fight 3 - Items */ zoopz_query('INSERT INTO `events` ( `userid`, `category`, `timestamp`, `message` ) VALUES ( \'' . $user['id'] . '\', \'' . $category . '\', \'' . time() . '\', \'' . mysqli_real_escape_string($dblink, $message) . '\' )'); } function rewardLevelUp() { global $user; zoopz_query('UPDATE `accounts` SET `trainingpoints` = (`trainingpoints` + ' . ($user['zoop_level'] * 10) . ') WHERE `id` = ' . $user['id'] . ''); } function canFight($user) { $halfhp = (calculateMaxHP($user['zoop_level'], $user['zoop_stamina']) / 2); if ($user['zoop_hp'] >= $halfhp) { return true; } return false; } function calculateMaxHP($level, $stamina) { return ($level * 50 + calculateStaminaHPBonus($stamina, $level)); } function calculateStaminaHPBonus($stamina, $level) { return floor($stamina * ($level * 0.25)); } function battleEndMessage($won, $money, $potatoes, $xp) { $return = 'You have '; $return .= ($won) ? 'gained' : 'lost'; $return .= ' ' . $money . ' Quetzals'; if ($potatoes > 0) { $return .= ', ' . $potatoes . ' potatoes'; } if ($xp > 0) { $return .= ', ' . $xp . ' XP'; } $return .= ' from the fight.'; return $return; } function battleEndEvent($won, $username, $money, $potatoes, $xp) { $return = $username . ' attacked your zoop and '; $return .= ($won) ? 'lost!' : 'won!'; $return .= ' You '; $return .= ($won) ? 'gained' : 'lost'; $return .= ' ' . $money . ' Quetzals'; if ($potatoes > 0) { $return .= ' and ' . $potatoes . ' potatoes'; } $return .= ' from the fight.'; return $return; } function potatoSackCapacity($user) { $useritems = getUserItems($user, true, 'potatosack'); foreach ($useritems as $useritem) { $item = getItem($useritem['itemid']); return $item['special']; } return 0; } function handleBattlePotatoes($winner, $loser) { $potatoesgained = 0; if ($loser['potatoes'] > 0) { $potatosackcapacity = potatoSackCapacity($winner); if ($potatosackcapacity > 0) { $potatoesgained = min($potatosackcapacity, $loser['potatoes']); } } return $potatoesgained; } function handleBattleItems($user, $attacker = true) { $useritems = getUserItems($user, true); $attack_buff = 0; $defend_buff = 0; foreach ($useritems as $useritem) { $item = getItem($useritem['itemid']); if ($item['type'] == 'offense') { if ($attacker) { $attack_buff += rand(floor($item['offense'] / 3), $item['offense']); } } if ($item['type'] == 'defense') { if (!$attacker) { $defend_buff += rand(floor($item['defense'] / 3), $item['defense']); } } } return array('atk' => $attack_buff, 'def' => $defend_buff); } function handleBreakableItems($user) { $useritems = getUserItems($user, true); foreach ($useritems as $useritem) { $item = getItem($useritem['itemid']); if ($item['type'] == 'offense' || $item['type'] == 'defense') { $rand = rand(1, 333); if ($rand == 111) { insertEvent($user, 'Your ' . $item['name'] . ' fell apart! It wasn\'t the best of quality; it was most likely made by a zoop.', 3); deleteItem($user, $item['id']); } } elseif ($item['type'] == 'potatosack') { $rand = rand(1, 200); if ($rand == 9) { insertEvent($user, 'Your ' . $item['name'] . ' fell apart! You should probably go buy a new one in the market.', 3); deleteItem($user, $item['id']); } } } } function checkCaptcha() { // CAPTCHA is currently disabled. return true; } function resetCaptchaTimer() { global $user; zoopz_query('UPDATE `accounts` SET `nextcaptcha` = ' . (time() + 1200) . ' WHERE `id` = ' . $user['id'] . ' LIMIT 1'); } function do_display() { global $smarty, $page_main, $page_infobar, $page_menu, $page_notification_bad, $page_notification_good, $update_halfhour_nextrun, $user_isloggedin, $user; $page_menu .= '

Menu

'; $page_menu .= '

Game

'; if ($user_isloggedin) { $page_menu .= '

Places

Account

'; } $page_menu .= '

Updates

'; /* Calculate at the end to provide up to date stats when the page is loaded, instead of requiring the user to get a new page */ if ($user_isloggedin) { $hp_percentage = round($user['zoop_hp'] / $user['zoop_maxhp'], 2) * 100; $bars_filled = floor($hp_percentage / 10); $bars_notfilled = 10 - $bars_filled; $page_infobar .= 'Zoop: ' . $user['zoop_name'] . ' | HP:  '; if ($bars_filled > 0) { $page_infobar .= ''; for ($i = 0; $i < $bars_filled; $i++) { $page_infobar .= ' '; } $page_infobar .= ''; } if ($bars_notfilled > 0) { $page_infobar .= ''; for ($i = 0; $i < $bars_notfilled; $i++) { $page_infobar .= ' '; } $page_infobar .= ''; } $page_infobar .= '  ' . $user['zoop_hp'] . '/' . $user['zoop_maxhp'] . '  [' . $hp_percentage . '%]' . ' | Level: ' . $user['zoop_level'] . ' | XP: ' . $user['zoop_xp'] . '/' . $user['zoop_xp_nextlevel'] . ' | Attack Turns: ' . $user['attackturns'] . ' | Quetzals: ' . $user['money'].''; } else { $page_infobar .= 'Log in or sign up to view your Zoop\'s stats!'; } $page_notification = ''; if ($page_notification_bad != array()) { $page_notification .= '
'; foreach ($page_notification_bad as $notification) { $page_notification .= '

'.$notification.'

'; } $page_notification .= '
'; } if ($page_notification_good != array()) { $page_notification .= '
'; foreach ($page_notification_good as $notification) { $page_notification .= '

' . $notification . '

'; } $page_notification .= '
'; } $smarty->assign('main', $page_main); $smarty->assign('infobar', $page_infobar); $smarty->assign('menu', $page_menu); $smarty->assign('notification', $page_notification); $smarty->display('index.tpl'); die(); }