Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/fix-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Nov 27, 2023
2 parents 1383437 + 33d62b4 commit 1a51f71
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 32 deletions.
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
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
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
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 1a51f71

Please sign in to comment.