Skip to content

Commit

Permalink
feat: transferring money bank from main/main and rookgaard/rookgaard (#…
Browse files Browse the repository at this point in the history
…2878)

Rookguard town is `town id` 3, so `minTownIdToBankTransfer` defaults to 4

Resolves #2778
  • Loading branch information
Luan Luciano authored Sep 24, 2024
1 parent f0830c3 commit a399c26
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ onlyPremiumAccount = false
-- NOTE: enablePlayerPutItemInAmmoSlot = true, will enable players to put any items on ammo slot, more used in custom shopping system
-- NOTE: startStreakLevel will make a reward streak level for new players who never logged in
-- NOTE: if showLootsInBestiary is true, will cause all loots to be shown in the bestiary even if the player has not reached the required number of kills
-- NOTE: minTownIdToBankTransfer blocks towns less than defined from receiving money transfers
-- NOTE: minTownIdToBankTransferFromMain blocks towns less than defined from receiving money transfers
-- NOTE: enableSupportOutfit enable GODS and GMS to select support outfit (gamemaster, customer support or community manager)
stashMoving = false
stashItemCount = 5000
Expand All @@ -275,7 +275,7 @@ storeInboxMaxLimit = 2000
enablePlayerPutItemInAmmoSlot = false
startStreakLevel = 0
showLootsInBestiary = false
minTownIdToBankTransfer = 3
minTownIdToBankTransferFromMain = 4
enableSupportOutfit = true

