Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Jan 25, 2024
2 parents cbf4ef3 + 28dbaef commit 2423d83
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 58 deletions.
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ coinPacketSize = 25
coinImagesURL = "http://127.0.0.1/images/store/"
classicAttackSpeed = false
showScriptsLogInConsole = false
-- time to suppress negative conditions after being affected by them (ms)
minDelayBetweenConditions = 0
-- configure maximum value of critical imbuement
criticalChance = 10
inventoryGlowOnFiveBless = false
Expand Down
54 changes: 27 additions & 27 deletions data-otservbr-global/scripts/weapons/unscripted_weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4605,14 +4605,14 @@ local weapons = {
itemId = 3348,
type = WEAPON_CLUB,
},
-- {
-- -- hunting spear
-- itemId = 3347,
-- type = WEAPON_MISSILE,
-- level = 20,
-- unproperly = true,
-- breakchance = 6
-- },
{
-- hunting spear
itemId = 3347,
type = WEAPON_MISSILE,
level = 20,
unproperly = true,
breakchance = 6,
},
{
-- ripper lance
itemId = 3346,
Expand Down Expand Up @@ -4650,17 +4650,17 @@ local weapons = {
unproperly = true,
action = "removecount",
},
-- {
-- -- -- arrow
-- -- itemId = 3447,
-- -- type = WEAPON_AMMO,
-- -- -- action = "removecount"
-- },
{
-- arrow
itemId = 3447,
type = WEAPON_AMMO,
action = "removecount",
},
{
-- bolt
itemId = 3446,
type = WEAPON_AMMO,
-- action = "removecount"
action = "removecount",
},
{
-- bow
Expand Down Expand Up @@ -5032,12 +5032,12 @@ local weapons = {
level = 80,
unproperly = true,
},
-- {
-- -- throwing star
-- itemId = 3287,
-- type = WEAPON_MISSILE,
-- breakchance = 10
-- },
{
-- throwing star
itemId = 3287,
type = WEAPON_MISSILE,
breakchance = 10,
},
{
-- mace
itemId = 3286,
Expand Down Expand Up @@ -5104,12 +5104,12 @@ local weapons = {
{ "Elite Knight" },
},
},
-- {
-- -- spear
-- itemId = 3277,
-- type = WEAPON_MISSILE,
-- -- breakchance = 3
-- },
{
-- spear
itemId = 3277,
type = WEAPON_MISSILE,
breakchance = 3,
},
{
-- hatchet
itemId = 3276,
Expand Down
1 change: 1 addition & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ enum ConfigKey_t : uint16_t {
METRICS_ENABLE_PROMETHEUS,
METRICS_OSTREAM_INTERVAL,
METRICS_PROMETHEUS_ADDRESS,
MIN_DELAY_BETWEEN_CONDITIONS,
MIN_ELEMENTAL_RESISTANCE,
MOMENTUM_CHANCE_FORMULA_A,
MOMENTUM_CHANCE_FORMULA_B,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, CLEAN_PROTECTION_ZONES, "cleanProtectionZones", false);
loadBoolConfig(L, GLOBAL_SERVER_SAVE_SHUTDOWN, "globalServerSaveShutdown", true);
loadBoolConfig(L, PUSH_WHEN_ATTACKING, "pushWhenAttacking", false);
loadIntConfig(L, MIN_DELAY_BETWEEN_CONDITIONS, "minDelayBetweenConditions", 0);

loadBoolConfig(L, WEATHER_RAIN, "weatherRain", false);
loadBoolConfig(L, WEATHER_THUNDER, "thunderEffect", false);
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ void Combat::CombatConditionFunc(std::shared_ptr<Creature> caster, std::shared_p

// TODO: infight condition until all aggressive conditions has ended
if (target) {
target->addCombatCondition(conditionCopy);
target->addCombatCondition(conditionCopy, caster && caster->getPlayer() != nullptr);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,9 @@ bool ConditionDamage::getNextDamage(int32_t &damage) {
}

bool ConditionDamage::doDamage(std::shared_ptr<Creature> creature, int32_t healthChange) {
if (creature->isSuppress(getType())) {
auto attacker = g_game().getPlayerByGUID(owner) ? g_game().getPlayerByGUID(owner)->getCreature() : g_game().getCreatureByID(owner);
bool isPlayer = attacker && attacker->getPlayer();
if (creature->isSuppress(getType(), isPlayer)) {
return true;
}

Expand All @@ -1653,7 +1655,6 @@ bool ConditionDamage::doDamage(std::shared_ptr<Creature> creature, int32_t healt
damage.primary.value = healthChange;
damage.primary.type = Combat::ConditionToDamageType(conditionType);

std::shared_ptr<Creature> attacker = g_game().getCreatureByID(owner);
if (field && creature->getPlayer() && attacker && attacker->getPlayer()) {
damage.primary.value = static_cast<int32_t>(std::round(damage.primary.value / 2.));
}
Expand Down
12 changes: 7 additions & 5 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,12 +1334,14 @@ bool Creature::setMaster(std::shared_ptr<Creature> newMaster, bool reloadCreatur
return true;
}

bool Creature::addCondition(std::shared_ptr<Condition> condition) {
bool Creature::addCondition(std::shared_ptr<Condition> condition, bool attackerPlayer /* = false*/) {
metrics::method_latency measure(__METHOD_NAME__);
if (condition == nullptr) {
return false;
}

if (isSuppress(condition->getType(), attackerPlayer)) {
return false;
}
std::shared_ptr<Condition> prevCond = getCondition(condition->getType(), condition->getId(), condition->getSubId());
if (prevCond) {
prevCond->addCondition(getCreature(), condition);
Expand All @@ -1355,11 +1357,11 @@ bool Creature::addCondition(std::shared_ptr<Condition> condition) {
return false;
}

bool Creature::addCombatCondition(std::shared_ptr<Condition> condition) {
bool Creature::addCombatCondition(std::shared_ptr<Condition> condition, bool attackerPlayer /* = false*/) {
// Caution: condition variable could be deleted after the call to addCondition
ConditionType_t type = condition->getType();

if (!addCondition(condition)) {
if (!addCondition(condition, attackerPlayer)) {
return false;
}

Expand Down Expand Up @@ -1490,7 +1492,7 @@ void Creature::executeConditions(uint32_t interval) {

bool Creature::hasCondition(ConditionType_t type, uint32_t subId /* = 0*/) const {
metrics::method_latency measure(__METHOD_NAME__);
if (isSuppress(type)) {
if (isSuppress(type, false)) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ class Creature : virtual public Thing, public SharedObject {
return SPEECHBUBBLE_NONE;
}

bool addCondition(std::shared_ptr<Condition> condition);
bool addCombatCondition(std::shared_ptr<Condition> condition);
bool addCondition(std::shared_ptr<Condition> condition, bool attackerPlayer = false);
bool addCombatCondition(std::shared_ptr<Condition> condition, bool attackerPlayer = false);
void removeCondition(ConditionType_t conditionType, ConditionId_t conditionId, bool force = false);
void removeCondition(ConditionType_t type);
void removeCondition(std::shared_ptr<Condition> condition);
Expand All @@ -406,7 +406,7 @@ class Creature : virtual public Thing, public SharedObject {
virtual bool isImmune(ConditionType_t type) const {
return false;
}
virtual bool isSuppress(ConditionType_t type) const {
virtual bool isSuppress(ConditionType_t type, bool attackerPlayer) const {
return false;
};

Expand Down
22 changes: 22 additions & 0 deletions src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ enum ConditionType_t : uint8_t {
CONDITION_COUNT = 39
};

// constexpr definiting suppressible conditions
constexpr bool IsConditionSuppressible(ConditionType_t condition) {
constexpr ConditionType_t suppressibleConditions[] = {
CONDITION_POISON,
CONDITION_FIRE,
CONDITION_ENERGY,
CONDITION_BLEEDING,
CONDITION_PARALYZE,
CONDITION_DROWN,
CONDITION_FREEZING,
CONDITION_CURSED,
};

for (const auto &suppressibleCondition : suppressibleConditions) {
if (condition == suppressibleCondition) {
return true;
}
}

return false;
}

enum ConditionParam_t {
CONDITION_PARAM_OWNER = 1,
CONDITION_PARAM_TICKS = 2,
Expand Down
40 changes: 39 additions & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,11 @@ void Monster::updateIdleStatus() {
bool idle = false;
if (conditions.empty()) {
if (!isSummon() && targetList.empty()) {
idle = true;
if (isInSpawnLocation()) {
idle = true;
} else {
isWalkingBack = true;
}
} else if (const auto &master = getMaster()) {
if ((!isSummon() && totalPlayersOnScreen == 0 || isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0) && getFaction() != FACTION_DEFAULT) {
idle = true;
Expand All @@ -696,6 +700,13 @@ void Monster::updateIdleStatus() {
setIdle(idle);
}

bool Monster::isInSpawnLocation() const {
if (!spawnMonster) {
return true;
}
return position == masterPos || masterPos == Position();
}

void Monster::onAddCondition(ConditionType_t type) {
onConditionStatusChange(type);
}
Expand Down Expand Up @@ -1159,6 +1170,8 @@ bool Monster::getNextStep(Direction &nextDirection, uint32_t &flags) {

if (getFollowCreature() && hasFollowPath) {
doFollowCreature(flags, nextDirection, result);
} else if (isWalkingBack) {
doWalkBack(flags, nextDirection, result);
} else {
doRandomStep(nextDirection, result);
}
Expand Down Expand Up @@ -1187,6 +1200,31 @@ void Monster::doRandomStep(Direction &nextDirection, bool &result) {
}
}

void Monster::doWalkBack(uint32_t &flags, Direction &nextDirection, bool &result) {
result = Creature::getNextStep(nextDirection, flags);
if (result) {
flags |= FLAG_PATHFINDING;
} else {
if (ignoreFieldDamage) {
ignoreFieldDamage = false;
updateMapCache();
}

int32_t distance = std::max<int32_t>(Position::getDistanceX(position, masterPos), Position::getDistanceY(position, masterPos));
if (distance == 0) {
isWalkingBack = false;
return;
}

stdext::arraylist<Direction> listDir(128);
if (!getPathTo(masterPos, listDir, 0, std::max<int32_t>(0, distance - 5), true, true, distance)) {
isWalkingBack = false;
return;
}
startAutoWalk(listDir.data());
}
}

void Monster::doFollowCreature(uint32_t &flags, Direction &nextDirection, bool &result) {
randomStepping = false;
result = Creature::getNextStep(nextDirection, flags);
Expand Down
3 changes: 3 additions & 0 deletions src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class Monster final : public Creature {

Position masterPos;

bool isWalkingBack = false;
bool isIdle = true;
bool extraMeleeAttack = false;
bool randomStepping = false;
Expand Down Expand Up @@ -427,6 +428,7 @@ class Monster final : public Creature {
bool canUseSpell(const Position &pos, const Position &targetPos, const spellBlock_t &sb, uint32_t interval, bool &inRange, bool &resetTicks);
bool getRandomStep(const Position &creaturePos, Direction &direction);
bool getDanceStep(const Position &creaturePos, Direction &direction, bool keepAttack = true, bool keepDistance = true);
bool isInSpawnLocation() const;
bool isInSpawnRange(const Position &pos) const;
bool canWalkTo(Position pos, Direction direction);

Expand Down Expand Up @@ -460,6 +462,7 @@ class Monster final : public Creature {

static std::vector<std::pair<int8_t, int8_t>> getPushItemLocationOptions(const Direction &direction);

void doWalkBack(uint32_t &flags, Direction &nextDirection, bool &result);
void doFollowCreature(uint32_t &flags, Direction &nextDirection, bool &result);
void doRandomStep(Direction &nextDirection, bool &result);

Expand Down
12 changes: 10 additions & 2 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ std::shared_ptr<Item> Player::getInventoryItem(Slots_t slot) const {
return inventory[slot];
}

bool Player::isSuppress(ConditionType_t conditionType) const {
bool Player::isSuppress(ConditionType_t conditionType, bool attackerPlayer) const {
auto minDelay = g_configManager().getNumber(MIN_DELAY_BETWEEN_CONDITIONS, __FUNCTION__);
if (IsConditionSuppressible(conditionType) && checkLastConditionTimeWithin(conditionType, minDelay)) {
return true;
}

return m_conditionSuppressions[static_cast<size_t>(conditionType)];
}

Expand Down Expand Up @@ -450,7 +455,7 @@ float Player::getDefenseFactor() const {
uint32_t Player::getClientIcons() {
uint32_t icons = 0;
for (const auto &condition : conditions) {
if (!isSuppress(condition->getType())) {
if (!isSuppress(condition->getType(), false)) {
icons |= condition->getIcons();
}
}
Expand Down Expand Up @@ -4481,6 +4486,9 @@ void Player::onAddCondition(ConditionType_t type) {
}

void Player::onAddCombatCondition(ConditionType_t type) {
if (IsConditionSuppressible(type)) {
updateLastConditionTime(type);
}
switch (type) {
case CONDITION_POISON:
sendTextMessage(MESSAGE_FAILURE, "You are poisoned.");
Expand Down
Loading

0 comments on commit 2423d83

Please sign in to comment.