forked from townforge/townforge
fix choice reserves acounting
This commit is contained in:
parent
ccf94054fa
commit
88442e6bc5
@ -286,31 +286,29 @@ bool cc_command_handler_script_choice::execute(cryptonote::BlockchainDB &db, con
|
||||
|
||||
if (cc::script::is_end_state(script, new_state))
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(script_choice.cc_account, ad_player), false, "Failed to get account data");
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(ad_player.script_owner, ad_owner), false, "Failed to get account data");
|
||||
|
||||
const uint32_t owner = ad_player.script_owner;
|
||||
|
||||
const auto &player_account_data = ad_player.reserve[owner];
|
||||
const auto &owner_account_data = ad_owner.reserve[script_choice.cc_account];
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(script_choice.cc_account, ad_player), false, "Failed to get account data");
|
||||
|
||||
const auto &player_account_data = ad_player.reserve[owner];
|
||||
if (player_account_data.first != 0)
|
||||
effects.balance_reserve.push_back({script_choice.cc_account, owner, make_signed_checked(player_account_data.first)});
|
||||
for (const auto &e: player_account_data.second)
|
||||
if (e.second != 0)
|
||||
effects.item_reserve.push_back({script_choice.cc_account, owner, e.first, make_signed_checked(e.second)});
|
||||
if (owner != script_choice.cc_account)
|
||||
{
|
||||
if (owner_account_data.first != 0)
|
||||
effects.balance_reserve.push_back({owner, script_choice.cc_account, make_signed_checked(owner_account_data.first)});
|
||||
for (const auto &e: owner_account_data.second)
|
||||
if (e.second != 0)
|
||||
effects.item_reserve.push_back({owner, script_choice.cc_account, e.first, make_signed_checked(e.second)});
|
||||
}
|
||||
|
||||
db.unreserve_cc_account(script_choice.cc_account, owner, player_account_data.first, player_account_data.second);
|
||||
if (owner != script_choice.cc_account)
|
||||
db.unreserve_cc_account(owner, script_choice.cc_account, owner_account_data.first, owner_account_data.second);
|
||||
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(ad_player.script_owner, ad_owner), false, "Failed to get account data");
|
||||
|
||||
const auto &owner_account_data = ad_owner.reserve[script_choice.cc_account];
|
||||
if (owner_account_data.first != 0)
|
||||
effects.balance_reserve.push_back({owner, script_choice.cc_account, make_signed_checked(owner_account_data.first)});
|
||||
for (const auto &e: owner_account_data.second)
|
||||
if (e.second != 0)
|
||||
effects.item_reserve.push_back({owner, script_choice.cc_account, e.first, make_signed_checked(e.second)});
|
||||
|
||||
db.unreserve_cc_account(owner, script_choice.cc_account, owner_account_data.first, owner_account_data.second);
|
||||
|
||||
for (const auto &e: ad_player.script_string_overrides)
|
||||
effects.string_override_removals.push_back({e.first, e.second});
|
||||
@ -494,11 +492,29 @@ bool cc_command_handler_script_choice::revert(cryptonote::BlockchainDB &db, cons
|
||||
db.set_cc_account_script_variable(script_choice.cc_account, e.name, db.get_cc_account_script_variable(script_choice.cc_account, e.name, true) - e.value_delta, true);
|
||||
}
|
||||
|
||||
// the reserves increase from execute will have been recorded in effects,
|
||||
// therefore already undone, we just have the actual balances to update
|
||||
uint64_t reserved_owner_balance, reserved_player_balance;
|
||||
std::map<uint32_t, uint32_t> reserved_owner_items, reserved_player_items;
|
||||
cc::script::get_choice_reserves(db, script, script_choice.state, script_choice.choice, {}, {}, reserved_owner_balance, reserved_owner_items, reserved_player_balance, reserved_player_items, script_choice.cc_account, script_choice.owner, script_choice.city);
|
||||
db.unreserve_cc_account(script_choice.owner, script_choice.cc_account, reserved_owner_balance, reserved_owner_items);
|
||||
db.unreserve_cc_account(script_choice.cc_account, script_choice.owner, reserved_player_balance, reserved_player_items);
|
||||
if (reserved_owner_balance || !reserved_owner_items.empty())
|
||||
{
|
||||
cryptonote::cc_account_data_t ad;
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(script_choice.owner, ad), false, "Failed to get account data");
|
||||
ad.balance += reserved_owner_balance;
|
||||
for (const auto &e: reserved_owner_items)
|
||||
ad.item_balances[e.first] += e.second;
|
||||
db.set_cc_account_data(script_choice.owner, ad);
|
||||
}
|
||||
if (reserved_player_balance || !reserved_player_items.empty())
|
||||
{
|
||||
cryptonote::cc_account_data_t ad;
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(script_choice.cc_account, ad), false, "Failed to get account data");
|
||||
ad.balance += reserved_player_balance;
|
||||
for (const auto &e: reserved_player_items)
|
||||
ad.item_balances[e.first] += e.second;
|
||||
db.set_cc_account_data(script_choice.cc_account, ad);
|
||||
}
|
||||
|
||||
cryptonote::cc_account_data_t ad_player;
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(script_choice.cc_account, ad_player), false, "Account not found");
|
||||
|
@ -236,27 +236,29 @@ bool cc_command_handler_start_script::execute(cryptonote::BlockchainDB &db, cons
|
||||
|
||||
if (cc::script::is_end_state(script, 0))
|
||||
{
|
||||
cryptonote::cc_account_data_t ad_player, ad_owner;
|
||||
cryptonote::cc_account_data_t ad_player;
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(start_script.cc_account, ad_player), false, "Account not found");
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(owner, ad_owner), false, "Account not found");
|
||||
|
||||
const auto &player_account_data = ad_player.reserve[owner];
|
||||
const auto &owner_account_data = ad_owner.reserve[start_script.cc_account];
|
||||
|
||||
if (player_account_data.first != 0)
|
||||
effects.balance_reserve.push_back({start_script.cc_account, owner, make_signed_checked(player_account_data.first)});
|
||||
for (const auto &e: player_account_data.second)
|
||||
if (e.second != 0)
|
||||
effects.item_reserve.push_back({start_script.cc_account, owner, e.first, make_signed_checked(e.second)});
|
||||
|
||||
db.unreserve_cc_account(start_script.cc_account, owner, player_account_data.first, player_account_data.second);
|
||||
|
||||
cryptonote::cc_account_data_t ad_owner;
|
||||
CHECK_AND_ASSERT_MES(db.get_cc_account_data(owner, ad_owner), false, "Account not found");
|
||||
|
||||
const auto &owner_account_data = ad_owner.reserve[start_script.cc_account];
|
||||
if (owner_account_data.first != 0)
|
||||
effects.balance_reserve.push_back({owner, start_script.cc_account, make_signed_checked(owner_account_data.first)});
|
||||
for (const auto &e: owner_account_data.second)
|
||||
if (e.second != 0)
|
||||
effects.item_reserve.push_back({owner, start_script.cc_account, e.first, make_signed_checked(e.second)});
|
||||
|
||||
db.unreserve_cc_account(start_script.cc_account, owner, player_account_data.first, player_account_data.second);
|
||||
if (owner != start_script.cc_account)
|
||||
db.unreserve_cc_account(owner, start_script.cc_account, owner_account_data.first, owner_account_data.second);
|
||||
db.unreserve_cc_account(owner, start_script.cc_account, owner_account_data.first, owner_account_data.second);
|
||||
}
|
||||
|
||||
if (!effects.new_background_scripts.empty())
|
||||
|
Loading…
Reference in New Issue
Block a user