Example #1
0
function get_current_enemies()
{
    $query = 'SELECT player_id, active, level, uname, health, least(100,floor((health / (150 + ((level-1)*25))::float)*100)) 
		AS health_percent FROM players JOIN enemies ON _enemy_id = player_id AND _player_id = :pid 
		WHERE active = 1 ORDER BY health DESC, level DESC';
    return query_resultset($query, [':pid' => self_char_id()]);
}
Example #2
0
function get_chats($chatlength = null)
{
    $chatlength = positive_int($chatlength);
    // Prevent negatives.
    $limit = $chatlength ? 'LIMIT :limit' : '';
    $bindings = array();
    if ($limit) {
        $bindings[':limit'] = $chatlength;
    }
    $chats = query_resultset("SELECT sender_id, uname, message, date, age(now(), date) AS ago FROM chat\n        JOIN players ON chat.sender_id = player_id ORDER BY chat_id DESC " . $limit, $bindings);
    return $chats;
}
Example #3
0
function message_to_clan($p_message)
{
    $error = null;
    $user_id = self_char_id();
    $clan_id = get_clan_by_player_id($user_id)->getID();
    $clan_members = query_resultset("SELECT player_id, uname\n\t    FROM clan JOIN clan_player ON _clan_id = clan_id JOIN players ON player_id = _player_id\n\t    WHERE clan_id = :clan", array(':clan' => $clan_id));
    $messaged_to = array();
    foreach ($clan_members as $loop_member) {
        send_message($user_id, $loop_member['player_id'], $p_message, $type = 1);
        $messaged_to[] = $loop_member['uname'];
    }
    return implode(', ', $messaged_to);
}
Example #4
0
function add_item($char_id, $identity, $quantity = 1)
{
    $quantity = (int) $quantity;
    if ($quantity > 0 && !empty($identity)) {
        $up_res = query_resultset("UPDATE inventory SET amount = amount + :quantity\n\t            WHERE owner = :char AND item_type = (select item_id from item where item_internal_name = :identity)", array(':quantity' => $quantity, ':char' => $char_id, ':identity' => $identity));
        $rows = $up_res->rowCount();
        if (!$rows) {
            // No entry was present, insert one.
            query_resultset("INSERT INTO inventory (owner, item_type, amount)\n\t\t        VALUES (:char, (SELECT item_id FROM item WHERE item_internal_name = :identity), :quantity)", array(':char' => $char_id, ':identity' => $identity, ':quantity' => $quantity));
        }
    } else {
        throw new \Exception('Invalid item to add to inventory.');
    }
}
Example #5
0
function save_clan_description($desc, $clan_id)
{
    $update = 'UPDATE clan SET description = :desc WHERE clan_id = :clan_id';
    query_resultset($update, array(':desc' => $desc, ':clan_id' => $clan_id));
}
Example #6
0
function query_row($sql, $bindings = array())
{
    $resultset = query_resultset($sql, $bindings);
    return $resultset->fetch(PDO::FETCH_ASSOC);
}
Example #7
0
 /**
  * Pulls the shop items costs and all.
  */
 private function itemForSaleCosts()
 {
     $sel = 'select item_display_name, item_internal_name, item_cost, image, usage from item where for_sale = TRUE order by image asc, item_cost asc';
     if (defined('DEBUG') && DEBUG) {
         $sel = 'select item_display_name, item_internal_name, item_cost, image, usage from item order by image asc, item_cost asc';
     }
     $items_data = query_resultset($sel);
     // Rearrange the array to use the internal identity as indexes.
     $item_costs = array();
     foreach ($items_data as $item_data) {
         $item_costs[$item_data['item_internal_name']] = $item_data;
     }
     return $item_costs;
 }
 /**
  * Retrieve enemies for the player specified
  *
  * @param int $p_playerId
  * @return resulset
  */
 private function getCurrentEnemies($p_playerId)
 {
     $query = 'SELECT player_id, active, level, uname, health FROM players JOIN enemies ON _enemy_id = player_id AND _player_id = :pid
         WHERE active = 1 ORDER BY health DESC, level DESC';
     return query_resultset($query, [':pid' => $p_playerId]);
 }
Example #9
0
function remove_item($char_id, $identity, $quantity = 1)
{
    $quantity = (int) $quantity;
    if ($quantity > 0 && !empty($identity)) {
        $up_res = query_resultset('UPDATE inventory SET amount = greatest(0, amount - :quantity)
	            WHERE owner = :char AND item_type = (SELECT item_id FROM item WHERE item_internal_name = :identity)', array(':quantity' => $quantity, ':char' => $char_id, ':identity' => $identity));
    } else {
        throw new Exception('Invalid item to remove from inventory.');
    }
}