introduce guild bank system

This commit is contained in:
ErikasKontenis 2020-11-10 19:42:48 +02:00
parent f127b2abf7
commit cf893a1aaa
5 changed files with 119 additions and 0 deletions

View File

@ -14,6 +14,9 @@
"money" -> *
"change" -> *
"exchange" -> *
"guild" -> "If you are a member of a guild, you can deposit money on its account via guild deposit or check the guild money via guild balance. ...",
"If you are leader or vice leader of a guild, you can also withdraw gold from your guild account via guild withdraw. ...",
"Please keep in mind that we may need some time to process such requests."
"change","gold",! -> "How many platinum coins do you want to get?", Topic=91
"exchange","gold",! -> *
@ -90,6 +93,9 @@ Topic=99 -> "Well, can I help you with something else
"balance",balance>9999999 -> Amount=Balance, "You have made ten millions and it still grows! Your account balance is %A gold."
"balance",balance>99999999 -> Amount=Balance, "I think you must be one of the richest inhabitants in the world! Your account balance is %A gold."
"guild","balance" -> "You are not a member of a guild."
"guild","balance",GuildLevel>0 -> Amount=GuildBalance, "Your guild account balance is %A gold."
"deposit" -> "You don't have any gold with you."
"deposit",CountMoney>0 -> "Please tell me how much gold it is you would like to deposit.", Topic=81
"deposit","all",CountMoney>0 -> Price=CountMoney, "Would you really like to deposit %P gold?", Topic=82
@ -104,6 +110,22 @@ Topic=82,"yes",CountMoney>=Price -> "Alright, we have added the amount of %P gol
Topic=82,"yes" -> "I am inconsolable, but it seems you have lost your gold. I hope you get it back."
Topic=82 -> "As you wish. Is there something else I can do for you?"
"guild","deposit",GuildLevel<=0 -> "You are not a member of a guild."
"guild","deposit" -> "You don't have any gold in your bank account."
"guild","deposit",Balance>0 -> "Please tell me how much gold it is you would like to deposit for your guild.", Topic=71
"guild","deposit","all",GuildLevel<=0 -> "You are not a member of a guild."
"guild","deposit","all",Balance>0 -> Price=Balance, "Would you really like to deposit %P gold in to your guild bank account?", Topic=72
"guild","deposit",$1,0<$1,GuildLevel<=0 -> "You are not a member of a guild."
"guild","deposit",$1,0<$1,Balance>=$1 -> Price=$1, "Would you really like to deposit %P gold in to your guild bank account?", Topic=72
"guild","deposit",$1,0<$1,Balance<$1 -> "You do not have enough gold in your bank account."
Topic=71,$1,0<$1,Balance>=$1 -> Price=$1, "Would you really like to deposit %P gold in to your guild bank account?", Topic=72
Topic=71,"0" -> "You are joking, aren't you?"
Topic=71,$1,0<$1,Balance<$1 -> "You do not have enough gold in your bank account."
Topic=71 -> "Please tell me how much gold it is you would like to deposit for your guild.", Topic=71
Topic=72,"yes",Balance>=Price,GuildLevel>0 -> "Alright, we have added the amount of %P gold to your guild balance. Keep in mind that only authorized person can withdraw from the guild account.", GuildDeposit(Price)
Topic=72,"yes" -> "I am inconsolable, but it seems you do not have enough gold in your bank account anymore."
Topic=72 -> "As you wish. Is there something else I can do for you?"
"withdraw" -> "Please tell me how much gold you would like to withdraw.", Topic=83
"withdraw",$1,0<$1,Balance>=$1 -> Price=$1, "Are you sure you wish to withdraw %P gold from your bank account?", Topic=84
"withdraw","0" -> "Sure, you want nothing you get nothing!"
@ -116,6 +138,21 @@ Topic=84,"yes",Balance>=Price -> "Here you are, %P gold. Please let me know if t
Topic=84,"yes" -> "I am inconsolable, but it seems you don't have that many gold in your bank account."
Topic=84 -> "The customer is king! Come back anytime you want to if you wish to withdraw your money."
"guild","withdraw",GuildLevel<=0 -> "I am sorry but it seems you are currently not in any guild."
"guild","withdraw",GuildLevel=1 -> "I am sorry but you are not eligible to withdraw from the guild account."
"guild","withdraw" -> "Please tell me how much gold you would like to withdraw from your guild account.", Topic=73
"guild","withdraw",$1,0<$1,GuildLevel<=0 -> "I am sorry but it seems you are currently not in any guild."
"guild","withdraw",$1,0<$1,GuildLevel=1 -> "I am sorry but you are not eligible to withdraw from the guild account."
"guild","withdraw",$1,0<$1,GuildBalance>=$1 -> Price=$1, "Are you sure you wish to withdraw %P gold from your guild bank account?", Topic=74
"guild","withdraw",$1,0<$1,GuildBalance<$1 -> "There is not enough gold on your guild account."
Topic=73,$1,0<$1,GuildBalance>=$1 -> Price=$1, "Are you sure you wish to withdraw %P gold from your guild bank account?", Topic=74
Topic=73,"0" -> "Sure, you want nothing you get nothing!"
Topic=73,$1,0<$1,GuildBalance<$1 -> "There is not enough gold on your guild account."
Topic=73 -> "Please tell me how much gold you would like to withdraw from your guild account..", Topic=73
Topic=74,"yes",GuildBalance>=Price,GuildLevel>1 -> "Here you are, we withdraw %P gold from your guild account to your personal account. Please let me know if there is something else I can do for you.", GuildWithdraw(Price)
Topic=74,"yes" -> "I am inconsolable, but it seems you don't have that many gold in your guild bank account."
Topic=74 -> "The customer is king! Come back anytime you want to if you wish to withdraw your money."
"transfer" -> "Please tell me the amount of gold you would like to transfer.", Topic=85
"transfer","0","to" -> "Please think about it. Okay?"
"transfer",$1,0<$1,"to",Balance<$1 -> "There is not enough gold on your account."

View File

@ -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);

View File

@ -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

View File

@ -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();

View File

@ -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);