Skip to content

Commit

Permalink
Merge branch 'main' into feature/tournament-coins-custom
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Dec 8, 2023
2 parents 916c186 + 3838427 commit cda782b
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 91 deletions.
22 changes: 11 additions & 11 deletions data-otservbr-global/monster/quests/forgotten_knowledge/icicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ monster.defenses = {
defense = 199,
armor = 199,
mitigation = 0.50,
{ name = "icicle heal", interval = 2000, chance = 25, target = false },
{ name = "icicle heal", interval = 2000, chance = 60, target = false },
}

monster.elements = {
{ type = COMBAT_PHYSICALDAMAGE, percent = 0 },
{ type = COMBAT_ENERGYDAMAGE, percent = 0 },
{ type = COMBAT_EARTHDAMAGE, percent = 0 },
{ type = COMBAT_FIREDAMAGE, percent = 0 },
{ type = COMBAT_LIFEDRAIN, percent = 0 },
{ type = COMBAT_MANADRAIN, percent = 0 },
{ type = COMBAT_DROWNDAMAGE, percent = 0 },
{ type = COMBAT_ICEDAMAGE, percent = 0 },
{ type = COMBAT_HOLYDAMAGE, percent = 0 },
{ type = COMBAT_DEATHDAMAGE, percent = 0 },
{ type = COMBAT_PHYSICALDAMAGE, percent = 100 },
{ type = COMBAT_ENERGYDAMAGE, percent = 100 },
{ type = COMBAT_EARTHDAMAGE, percent = 100 },
{ type = COMBAT_FIREDAMAGE, percent = 100 },
{ type = COMBAT_LIFEDRAIN, percent = 100 },
{ type = COMBAT_MANADRAIN, percent = 100 },
{ type = COMBAT_DROWNDAMAGE, percent = 100 },
{ type = COMBAT_ICEDAMAGE, percent = 100 },
{ type = COMBAT_HOLYDAMAGE, percent = 100 },
{ type = COMBAT_DEATHDAMAGE, percent = 100 },
}

