Skip to content

Commit

Permalink
Fix checks on player death, player speed breakpoint and misc enhancem…
Browse files Browse the repository at this point in the history
…ents (#378)

### Added tag in config.lua for:
* Max critical chance of imbuements
* Adventurers blessing level 
* Inventory glow on five bless 

### Fixed:
* Set default maxSpeed for 70000
* Still blessed after dead for work with "no disconnect on death"
* Player targetting after dead for work with "no disconnect on death"
* Adventurer blessing logic for work with "no disconnect on death"
  • Loading branch information
omeranha committed Jun 24, 2022
1 parent 1960d49 commit e5cc80a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
4 changes: 4 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ coinPacketSize = 25
coinImagesURL = "http://127.0.0.1/images/store/"
classicAttackSpeed = false
showScriptsLogInConsole = false
-- configure maximum value of critical imbuement
criticalChance = 10
inventoryGlowOnFiveBless = false
adventurersBlessingLevel = 21

-- Global server Save
-- NOTE: globalServerSaveNotifyDuration in minutes
Expand Down
3 changes: 3 additions & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum booleanConfig_t {
AUTOLOOT,
AUTOBANK,
RATE_USE_STAGES,
INVENTORY_GLOW,

LAST_BOOLEAN_CONFIG
};
Expand Down Expand Up @@ -175,6 +176,8 @@ enum integerConfig_t {
MAX_ALLOWED_ON_A_DUMMY,
FREE_QUEST_STAGE,
DEPOTCHEST,
CRITICALCHANCE,
ADVENTURERSBLESSING_LEVEL,

LAST_INTEGER_CONFIG
};
Expand Down
4 changes: 4 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ bool ConfigManager::load()
integer[MAX_ALLOWED_ON_A_DUMMY] = getGlobalNumber(L, "maxAllowedOnADummy", 1);
integer[FREE_QUEST_STAGE] = getGlobalNumber(L, "freeQuestStage", 1);
integer[DEPOTCHEST] = getGlobalNumber(L, "depotChest", 4);
integer[CRITICALCHANCE] = getGlobalNumber(L, "criticalChance", 10);

boolean[INVENTORY_GLOW] = getGlobalBoolean(L, "inventoryGlowOnFiveBless", false);
integer[ADVENTURERSBLESSING_LEVEL] = getGlobalNumber(L, "adventurersBlessingLevel", 21);

floating[RATE_HEALTH_REGEN] = getGlobalFloat(L, "rateHealthRegen", 1.0);
floating[RATE_HEALTH_REGEN_SPEED] = getGlobalFloat(L, "rateHealthRegenSpeed", 1.0);
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreatur
g_game().internalAddItem(tile, corpse, INDEX_WHEREEVER, FLAG_NOLIMIT);
dropLoot(corpse->getContainer(), lastHitCreature);
corpse->startDecaying();
bool corpses = corpse->isRewardCorpse() && (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE);
bool corpses = corpse->isRewardCorpse() || (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE);
if (mostDamageCreature && mostDamageCreature->getPlayer() && !corpses) {
Player* player = mostDamageCreature->getPlayer();
if (g_configManager().getBoolean(AUTOBANK)) {
Expand Down
46 changes: 21 additions & 25 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,9 +1526,7 @@ void Player::onCreatureAppear(Creature* creature, bool isLogin)
bed->wakeUp(this);
}

if (isLogin) {
SPDLOG_INFO("{} has logged in", name);
}
SPDLOG_INFO("{} has logged in", name);

if (guild) {
guild->addMember(this);
Expand All @@ -1554,6 +1552,14 @@ void Player::onCreatureAppear(Creature* creature, bool isLogin)

g_game().checkPlayersRecord();
IOLoginData::updateOnlineStatus(guid, true);
if (getLevel() < g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL)) {
for (uint8_t i = 2; i <= 6; i++) {
if (!hasBlessing(i)) {
addBlessing(i, 1);
}
}
sendBlessStatus();
}
}
}

Expand Down Expand Up @@ -1629,14 +1635,21 @@ void Player::onRemoveCreature(Creature* creature, bool isLogout)

