mirror of
https://github.com/ErikasKontenis/SabrehavenServer.git
synced 2025-10-14 06:34:55 +02:00
introduce guild bank system
This commit is contained in:
@@ -292,9 +292,15 @@ bool BehaviourDatabase::loadActions(ScriptReader& script, NpcBehaviour* behaviou
|
||||
} else if (identifier == "withdraw") {
|
||||
action->type = BEHAVIOUR_TYPE_WITHDRAW;
|
||||
searchType = BEHAVIOUR_PARAMETER_ONE;
|
||||
} else if (identifier == "guildwithdraw") {
|
||||
action->type = BEHAVIOUR_TYPE_GUILDWITHDRAW;
|
||||
searchType = BEHAVIOUR_PARAMETER_ONE;
|
||||
} else if (identifier == "deposit") {
|
||||
action->type = BEHAVIOUR_TYPE_DEPOSIT;
|
||||
searchType = BEHAVIOUR_PARAMETER_ONE;
|
||||
} else if (identifier == "guilddeposit") {
|
||||
action->type = BEHAVIOUR_TYPE_GUILDDEPOSIT;
|
||||
searchType = BEHAVIOUR_PARAMETER_ONE;
|
||||
} else if (identifier == "transfer") {
|
||||
action->type = BEHAVIOUR_TYPE_TRANSFER;
|
||||
searchType = BEHAVIOUR_PARAMETER_ONE;
|
||||
@@ -535,6 +541,9 @@ NpcBehaviourNode* BehaviourDatabase::readValue(ScriptReader& script)
|
||||
} else if (identifier == "level") {
|
||||
node = new NpcBehaviourNode();
|
||||
node->type = BEHAVIOUR_TYPE_LEVEL;
|
||||
} else if (identifier == "guildlevel") {
|
||||
node = new NpcBehaviourNode();
|
||||
node->type = BEHAVIOUR_TYPE_GUILDLEVEL;
|
||||
} else if (identifier == "poison") {
|
||||
node = new NpcBehaviourNode();
|
||||
node->type = BEHAVIOUR_TYPE_POISON;
|
||||
@@ -1063,11 +1072,57 @@ void BehaviourDatabase::checkAction(const NpcBehaviourAction* action, Player* pl
|
||||
player->setBankBalance(player->getBankBalance() - money);
|
||||
break;
|
||||
}
|
||||
case BEHAVIOUR_TYPE_GUILDWITHDRAW: {
|
||||
int32_t money = evaluate(action->expression, player, message);
|
||||
const Guild* playerGuild = player->getGuild();
|
||||
if (!playerGuild) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (player->getGuildRank()->level <= 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (money <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (IOLoginData::getGuildBalance(playerGuild->getId()) < static_cast<uint64_t>(money)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (IOLoginData::decreaseGuildBankBalance(playerGuild->getId(), money)) {
|
||||
player->setBankBalance(player->getBankBalance() + money);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case BEHAVIOUR_TYPE_DEPOSIT: {
|
||||
int32_t money = evaluate(action->expression, player, message);
|
||||
player->setBankBalance(player->getBankBalance() + money);
|
||||
break;
|
||||
}
|
||||
case BEHAVIOUR_TYPE_GUILDDEPOSIT: {
|
||||
int32_t money = evaluate(action->expression, player, message);
|
||||
const Guild* playerGuild = player->getGuild();
|
||||
if (!playerGuild) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (money <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (player->getBankBalance() < static_cast<uint64_t>(money)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (IOLoginData::increaseGuildBankBalance(playerGuild->getId(), money)) {
|
||||
player->setBankBalance(player->getBankBalance() - money);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case BEHAVIOUR_TYPE_TRANSFER: {
|
||||
int32_t money = evaluate(action->expression, player, message);
|
||||
uint16_t state = 0;
|
||||
@@ -1207,6 +1262,14 @@ int32_t BehaviourDatabase::evaluate(NpcBehaviourNode* node, Player* player, cons
|
||||
}
|
||||
case BEHAVIOUR_TYPE_LEVEL:
|
||||
return player->getLevel();
|
||||
case BEHAVIOUR_TYPE_GUILDLEVEL: {
|
||||
const Guild* playerGuild = player->getGuild();
|
||||
if (!playerGuild) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return player->getGuildRank()->level;
|
||||
}
|
||||
case BEHAVIOUR_TYPE_RANDOM: {
|
||||
int32_t min = evaluate(node->left, player, message);
|
||||
int32_t max = evaluate(node->right, player, message);
|
||||
|
@@ -63,6 +63,7 @@ enum NpcBehaviourType_t
|
||||
BEHAVIOUR_TYPE_SPELLLEVEL, // get spell level
|
||||
BEHAVIOUR_TYPE_TEACHSPELL, // player learn spell
|
||||
BEHAVIOUR_TYPE_LEVEL, // get player level
|
||||
BEHAVIOUR_TYPE_GUILDLEVEL, // get player guild level
|
||||
BEHAVIOUR_TYPE_RANDOM, // random value
|
||||
BEHAVIOUR_TYPE_QUESTVALUE, // get/set quest value
|
||||
BEHAVIOUR_TYPE_TELEPORT, // teleport player to position
|
||||
@@ -83,7 +84,9 @@ enum NpcBehaviourType_t
|
||||
BEHAVIOUR_TYPE_BALANCE, // return player balance
|
||||
BEHAVIOUR_TYPE_GUILDBALANCE, // return guild balance
|
||||
BEHAVIOUR_TYPE_WITHDRAW, // withdraw from player bank balance
|
||||
BEHAVIOUR_TYPE_GUILDWITHDRAW, // withdraw from guild bank balance
|
||||
BEHAVIOUR_TYPE_DEPOSIT, // deposit x amount of gold
|
||||
BEHAVIOUR_TYPE_GUILDDEPOSIT, // deposit x amount of gold to guild
|
||||
BEHAVIOUR_TYPE_TRANSFER, // transfer x amount of gold
|
||||
BEHAVIOUR_TYPE_EXPERIENCESTAGE, // get experience staged based on player level
|
||||
BEHAVIOUR_TYPE_BLESS, // add blessing to player
|
||||
|
@@ -930,6 +930,20 @@ void IOLoginData::increaseBankBalance(uint32_t guid, uint64_t bankBalance)
|
||||
Database::getInstance()->executeQuery(query.str());
|
||||
}
|
||||
|
||||
bool IOLoginData::increaseGuildBankBalance(uint32_t guid, uint64_t bankBalance)
|
||||
{
|
||||
std::ostringstream query;
|
||||
query << "UPDATE `guilds` SET `balance` = `balance` + " << bankBalance << " WHERE `id` = " << guid;
|
||||
return Database::getInstance()->executeQuery(query.str());
|
||||
}
|
||||
|
||||
bool IOLoginData::decreaseGuildBankBalance(uint32_t guid, uint64_t bankBalance)
|
||||
{
|
||||
std::ostringstream query;
|
||||
query << "UPDATE `guilds` SET `balance` = `balance` - " << bankBalance << " WHERE `id` = " << guid;
|
||||
return Database::getInstance()->executeQuery(query.str());
|
||||
}
|
||||
|
||||
void IOLoginData::increaseBankBalance(std::string name, uint64_t bankBalance)
|
||||
{
|
||||
Database* db = Database::getInstance();
|
||||
|
@@ -51,6 +51,8 @@ class IOLoginData
|
||||
static std::string getNameByGuid(uint32_t guid);
|
||||
static bool formatPlayerName(std::string& name);
|
||||
static void increaseBankBalance(uint32_t guid, uint64_t bankBalance);
|
||||
static bool increaseGuildBankBalance(uint32_t guid, uint64_t bankBalance);
|
||||
static bool decreaseGuildBankBalance(uint32_t guid, uint64_t bankBalance);
|
||||
static void increaseBankBalance(const std::string name, uint64_t bankBalance);
|
||||
static bool hasBiddedOnHouse(uint32_t guid);
|
||||
|
||||
|
Reference in New Issue
Block a user