-- Teleport summon
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ enum ConfigKey_t : uint16_t {
METRICS_PROMETHEUS_ADDRESS,
MIN_DELAY_BETWEEN_CONDITIONS,
MIN_ELEMENTAL_RESISTANCE,
MIN_TOWN_ID_TO_BANK_TRANSFER,
MIN_TOWN_ID_TO_BANK_TRANSFER_FROM_MAIN,
MOMENTUM_CHANCE_FORMULA_A,
MOMENTUM_CHANCE_FORMULA_B,
MOMENTUM_CHANCE_FORMULA_C,
Expand Down
2 changes: 1 addition & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ bool ConfigManager::load() {
loadIntConfig(L, METRICS_OSTREAM_INTERVAL, "metricsOstreamInterval", 1000);
loadIntConfig(L, MIN_DELAY_BETWEEN_CONDITIONS, "minDelayBetweenConditions", 0);
loadIntConfig(L, MIN_ELEMENTAL_RESISTANCE, "minElementalResistance", -200);
loadIntConfig(L, MIN_TOWN_ID_TO_BANK_TRANSFER, "minTownIdToBankTransfer", 3);
loadIntConfig(L, MIN_TOWN_ID_TO_BANK_TRANSFER_FROM_MAIN, "minTownIdToBankTransferFromMain", 4);
loadIntConfig(L, MONTH_KILLS_TO_RED, "monthKillsToRedSkull", 10);
loadIntConfig(L, MULTIPLIER_ATTACKONFIST, "multiplierSpeedOnFist", 5);
loadIntConfig(L, ORANGE_SKULL_DURATION, "orangeSkullDuration", 7);
Expand Down
29 changes: 20 additions & 9 deletions src/game/bank/bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,28 @@ const std::set<std::string> deniedNames = {
"paladinsample"
};

bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount) {
bool Bank::transferTo(const std::shared_ptr<Bank> &destination, const uint64_t amount) {
if (!destination) {
g_logger().error("Bank::transferTo: destination is nullptr");
return false;
}

auto bankable = getBankable();
const auto bankable = getBankable();
if (!bankable) {
g_logger().error("Bank::transferTo: bankable is nullptr");
return false;
}

auto destinationBankable = destination->getBankable();
const auto destinationBankable = destination->getBankable();
if (!destinationBankable) {
g_logger().error("Bank::transferTo: destinationBankable is nullptr");
return false;
}

auto destinationPlayer = destinationBankable->getPlayer();
if (destinationPlayer != nullptr) {
const auto &destinationPlayer = destinationBankable->getPlayer();
const auto &bankablePlayer = bankable->getPlayer();

if (destinationPlayer && bankablePlayer) {
auto name = asLowerCaseString(destinationPlayer->getName());
replaceString(name, " ", "");

Expand All @@ -108,8 +110,17 @@ bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount)
return false;
}

if (destinationPlayer->getTown()->getID() < g_configManager().getNumber(MIN_TOWN_ID_TO_BANK_TRANSFER, __FUNCTION__)) {
g_logger().warn("Bank::transferTo: denied town: {}", destinationPlayer->getTown()->getID());
const auto destinationTownId = destinationPlayer->getTown()->getID();
const auto bankableTownId = bankablePlayer->getTown()->getID();
const auto minTownIdToTransferFromMain = g_configManager().getNumber(MIN_TOWN_ID_TO_BANK_TRANSFER_FROM_MAIN, __FUNCTION__);

if (destinationTownId < minTownIdToTransferFromMain && bankableTownId >= minTownIdToTransferFromMain) {
g_logger().warn("[{}] Player {} is from main town, trying to transfer money to player {} in {} town.", __FUNCTION__, bankablePlayer->getName(), destinationPlayer->getName(), destinationTownId);
return false;
}

if (bankableTownId < minTownIdToTransferFromMain && destinationTownId >= minTownIdToTransferFromMain) {
g_logger().warn("[{}] Player {} is not from main town, trying to transfer money to player {} in {} town.", __FUNCTION__, bankablePlayer->getName(), destinationPlayer->getName(), destinationTownId);
return false;
}
}
Expand All @@ -122,8 +133,8 @@ bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount)
g_metrics().addCounter("balance_increase", amount, { { "player", destinationPlayer->getName() }, { "context", "bank_transfer" } });
}

if (bankable->getPlayer()) {
g_metrics().addCounter("balance_decrease", amount, { { "player", bankable->getPlayer()->getName() }, { "context", "bank_transfer" } });
if (bankablePlayer) {
g_metrics().addCounter("balance_decrease", amount, { { "player", bankablePlayer->getName() }, { "context", "bank_transfer" } });
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/game/bank/bank.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Bank : public SharedObject {
bool balance(uint64_t amount) const;
uint64_t balance();
bool hasBalance(uint64_t amount);
bool transferTo(const std::shared_ptr<Bank> destination, uint64_t amount);
bool transferTo(const std::shared_ptr<Bank> &destination, const uint64_t amount);
bool withdraw(std::shared_ptr<Player> player, uint64_t amount);
bool deposit(const std::shared_ptr<Bank> destination);
bool deposit(const std::shared_ptr<Bank> destination, uint64_t amount);
Expand Down
13 changes: 6 additions & 7 deletions src/lua/functions/core/game/bank_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,36 @@ int BankFunctions::luaBankHasBalance(lua_State* L) {

int BankFunctions::luaBankTransfer(lua_State* L) {
// Bank.transfer(fromPlayerOrGuild, toPlayerOrGuild, amount)
auto source = getBank(L, 1);
const auto &source = getBank(L, 1);
if (source == nullptr) {
g_logger().debug("BankFunctions::luaBankTransfer: source is null");
reportErrorFunc("Bank is nullptr");
return 1;
}
std::shared_ptr<Bank> destination = getBank(L, 2);
const auto &destination = getBank(L, 2);
if (destination == nullptr) {
g_logger().debug("BankFunctions::luaBankTransfer: destination is null");
reportErrorFunc("Bank is nullptr");
return 1;
}
uint64_t amount = getNumber<uint64_t>(L, 3);
const uint64_t amount = getNumber<uint64_t>(L, 3);
pushBoolean(L, source->transferTo(destination, amount));
return 1;
}

int BankFunctions::luaBankTransferToGuild(lua_State* L) {
// Bank.transfer(fromPlayerOrGuild, toGuild, amount)
auto source = getBank(L, 1);
const auto &source = getBank(L, 1);
if (source == nullptr) {
reportErrorFunc("Source is nullptr");
return 1;
}

std::shared_ptr<Bank> destination = getBank(L, 2, true /* isGuild */);
const auto &destination = getBank(L, 2, true /* isGuild */);
if (destination == nullptr) {
reportErrorFunc("Destination is nullptr");
return 1;
}
uint64_t amount = getNumber<uint64_t>(L, 3);
const uint64_t amount = getNumber<uint64_t>(L, 3);
pushBoolean(L, source->transferTo(destination, amount));
return 1;
}
Expand Down

0 comments on commit a399c26

Please sign in to comment.