Last active
March 2, 2019 18:49
-
-
Save vankk/ebd1377d52b3b92028ecad632e949d0c to your computer and use it in GitHub Desktop.
Stamina Regeneration PZ 0.4 C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/a/configmanager.cpp b/b/configmanager.cpp | |
index 3578a89..3a6d7dd 100644 | |
--- a/a/configmanager.cpp | |
+++ b/b/configmanager.cpp | |
@@ -317,6 +317,9 @@ bool ConfigManager::load() | |
m_confNumber[EXHAUST_ONBUY] = getGlobalNumber("onBuy", 500); | |
m_confNumber[EXHAUST_ONSELL] = getGlobalNumber("onSell", 500); | |
m_confNumber[EXHAUST_CHANGEOUFIT] = getGlobalNumber("changeOutfit", 500); | |
+ m_confBool[STAMINA_REGEN_PZ] = getGlobalBool("staminaRegenPz", true); | |
+ m_confNumber[STAMINA_SECONDS_TO_REGEN] = getGlobalNumber("staminaSecondsToRegen", 30); | |
+ m_confNumber[STAMINA_REGENERATION_PZ] = getGlobalNumber("gainStaminaRegerationPz", 1); | |
m_loaded = true; | |
return true; | |
diff --git a/a/configmanager.h b/b/configmanager.h | |
index cb4d494..27d3b9e 100644 | |
--- a/a/configmanager.h | |
+++ b/b/configmanager.h | |
@@ -175,6 +175,8 @@ class ConfigManager | |
EXHAUST_ONBUY, | |
EXHAUST_ONSELL, | |
EXHAUST_CHANGEOUFIT, | |
+ STAMINA_SECONDS_TO_REGEN, | |
+ STAMINA_REGENERATION_PZ, | |
LAST_NUMBER_CONFIG /* this must be the last one */ | |
}; | |
@@ -287,6 +289,7 @@ class ConfigManager | |
ENABLE_CAST, | |
SKIP_ITEMS_VERSION, | |
BIND_ONLY_GLOBAL_ADDRESS, | |
+ STAMINA_REGEN_PZ, | |
LAST_BOOL_CONFIG /* this must be the last one */ | |
}; | |
diff --git a/a/player.cpp b/b/player.cpp | |
index 72f4585..c1ffeb3 100644 | |
--- a/a/player.cpp | |
+++ b/b/player.cpp | |
@@ -93,6 +93,8 @@ Player::Player(const std::string& _name, ProtocolGame* p): | |
tradePartner = NULL; | |
walkTask = NULL; | |
weapon = NULL; | |
+ timeInPz = 0; | |
+ regenerationActivated = false; | |
setVocation(0); | |
setParty(NULL); | |
@@ -1793,6 +1795,37 @@ void Player::onThink(uint32_t interval) | |
g_game.removeCreature(this, true); | |
} | |
+ bool regenerationInPz = g_config.getBool(ConfigManager::STAMINA_REGEN_PZ); | |
+ if (regenerationInPz) { | |
+ if (getTile()->hasFlag(TILESTATE_PROTECTIONZONE)) { | |
+ if (!regenerationActivated) { | |
+ regenerationActivated = true; | |
+ timeInPz = 0; | |
+ } | |
+ | |
+ if (timeInPz == 0) { | |
+ uint16_t secondsToRegeneration = g_config.getNumber(ConfigManager::STAMINA_SECONDS_TO_REGEN); | |
+ uint16_t staminaRegeneration = g_config.getNumber(ConfigManager::STAMINA_REGENERATION_PZ); | |
+ timeInPz = OTSYS_TIME() + secondsToRegeneration; | |
+ std::stringstream ss; | |
+ ss << "[Recuperação de Stamina] - Sua stamina começou a se recuperar, ela se regenera " << staminaRegeneration << " a cada " << secondsToRegeneration << " segundo" << ((secondsToRegeneration > 1) ? "s" : "") << "."; | |
+ this->sendTextMessage(MSG_EVENT_ORANGE, ss.str()); | |
+ } | |
+ | |
+ } else { | |
+ if (regenerationActivated) { | |
+ regenerationActivated = false; | |
+ timeInPz = 0; | |
+ } | |
+ } | |
+ | |
+ if (regenerationActivated && timeInPz >= timeNow) { | |
+ uint16_t staminaRegeneration = g_config.getNumber(ConfigManager::STAMINA_REGENERATION_PZ); | |
+ uint32_t getStamina = this->getStaminaMinutes(); | |
+ if (getStamina < STAMINA_MAX && getStamina + staminaRegeneration < STAMINA_MAX) { | |
+ this->setStaminaMinutes(getStamina + staminaRegeneration); | |
+ } | |
+ } | |
+ } | |
+ | |
messageTicks += interval; | |
if(messageTicks >= 1500) | |
{ | |
diff --git a/a/player.h b/b/player.h | |
index 8e7c78a..1723ef5 100644 | |
--- a/a/player.h | |
+++ b/b/player.h | |
@@ -1199,6 +1199,8 @@ class Player : public Creature, public Cylinder | |
uint64_t experience; | |
uint64_t manaSpent; | |
uint64_t lastAttack; | |
+ uint64_t timeInPz; | |
+ bool regenerationActivated; | |
double inventoryWeight; | |
double capacity; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (regenerationActivated && timeInPz >= timeNow) {
^
cc1plus: all warnings being treated as errors