forked from townforge/townforge
game: display account overview in auctions screen
This commit is contained in:
parent
e2243eb7cd
commit
52c1b87de1
@ -2,6 +2,7 @@
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/type_traits/make_unsigned.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <Urho3D/Math/Color.h>
|
||||
#include "reg_exp_definer.h"
|
||||
#include "common/util.h"
|
||||
@ -511,6 +512,114 @@ std::pair<std::string, crypto::hash> get_item_info(const GameState *game, const
|
||||
return std::make_pair(ss.str(), ipfs_hash);
|
||||
}
|
||||
|
||||
std::string get_flag_info(const GameState *game, const std::shared_ptr<GameWallet> &w, uint32_t id)
|
||||
{
|
||||
const std::shared_ptr<Flag> flag = game->map.get_flag(id);
|
||||
if (!flag)
|
||||
return "Land in another city, travel to this city for details\n";
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Flag " << flag->id;
|
||||
if (!flag->name_hidden.empty())
|
||||
ss << " (" << game_util::get_building_name(game, flag) << ")";
|
||||
ss << "\n";
|
||||
ss << boost::format(" %ux%u %u%% %s land in %s\n")
|
||||
% (flag->x1 - flag->x0 + 1) % (flag->y1 - flag->y0 + 1) % flag->economic_power % cc::get_role_name(flag->role) % game->get_city_name(flag->city);
|
||||
ss << " Owner: " << game->get_player_name(flag->owner) << "\n";
|
||||
ss << " Repair: " << cc::print_repair_percentage(flag->repair) << "\n";
|
||||
ss << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string get_account_info(const GameState *game, const std::shared_ptr<GameWallet> &w, uint32_t id)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "ID: " << id << "\n";
|
||||
|
||||
uint64_t balance;
|
||||
std::map<uint32_t, uint32_t> item_balances;
|
||||
std::vector<uint32_t> flags;
|
||||
std::map<uint32_t, std::pair<uint8_t, uint64_t>> badges;
|
||||
std::map<uint32_t, uint32_t> attributes;
|
||||
std::string name, description, title;
|
||||
std::string public_key, pmspk, pmvpk;
|
||||
bool ignore;
|
||||
uint32_t inviting_account, num_invited, num_invited_bought_land, first_flag;
|
||||
uint32_t script, script_state, script_city, script_owner;
|
||||
std::map<uint32_t, std::pair<uint64_t, std::map<uint32_t, uint32_t>>> reserve;
|
||||
std::map<std::string, uint64_t> script_variables, script_local_variables;
|
||||
std::map<uint32_t, std::pair<uint32_t, std::map<std::string, uint64_t>>> background_script_states;
|
||||
uint32_t prestige, coru_rating;
|
||||
std::vector<uint32_t> textures_created, textures_licenced;
|
||||
int32_t title_adjective, title_noun, title_origin, title_unique;
|
||||
if (w->get_cc_account_data(id, public_key, balance, item_balances, flags, badges, attributes, name, title_adjective, title_noun, title_origin, title_unique, title, description, ignore, inviting_account, num_invited, num_invited_bought_land, first_flag, script, script_state, script_city, script_owner, reserve, script_variables, script_local_variables, background_script_states, prestige, textures_created, textures_licenced, coru_rating, pmspk, pmvpk))
|
||||
{
|
||||
const std::map<uint32_t, uint32_t> items = game_util::get_total_item_balances(item_balances, reserve);
|
||||
uint64_t reserved_balance = 0;
|
||||
for (const auto &e: reserve)
|
||||
reserved_balance += e.second.first;
|
||||
std::vector<uint32_t> badge_count(NUM_BADGE_LEVELS, 0);
|
||||
for (const auto &e: badges)
|
||||
{
|
||||
const uint8_t level = e.second.first;
|
||||
if (level > 0 && level <= NUM_BADGE_LEVELS)
|
||||
badge_count[level - 1] += 1;
|
||||
}
|
||||
const uint32_t level = cc::get_badge_score(badge_count).second;
|
||||
|
||||
ss << "Name: " << name << "\n";
|
||||
ss << "Level: " << level << "\n";
|
||||
ss << "Prestige: " << prestige << "\n";
|
||||
ss << "Balance: " << game_util::print_money(balance);
|
||||
if (reserved_balance > 0)
|
||||
ss << " (+" << game_util::print_money(reserved_balance) << " reserved)";
|
||||
ss << "\n";
|
||||
|
||||
if (!items.empty())
|
||||
{
|
||||
ss << "Inventory:\n";
|
||||
for (const auto &e: items)
|
||||
{
|
||||
const uint32_t type = e.first;
|
||||
const uint32_t amount = e.second;
|
||||
uint32_t reserved_amount = 0;
|
||||
for (const auto &f: reserve)
|
||||
{
|
||||
for (const auto &g: f.second.second)
|
||||
if (g.first == type)
|
||||
reserved_amount += g.second;
|
||||
}
|
||||
ss << " " << std::to_string(amount) << " " << game->get_item_name(type);
|
||||
if (reserved_amount > 0)
|
||||
ss << " (" << std::to_string(reserved_amount) << " reserved)";
|
||||
ss << "\n";
|
||||
}
|
||||
ss << "\n";
|
||||
}
|
||||
|
||||
if (!flags.empty())
|
||||
{
|
||||
ss << std::to_string(flags.size()) << " flags:\n";
|
||||
for (uint32_t flag: flags)
|
||||
{
|
||||
std::string flag_info = get_flag_info(game, w, flag);
|
||||
if (!flag_info.empty())
|
||||
{
|
||||
boost::replace_all(flag_info, "\n", "\n ");
|
||||
ss << " " << flag_info << "\n\n";
|
||||
}
|
||||
}
|
||||
ss << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
ss << "Error getting account data\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void reduce_amount_zeroes(std::string &money)
|
||||
{
|
||||
if (strchr(money.c_str(), '.'))
|
||||
|
@ -25,7 +25,9 @@ std::string get_command_string(const GameState *game, const cryptonote::cc_comma
|
||||
void replace_string(std::string &s, size_t start, size_t len, const std::string &replacement);
|
||||
std::string format_variable(const GameState *game, uint64_t value, const std::string &format);
|
||||
void process_overrides(const GameState *game, std::string &s, const std::vector<std::tuple<uint8_t, uint64_t, std::string>> &overrides, bool in_script);
|
||||
std::pair<std::string, crypto::hash> get_item_info(const GameState *Game, const std::shared_ptr<GameWallet> &w, uint32_t item);
|
||||
std::pair<std::string, crypto::hash> get_item_info(const GameState *game, const std::shared_ptr<GameWallet> &w, uint32_t item);
|
||||
std::string get_flag_info(const GameState *game, const std::shared_ptr<GameWallet> &w, uint32_t id);
|
||||
std::string get_account_info(const GameState *game, const std::shared_ptr<GameWallet> &w, uint32_t account);
|
||||
void reduce_amount_zeroes(std::string &s);
|
||||
std::string print_money(uint64_t amount, bool is_signed = false);
|
||||
uint32_t get_logging_level(const std::shared_ptr<GameWallet> &w, uint32_t account);
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <limits>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
#include "Urho3D/Core/Context.h"
|
||||
#include "Urho3D/Resource/ResourceCache.h"
|
||||
@ -188,27 +187,16 @@ std::string UIAuctionsDialog::GetAuctionDetails(const std::shared_ptr<GameWallet
|
||||
switch (auction.type)
|
||||
{
|
||||
case cc::auction_t::type_flag:
|
||||
for (const auto &e: auction.entries)
|
||||
{
|
||||
for (const auto &e: auction.entries)
|
||||
std::string info = game_util::get_flag_info(game, w, e.first);
|
||||
if (!info.empty())
|
||||
{
|
||||
const std::shared_ptr<Flag> flag = game->map.get_flag(e.first);
|
||||
if (!flag)
|
||||
{
|
||||
ss << "Land in another city, travel to this city for details\n";
|
||||
break;
|
||||
}
|
||||
ss << "Flag " << flag->id;
|
||||
if (!flag->name_hidden.empty())
|
||||
ss << " (" << game_util::get_building_name(game, flag) << ")";
|
||||
ss << "\n";
|
||||
ss << boost::format(" %ux%u %u%% %s land in %s\n")
|
||||
% (flag->x1 - flag->x0 + 1) % (flag->y1 - flag->y0 + 1) % flag->economic_power % cc::get_role_name(flag->role) % game->get_city_name(flag->city);
|
||||
ss << " Owner: " << game->get_player_name(flag->owner) << "\n";
|
||||
ss << " Repair: " << cc::print_repair_percentage(flag->repair) << "\n";
|
||||
ss << "\n";
|
||||
boost::replace_all(info, "\n", "\n ");
|
||||
ss << " " << info << "\n\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case cc::auction_t::type_item:
|
||||
for (const auto &e: auction.entries)
|
||||
{
|
||||
@ -225,6 +213,12 @@ std::string UIAuctionsDialog::GetAuctionDetails(const std::shared_ptr<GameWallet
|
||||
for (const auto &e: auction.entries)
|
||||
{
|
||||
ss << "The '" + game->get_player_name(e.first) + "' Townforge account\n";
|
||||
std::string info = game_util::get_account_info(game, w, e.first);
|
||||
if (!info.empty())
|
||||
{
|
||||
boost::replace_all(info, "\n", "\n ");
|
||||
ss << " " << info << "\n\n";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user