if (creature == this) {
if (isLogout) {
if (party) {
party->leaveParty(this);
}
if (guild) {
guild->removeMember(this);
}

loginPosition = getPosition();
lastLogout = time(nullptr);
SPDLOG_INFO("{} has logged out", getName());
g_chat().removeUserFromAllChannels(*this);
clearPartyInvitations();
IOLoginData::updateOnlineStatus(guid, false);
}

lastLogout = time(nullptr);

if (eventWalk != 0) {
setFollowCreature(nullptr);
}
Expand All @@ -1647,16 +1660,6 @@ void Player::onRemoveCreature(Creature* creature, bool isLogout)

closeShopWindow();

if (party && isLogout) {
party->leaveParty(this);
}

if (guild && isLogout) {
guild->removeMember(this);
}

IOLoginData::updateOnlineStatus(guid, false);

bool saved = false;
for (uint32_t tries = 0; tries < 3; ++tries) {
if (IOLoginData::savePlayer(this)) {
Expand Down Expand Up @@ -2642,14 +2645,6 @@ void Player::death(Creature* lastHitCreature)
}
}

std::ostringstream lostBlesses;
if (bless.length() == 0) {
lostBlesses << "You lost all your blesses.";
} else {
lostBlesses << "You are still blessed with " << bless;
}
sendTextMessage(MESSAGE_EVENT_ADVANCE, lostBlesses.str());

sendStats();
sendSkills();
sendReLoginWindow(unfairFightReduction);
Expand Down Expand Up @@ -2729,8 +2724,7 @@ bool Player::spawn()

getParent()->postAddNotification(this, nullptr, 0);
g_game().addCreatureCheck(this);

addList();
g_game().addPlayer(this);
return true;
}

Expand All @@ -2743,6 +2737,8 @@ void Player::despawn()
listWalkDir.clear();
stopEventWalk();
onWalkAborted();
g_game().playerSetAttackedCreature(this->getID(), 0);
g_game().playerFollowCreature(this->getID(), 0);

// remove check
Game::removeCreatureCheck(this);
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct OpenContainer {

using MuteCountMap = std::map<uint32_t, uint32_t>;

static constexpr int32_t PLAYER_MAX_SPEED = 4500;
static constexpr int32_t PLAYER_MAX_SPEED = 70000;
static constexpr int32_t PLAYER_MIN_SPEED = 10;

class Player final : public Creature, public Cylinder
Expand Down Expand Up @@ -2116,7 +2116,7 @@ class Player final : public Creature, public Cylinder
std::map<uint8_t, uint16_t> maxValuePerSkill = {
{SKILL_LIFE_LEECH_CHANCE, 100},
{SKILL_MANA_LEECH_CHANCE, 100},
{SKILL_CRITICAL_HIT_CHANCE, 10}
{SKILL_CRITICAL_HIT_CHANCE, g_configManager().getNumber(CRITICALCHANCE)}
};

std::map<uint32_t, Reward*> rewardMap;
Expand Down
18 changes: 16 additions & 2 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,19 @@ void ProtocolGame::parsePacket(NetworkMessage& msg)
}

sendAddCreature(player, player->getPosition(), 0, false);

std::string bless = player->getBlessingsName();
std::ostringstream lostBlesses;
(bless.length() == 0) ? lostBlesses << "You lost all your blessings." : lostBlesses << "You are still blessed with " << bless;
player->sendTextMessage(MESSAGE_EVENT_ADVANCE, lostBlesses.str());
if (player->getLevel() < g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL)) {
for (uint8_t i = 2; i <= 6; i++) {
if (!player->hasBlessing(i)) {
player->addBlessing(i, 1);
}
}
sendBlessStatus();
}
return;
}

Expand All @@ -632,7 +645,7 @@ void ProtocolGame::parsePacket(NetworkMessage& msg)
g_dispatcher().addTask(createTask(std::bind(&Modules::executeOnRecvbyte, &g_modules(), player->getID(), msg, recvbyte)));
}

g_dispatcher().addTask(createTask(std::bind(&ProtocolGame::parsePacketFromDispatcher, getThis(), msg, recvbyte)));
g_dispatcher().addTask(createTask(std::bind(&ProtocolGame::parsePacketFromDispatcher, getThis(), msg, recvbyte)));
}

void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyte)
Expand Down Expand Up @@ -3563,7 +3576,8 @@ void ProtocolGame::sendBlessStatus()

msg.addByte(0x9C);

msg.add<uint16_t>((blessCount >= 5) ? (flag | 1) : flag); //Show up the glowing effect in items if have all blesses
bool glow = g_configManager().getBoolean(INVENTORY_GLOW) || player->getLevel() < g_configManager().getNumber(ADVENTURERSBLESSING_LEVEL);
msg.add<uint16_t>(glow ? 1 : 0); //Show up the glowing effect in items if have all blesses or adventurer's blessing
msg.addByte((blessCount >= 7) ? 3 : ((blessCount >= 5) ? 2 : 1)); // 1 = Disabled | 2 = normal | 3 = green
// msg.add<uint16_t>(0);

Expand Down

0 comments on commit e5cc80a

Please sign in to comment.