Skip to content

Commit

Permalink
Merge branch 'main' into dudantas/fix-crash-related-to-check-creatures
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas authored Nov 27, 2023
2 parents 551e66f + 33d62b4 commit 9fae53c
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 51 deletions.
25 changes: 9 additions & 16 deletions data-otservbr-global/monster/quests/annihilator/angry_demon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local mType = Game.createMonsterType("Angry Demon")
local monster = {}

monster.description = "an angry demon"
monster.experience = 30000
monster.experience = 6000
monster.outfit = {
lookType = 35,
lookHead = 0,
Expand All @@ -13,8 +13,8 @@ monster.outfit = {
lookMount = 0,
}

monster.health = 60000
monster.maxHealth = 60000
monster.health = 8200
monster.maxHealth = 8200
monster.race = "fire"
monster.corpse = 5995
monster.speed = 128
Expand Down Expand Up @@ -57,7 +57,7 @@ monster.light = {
monster.summon = {
maxSummons = 1,
summons = {
{ name = "massive fire elemental", chance = 25, interval = 2000, count = 1 },
{ name = "fire elemental", chance = 10, interval = 2000, count = 1 },
},
}

Expand Down Expand Up @@ -108,19 +108,12 @@ monster.loot = {
}

monster.attacks = {
-- {name ="melee", interval = 2000, chance = 100, minDamage = 0, maxDamage = -520},
-- {name ="combat", interval = 2000, chance = 10, type = COMBAT_MANADRAIN, minDamage = 0, maxDamage = -120, range = 7, target = false},
-- {name ="combat", interval = 2000, chance = 20, type = COMBAT_FIREDAMAGE, minDamage = -150, maxDamage = -250, range = 7, radius = 7, shootEffect = CONST_ANI_FIRE, effect = CONST_ME_FIREAREA, target = true},
-- {name ="firefield", interval = 2000, chance = 10, range = 7, radius = 1, shootEffect = CONST_ANI_FIRE, target = true},
-- {name ="combat", interval = 2000, chance = 10, type = COMBAT_LIFEDRAIN, minDamage = -300, maxDamage = -490, length = 8, spread = 3, effect = CONST_ME_PURPLEENERGY, target = false},
-- {name ="combat", interval = 2000, chance = 10, type = COMBAT_ENERGYDAMAGE, minDamage = -210, maxDamage = -300, range = 1, shootEffect = CONST_ANI_ENERGY, target = false},
-- {name ="speed", interval = 2000, chance = 15, speedChange = -700, radius = 1, effect = CONST_ME_MAGIC_RED, target = true, duration = 30000}
{ name = "melee", interval = 2000, chance = 500, minDamage = 0, maxDamage = -1940 },
{ name = "combat", interval = 2000, chance = 10, type = COMBAT_MANADRAIN, minDamage = 0, maxDamage = -150, range = 7, target = false },
{ name = "combat", interval = 2000, chance = 20, type = COMBAT_FIREDAMAGE, minDamage = -650, maxDamage = -900, range = 7, radius = 7, shootEffect = CONST_ANI_FIRE, effect = CONST_ME_FIREAREA, target = true },
{ name = "melee", interval = 2000, chance = 100, minDamage = 0, maxDamage = -520 },
{ name = "combat", interval = 2000, chance = 10, type = COMBAT_MANADRAIN, minDamage = 0, maxDamage = -120, range = 7, target = false },
{ name = "combat", interval = 2000, chance = 20, type = COMBAT_FIREDAMAGE, minDamage = -150, maxDamage = -250, range = 7, radius = 7, shootEffect = CONST_ANI_FIRE, effect = CONST_ME_FIREAREA, target = true },
{ name = "firefield", interval = 2000, chance = 10, range = 7, radius = 1, shootEffect = CONST_ANI_FIRE, target = true },
{ name = "combat", interval = 2000, chance = 20, type = COMBAT_LIFEDRAIN, minDamage = -300, maxDamage = -800, length = 8, spread = 0, effect = CONST_ME_PURPLEENERGY, target = false },
{ name = "combat", interval = 2000, chance = 10, type = COMBAT_ENERGYDAMAGE, minDamage = -1050, maxDamage = -1500, range = 1, shootEffect = CONST_ANI_ENERGY, target = true },
{ name = "combat", interval = 2000, chance = 10, type = COMBAT_LIFEDRAIN, minDamage = -300, maxDamage = -490, length = 8, spread = 3, effect = CONST_ME_PURPLEENERGY, target = false },
{ name = "combat", interval = 2000, chance = 10, type = COMBAT_ENERGYDAMAGE, minDamage = -210, maxDamage = -300, range = 1, shootEffect = CONST_ANI_ENERGY, target = false },
{ name = "speed", interval = 2000, chance = 15, speedChange = -700, radius = 1, effect = CONST_ME_MAGIC_RED, target = true, duration = 30000 },
}

Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/monster/reptiles/boar_man.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monster.outfit = {

monster.raceId = 2339
monster.Bestiary = {
class = "Hybrids",
class = "Humanoid",
race = BESTY_RACE_HUMANOID,
toKill = 2500,
FirstUnlock = 100,
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/monster/reptiles/crape_man.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monster.outfit = {

monster.raceId = 2337
monster.Bestiary = {
class = "Hybrids",
class = "Humanoid",
race = BESTY_RACE_HUMANOID,
toKill = 2500,
FirstUnlock = 100,
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/monster/reptiles/liodile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monster.outfit = {

monster.raceId = 2338
monster.Bestiary = {
class = "Hybrids",
class = "Humanoid",
race = BESTY_RACE_HUMANOID,
toKill = 2500,
FirstUnlock = 100,
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/monster/reptiles/rhindeer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monster.outfit = {

monster.raceId = 2342
monster.Bestiary = {
class = "Hybrids",
class = "Humanoid",
race = BESTY_RACE_HUMANOID,
toKill = 2500,
FirstUnlock = 100,
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/actions/other/cask_kegs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey)
return false
end

local charges = item:getCharges()
local charges = target:getCharges()
local itemCount = item:getCount()
local recharged = itemCount

Expand Down
7 changes: 7 additions & 0 deletions data-otservbr-global/scripts/spells/house/kick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ function spell.onCastSpell(player, variant)
local targetPlayer = Player(variant:getString()) or player
local guest = targetPlayer:getTile():getHouse()
local owner = player:getTile():getHouse()
-- Owner kick yourself from house
if targetPlayer == player then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:teleportTo(owner:getExitPosition())
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
return true
end
if not owner or not guest or not guest:kickPlayer(player, targetPlayer) then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
Expand Down
4 changes: 2 additions & 2 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ if not _G.NextUseXpStamina then
_G.NextUseXpStamina = {}
end

if not _G._G.NextUseConcoctionTime then
_G._G.NextUseConcoctionTime = {}
if not _G.NextUseConcoctionTime then
_G.NextUseConcoctionTime = {}
end

-- Delay potion
Expand Down
48 changes: 36 additions & 12 deletions data/scripts/talkactions/gm/position.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
local position = TalkAction("/pos", "!pos")

local function extractCoordinates(input)
local patterns = {
-- table format
"{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}",
-- Position format
"Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)",
-- x, y, z format
"(%d+)%s*,%s*(%d+)%s*,%s*(%d+)",
}

for _, pattern in ipairs(patterns) do
local x, y, z = string.match(input, pattern)
if x and y and z then
return tonumber(x), tonumber(y), tonumber(z)
end
end
end

function position.onSay(player, words, param)
-- create log
logCommand(player, words, param)

local param = string.gsub(param, "%s+", "")
local tile = load("return " .. param)()
local split = param:split(",")
if type(tile) == "table" and tile.x and tile.y and tile.z then
player:teleportTo(Position(tile.x, tile.y, tile.z))
elseif split and param ~= "" then
player:teleportTo(Position(split[1], split[2], split[3]))
elseif param == "" then
local playerPosition = player:getPosition()
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your current position is: \z
" .. playerPosition.x .. ", " .. playerPosition.y .. ", " .. playerPosition.z .. ".")
if param == "" then
local pos = player:getPosition()
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your current position is: " .. pos.x .. ", " .. pos.y .. ", " .. pos.z .. ".")
return
end

local x, y, z = extractCoordinates(param)
if x and y and z then
local teleportPosition = Position(x, y, z)
local tile = Tile(teleportPosition)
if not tile then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Invalid tile or position. Send a valid position.")
return
end

player:teleportTo(teleportPosition)
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Invalid position format. Use one of the following formats: \n/pos {x = ..., y = ..., z = ...}\n/pos Position(..., ..., ...)\n/pos x, y, z.")
end
return true
end

position:separator(" ")
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/talkactions/player/buy_house.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local buyHouse = TalkAction("!buyhouse")

function buyHouse.onSay(player, words, param)
local housePrice = configManager.getNumber(configKeys.HOUSE_PRICE)
local housePrice = configManager.getNumber(configKeys.HOUSE_PRICE_PER_SQM)
if housePrice == -1 then
return true
end
Expand Down
9 changes: 4 additions & 5 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2024,13 +2024,12 @@ void Combat::applyExtensions(std::shared_ptr<Creature> caster, std::shared_ptr<C

// Critical hit
uint16_t chance = 0;
int32_t multiplier = 50;
int32_t bonus = 50;
auto player = caster->getPlayer();
auto monster = caster->getMonster();
if (player) {
chance = player->getSkillLevel(SKILL_CRITICAL_HIT_CHANCE);
multiplier = player->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE);

bonus = player->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE);
if (target) {
uint16_t playerCharmRaceid = player->parseRacebyCharm(CHARM_LOW, false, 0);
if (playerCharmRaceid != 0) {
Expand All @@ -2048,8 +2047,8 @@ void Combat::applyExtensions(std::shared_ptr<Creature> caster, std::shared_ptr<C
chance = monster->critChance();
}

multiplier += damage.criticalDamage;
multiplier = 1 + multiplier / 100;
bonus += damage.criticalDamage;
double multiplier = 1.0 + static_cast<double>(bonus) / 100;
chance += (uint16_t)damage.criticalChance;

if (chance != 0 && uniform_random(1, 100) <= chance) {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ bool Creature::setFollowCreature(std::shared_ptr<Creature> creature) {
onWalkAborted();
}

hasFollowPath = false;
hasFollowPath = true;
forceUpdateFollowPath = false;
m_followCreature = creature;
isUpdatingPath = true;
Expand Down
20 changes: 11 additions & 9 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6625,10 +6625,8 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt
}
}

std::string attackMsg = fmt::format("{} attack", damage.critical ? "critical " : " ");
std::stringstream ss;
ss << (damage.critical ? "critical " : " ") << "attack";
std::string attackMsg = ss.str();
ss.str({});

if (target->hasCondition(CONDITION_MANASHIELD) && damage.primary.type != COMBAT_UNDEFINEDDAMAGE) {
int32_t manaDamage = std::min<int32_t>(target->getMana(), healthChange);
Expand Down Expand Up @@ -6915,17 +6913,19 @@ void Game::buildMessageAsSpectator(
) const {
if (spectatorMessage.empty()) {
ss.str({});
auto attackMsg = damage.critical ? "critical " : "";
auto article = damage.critical ? "a" : "an";
ss << ucfirst(target->getNameDescription()) << " loses " << damageString;
if (attacker) {
ss << " due to ";
if (attacker == target) {
if (targetPlayer) {
ss << targetPlayer->getPossessivePronoun() << " own attack";
ss << targetPlayer->getPossessivePronoun() << " own " << attackMsg << "attack";
} else {
ss << "its own attack";
ss << "its own " << attackMsg << "attack";
}
} else {
ss << "an attack by " << attacker->getNameDescription();
ss << article << " " << attackMsg << "attack by " << attacker->getNameDescription();
}
}
ss << '.';
Expand All @@ -6945,13 +6945,15 @@ void Game::buildMessageAsTarget(
const std::string &damageString
) const {
ss.str({});
auto attackMsg = damage.critical ? "critical " : "";
auto article = damage.critical ? "a" : "an";
ss << "You lose " << damageString;
if (!attacker) {
ss << '.';
} else if (targetPlayer == attackerPlayer) {
ss << " due to your own attack.";
ss << " due to your own " << attackMsg << "attack.";
} else {
ss << " due to an attack by " << attacker->getNameDescription() << '.';
ss << " due to " << article << " " << attackMsg << "attack by " << attacker->getNameDescription() << '.';
}
if (damage.extension) {
ss << " " << damage.exString;
Expand All @@ -6965,7 +6967,7 @@ void Game::buildMessageAsAttacker(
std::stringstream &ss, const std::string &damageString
) const {
ss.str({});
ss << ucfirst(target->getNameDescription()) << " loses " << damageString << " due to your attack.";
ss << ucfirst(target->getNameDescription()) << " loses " << damageString << " due to your " << (damage.critical ? "critical " : " ") << "attack.";
if (damage.extension) {
ss << " " << damage.exString;
}
Expand Down

0 comments on commit 9fae53c

Please sign in to comment.