monster.immunities = {
Expand Down
2 changes: 2 additions & 0 deletions data-otservbr-global/scripts/actions/door/custom_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ function customDoor.onUse(player, item, fromPosition, target, toPosition, isHotk
for index, value in ipairs(CustomDoorTable) do
if value.closedDoor == item.itemid then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
return true
end
end
for index, value in ipairs(CustomDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
return true
end
end
Expand Down
6 changes: 6 additions & 0 deletions data-otservbr-global/scripts/actions/door/key_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function keyDoor.onUse(player, item, fromPosition, target, toPosition, isHotkey)
for index, value in ipairs(KeyDoorTable) do
if value.closedDoor == item.itemid then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
return true
end
end
Expand All @@ -46,6 +47,7 @@ function keyDoor.onUse(player, item, fromPosition, target, toPosition, isHotkey)
return false
end
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
return true
end
end
Expand All @@ -60,8 +62,12 @@ function keyDoor.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.actionid == target.actionid then
if value.lockedDoor == target.itemid then
target:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
return true
elseif table.contains({ value.openDoor, value.closedDoor }, target.itemid) then
if value.openDoor == item.itemid then
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
end
target:transform(value.lockedDoor)
return true
end
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/scripts/actions/door/level_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function levelDoor.onUse(player, item, fromPosition, target, toPosition, isHotke
if value.closedDoor == item.itemid then
if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
player:teleportTo(toPosition, true)
return true
else
Expand Down
1 change: 1 addition & 0 deletions data-otservbr-global/scripts/actions/door/quest_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function questDoor.onUse(player, item, fromPosition, target, toPosition, isHotke
if value.closedDoor == item.itemid then
if item.actionid > 0 and player:getStorageValue(item.actionid) ~= -1 then
item:transform(value.openDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_OPEN_DOOR)
player:teleportTo(toPosition, true)
return true
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ function closingDoor.onStepOut(creature, item, position, fromPosition)
for index, value in ipairs(LevelDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
end
end
for index, value in ipairs(QuestDoorTable) do
if value.openDoor == item.itemid then
item:transform(value.closedDoor)
item:getPosition():sendSingleSoundEffect(SOUND_EFFECT_TYPE_ACTION_CLOSE_DOOR)
end
end
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local encounter = Encounter("Magma Bubble", {
function encounter:onReset(position)
encounter:removeMonsters()
bossZone:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("The Magma Bubble has been defeated. You have %i seconds to leave the room.", config.timeToLeftAfterKill))
addEvent(function(zn)
self:addEvent(function(zn)
zn:refresh()
zn:removePlayers()
end, config.timeToLeftAfterKill * 1000, bossZone)
Expand Down
21 changes: 11 additions & 10 deletions data-otservbr-global/scripts/spells/monster/icicle_heal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

function onTargetCreature(creature, target)
local min = 400
local max = 600

local master = target:getMaster()
if target:isPlayer() and not master or master and master:isPlayer() then
return true
local spectators, spectator = Game.getSpectators(creature:getPosition(), false, false, 3, 3, 3, 3)
for i = 1, #spectators do
spectator = spectators[i]
if spectator:isMonster() and spectator:getName():lower() == "dragon egg" then
creature:setTarget("dragon egg")
if target:getName():lower() == "dragon egg" then
target:addHealth(-100)
return true
end
end
end

doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
return true
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
Expand All @@ -29,5 +30,5 @@ spell:words("###436")
spell:isAggressive(true)
spell:blockWalls(true)
spell:needLearn(true)
spell:isSelfTarget(true)
spell:isSelfTarget(false)
spell:register()
8 changes: 5 additions & 3 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24931,13 +24931,13 @@
<item id="11240" article="an" name="open door">
<attribute key="type" value="door"/>
</item>
<item id="11241" article="a" name="closed door">
<item id="11241" article="a" name="closed door" editorsuffix="(it is locked)">
<attribute key="type" value="door"/>
<attribute key="description" value="It is locked."/>
<attribute key="blockProjectile" value="1"/>
</item>
<item id="11242" article="a" name="closed door" editorsuffix="(it is locked)">
<item id="11242" article="a" name="closed door">
<attribute key="type" value="door"/>
<attribute key="description" value="It is locked."/>
<attribute key="blockProjectile" value="1"/>
</item>
<item id="11243" article="an" name="open door">
Expand Down Expand Up @@ -61565,6 +61565,7 @@
<item id="36666" article="a" name="eldritch quiver">
<attribute key="primarytype" value="quivers"/>
<attribute key="slotType" value="right-hand"/>
<attribute key="showattributes" value="1"/>
<attribute key="containersize" value="8"/>
<attribute key="weight" value="2200"/>
<attribute key="perfectshotdamage" value="20"/>
Expand Down Expand Up @@ -65289,6 +65290,7 @@
<item id="39150" article="an" name="alicorn quiver">
<attribute key="primarytype" value="quivers"/>
<attribute key="slotType" value="right-hand"/>
<attribute key="showattributes" value="1"/>
<attribute key="containersize" value="12"/>
<attribute key="weight" value="2000"/>
<attribute key="magiclevelpoints" value="1"/>
Expand Down
11 changes: 5 additions & 6 deletions data/libs/encounters_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,25 @@ function Encounter:resetConfig(config)
self.registered = false
self.global = config.global or false
self.timeToSpawnMonsters = ParseDuration(config.timeToSpawnMonsters or "3s")
self.events = {}
self.events = Set()
end

---@param callable function The callable function for the event
---@param delay number The delay time for the event
function Encounter:addEvent(callable, delay, ...)
local index = #self.events + 1
local event = addEvent(function(callable, ...)
pcall(callable, ...)
table.remove(self.events, index)
self.events:remove(event)
end, ParseDuration(delay), callable, ...)
table.insert(self.events, index, event)
self.events:insert(event)
end

---Cancels all the events associated with the encounter
function Encounter:cancelEvents()
for _, event in ipairs(self.events) do
for event in self.events:iter() do
stopEvent(event)
end
self.events = {}
self.events = Set()
end

---Returns the stage of the encounter by the given stage number
Expand Down
3 changes: 3 additions & 0 deletions data/libs/functions/set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function Set:insert(key)
end

function Set:remove(key)
if not self:contains(key) then
return
end
key = self:__key(key)
self.values[key] = nil
end
Expand Down
13 changes: 9 additions & 4 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,19 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr
void Spell::applyCooldownConditions(std::shared_ptr<Player> player) const {
WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName());
bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast<uint8_t>(spellGrade) > 0;
auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__);
// Safety check to prevent division by zero
auto rateCooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__);
if (std::abs(rateCooldown) < std::numeric_limits<float>::epsilon()) {
rateCooldown = 0.1; // Safe minimum value
}

if (cooldown > 0) {
int32_t spellCooldown = cooldown;
if (isUpgraded) {
spellCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, spellGrade);
}
if (spellCooldown > 0) {
std::shared_ptr<Condition> condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rate_cooldown, 0, false, spellId);
std::shared_ptr<Condition> condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, spellId);
player->addCondition(condition);
}
}
Expand All @@ -627,7 +632,7 @@ void Spell::applyCooldownConditions(std::shared_ptr<Player> player) const {
spellGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::GROUP_COOLDOWN, spellGrade);
}
if (spellGroupCooldown > 0) {
std::shared_ptr<Condition> condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellGroupCooldown / rate_cooldown, 0, false, group);
std::shared_ptr<Condition> condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellGroupCooldown / rateCooldown, 0, false, group);
player->addCondition(condition);
}
}
Expand All @@ -638,7 +643,7 @@ void Spell::applyCooldownConditions(std::shared_ptr<Player> player) const {
spellSecondaryGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN, spellGrade);
}
if (spellSecondaryGroupCooldown > 0) {
std::shared_ptr<Condition> condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rate_cooldown, 0, false, secondaryGroup);
std::shared_ptr<Condition> condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rateCooldown, 0, false, secondaryGroup);
player->addCondition(condition);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3942,9 +3942,7 @@ std::map<uint32_t, uint32_t> &Player::getAllItemTypeCount(std::map<uint32_t, uin

std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t, uint16_t> &countMap) const {
for (const auto item : getAllInventoryItems(false, true)) {
if (!item->hasImbuements()) {
countMap[item->getID()] += item->getItemCount();
}
countMap[item->getID()] += item->getItemCount();
}

return countMap;
Expand Down
Loading

0 comments on commit cda782b

Please sign in to comment.