/** * Buy XP in-game // function is still working with usernames instead of UUID since * the /xp command does not work with UUIDs (yet) * * * @global type $UMC_USER */ function umc_do_buyxp() { global $UMC_USER; $player = $UMC_USER['username']; $args = $UMC_USER['args']; $xp_ratio = 1; // check to see if player has entered a value of xp to buy if (isset($args[2])) { // feedback on current xp point values $user_xp = $UMC_USER['xp']; umc_echo("{white} You started with {$user_xp} experience points."); // amount player is trying to spend $amount = $args[2]; // cast argument to type int to sanitise the data settype($amount, 'int'); // amount of xp calculated $xp = floor($amount * $xp_ratio); // retrieve the players balance to check if they can afford $balance = umc_money_check($player); if ($xp < 1 || $amount < 1) { umc_error("{red}You need to buy at least 1 XP. For {$amount} Uncs you get only {$xp} XP (ratio is {$xp_ratio}!)"); } if ($amount > $balance) { umc_error("{red}Sorry, you cannot afford this purchase. You currently have {$balance} uncs."); } // calculate the total new xp point value $new_xp = $user_xp + $xp; // apply purchase // send the console command to give the player experience umc_ws_cmd("exp set {$player} {$new_xp}", 'asConsole'); // take the purchase amount from players account. // take from, give to, positive value umc_money($player, false, $amount); // announce the purchase to encourage players to consider buying xp umc_announce("{gold}{$player}{gray} just bought {purple}{$xp} XP{gray} for{cyan} {$amount} Uncs{gray}!"); umc_echo("{white} You ended with {$new_xp} experience points."); // log the purchase umc_log('buyxp', 'buy', "{$player} paid {$amount} for {$xp} XP, going from {$user_xp} to {$new_xp}"); } else { umc_error("{red}You need to specify the amount of Uncs you want to spend. See {yellow}/helpme buyxp"); } }
function umc_hunger_check_winner() { global $HUNGER, $UMC_PLAYER; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); umc_hunger_find_current_game(); $player_list = $HUNGER['current_game']['players']['alive']; $id = $HUNGER['current_game']['id']; // if there is only one player. it's the winner if (sizeof($player_list) == 1) { $winner_uuid = key($player_list); XMPP_ERROR_send_msg("Found winner! {$winner_uuid}"); $winner = current($player_list); if (!in_array($winner, $UMC_PLAYER['online_players']['alive'])) { $sql_game = "UPDATE minecraft_iconomy.`hunger_games`\r\n SET status='aborted', end=NOW() WHERE id = {$id};"; umc_mysql_query($sql_game, true); $sql_player = "UPDATE minecraft_iconomy.`hunger_players`\r\n SET status='left' WHERE uuid='{$winner_uuid}' and game_id = {$id};"; umc_mysql_query($sql_player, true); if ($HUNGER['announce']) { umc_announce("The Hunger Game has been {red}aborted{purple}, no active players online.", $HUNGER['channel']); } else { umc_echo("The Hunger Game has been {red}aborted{purple}, no active players online."); } } $sql_winner = "UPDATE minecraft_iconomy.`hunger_games`\r\n SET status='ended', winner='{$winner_uuid}', end=NOW() WHERE id = {$id};"; umc_mysql_query($sql_winner, true); $sql = "UPDATE minecraft_iconomy.`hunger_players` SET status='winner' WHERE uuid='{$winner_uuid}' and game_id = {$id};"; umc_mysql_query($sql, true); if ($HUNGER['announce']) { umc_announce("{yellow}The Hunger Game has ended! {gold}{$winner}{yellow} wins!;", $HUNGER['channel']); } else { umc_echo("{yellow}The Hunger Game has ended! {gold}{$winner}{yellow} wins!;"); } umc_hunger_remove_perms('all'); umc_hunger_kill_all_in_world(); return true; } else { return false; } }
/** * Create a request * * @global type $UMC_USER * @return type */ function umc_do_request() { global $UMC_USER; $player = $UMC_USER['username']; $uuid = $UMC_USER['uuid']; $args = $UMC_USER['args']; // this returns a item_array already $item_check = umc_sanitize_input($args[2], 'item'); if (!$item_check) { umc_error("{red}Unknown item ({yellow}{$args['2']}{red}). Try using {yellow}/search{red} to find names."); } else { XMPP_ERROR_trace("item_check", $item_check); $item = umc_goods_get_text($item_check['item_name'], $item_check['type']); } $item_name = $item['item_name']; $type = $item['type']; $meta = ''; $meta_txt = ''; $do_check = false; $pos = array_search('check', $args); if ($pos) { $do_check = true; array_splice($args, $pos, 1); } // TODO: This should be checking for the item type instead of assuming 0 //if ($UMC_ITEMS[$type][0]['avail'] == false) { // umc_error("{red}Sorry, this item (ID $type) is unavailable in the game!",true); //} $sql = "SELECT * FROM minecraft_iconomy.request\r\n WHERE item_name='{$item_name}' AND damage='{$type}' AND meta='{$meta}' AND uuid='{$uuid}';"; $sql_data = umc_mysql_fetch_all($sql); if (count($sql_data) == 0) { $row = false; } else { $row = $sql_data[0]; } // buy item at same price, check if exists if (!isset($args[3])) { if ($row) { $price = $row['price']; } else { umc_error("{red}Since you do not have the same item already in the shop you need to specify a price.;"); } } else { $price = umc_sanitize_input($args[3], 'price'); } // check if an argument was given for amount. $amount = umc_sanitize_input($args[4], 'amount'); if ($amount == NULL) { // buying 0 amount available is not possible umc_error("{red}You need to specify an amount, too!;"); } $cost = $price * $amount; // if there is an existing row, recalculate price accordingly if ($row) { // give money back from the original request $refund = $row['amount'] * $row['price']; // calculate how much this one + the old item amount would cost $new_cost = ($amount + $row['amount']) * $price; // do the sum for the balance, can be negative $cost = $new_cost - $refund; } $balance = umc_money_check($uuid); if ($balance < $cost) { umc_error("{red}[!]{gray} Insufficient funds ({white}{$cost}{gray} needed). " . "{purple}[?]{white} Why don't you vote for the server and try again?"); } if ($do_check) { if ($row) { $sum = $amount + $row['amount']; umc_echo("{white}[?]{gray} This would update your existing request to " . "{yellow}{$sum} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each."); } else { umc_echo("{white}[?]{gray} This would create a new request for " . "{yellow}{$amount} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each."); } if ($cost > 0) { umc_echo("{white}[?]{white} Your account would be charged {cyan}{$cost}{gray} Uncs."); } else { umc_echo("{white}[?]{white} Your account would be credited {cyan}" . $cost * -1 . "{gray} Uncs."); } return; } $sum = 0; $posted_id = 0; if ($row) { // Update existing listing $sum = $amount + $row['amount']; umc_echo("{green}[+]{gray} You already requested {yellow}" . "{$row['amount']} {$item['full']}{gray}. Adding another {yellow}{$amount}{gray}."); $sql = "UPDATE minecraft_iconomy.`request` SET `amount` = amount + '{$amount}', price='{$price}' WHERE id={$row['id']};"; $rst = umc_mysql_query($sql); $posted_id = $row['id']; } else { // Create a new listing. $sum = $amount; umc_echo("{green}[+]{gray} You are now requesting {yellow}" . "{$sum} {$item['full']}{gray} in the shop."); $sql = "INSERT INTO minecraft_iconomy.`request` (`id` ,`damage` ,`uuid` ,`item_name` ,`price` ,`amount` ,`meta`)\r\n VALUES (NULL , '{$type}', '{$uuid}', '{$item['item_name']}', '{$price}', '{$amount}', '{$meta}');"; //XMPP_ERROR_trigger($sql); $rst = umc_mysql_query($sql); $posted_id = umc_mysql_insert_id(); } if ($cost > 0) { umc_echo("{yellow}[\$]{white} Your account has been charged {cyan}{$cost}{gray} Uncs."); } else { umc_echo("{green}[\$]{white} Your account has been credited {cyan}" . $cost * -1 . "{gray} Uncs."); } umc_money($player, false, $cost); umc_announce("{gold}{$player}{gray} is {red}requesting to buy {yellow}{$sum}{$meta_txt}{green} " . "{$item['full']}{darkgray} @ {cyan}{$price}{gray} each{darkgray}, shop-id {gray}{$posted_id}"); }