Skip to content

Commit

Permalink
fix: add condition for taint icon
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Apr 15, 2024
1 parent 8319f29 commit b1fb702
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 57 deletions.
42 changes: 28 additions & 14 deletions data-otservbr-global/scripts/lib/quests/soul-war.lua
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,11 @@ end

TaintTeleportCooldown = {}

function Player:getTaintNameByNumber(taintNumber)
function Player:getTaintNameByNumber(taintNumber, skipKvCheck)
local haveTaintName = nil
local soulWarQuest = self:soulWarQuestKV()
local taintName = soulWarTaints[taintNumber]
if taintName and soulWarQuest:get(taintName) then
if skipKvCheck or taintName and soulWarQuest:get(taintName) then
haveTaintName = taintName
end

Expand All @@ -983,15 +983,29 @@ end

function Player:addNextTaint()
local soulWarQuest = self:soulWarQuestKV()
for _, taint in ipairs(soulWarTaints) do
if not soulWarQuest:get(taint) then
soulWarQuest:set(taint, true)
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have gained the " .. taint .. ".")
for _, taintName in ipairs(soulWarTaints) do
if not soulWarQuest:get(taintName) then
soulWarQuest:set(taintName, true)
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have gained the " .. taintName .. ".")
self:setTaintIcon()
break
end
end
end

function Player:setTaintIcon(taintId)
self:resetTaintConditions()
local condition = Condition(CONDITION_GOSHNARTAINT, CONDITIONID_DEFAULT, taintId or self:getTaintLevel())
condition:setTicks(14 * 24 * 60 * 60 * 1000)
self:addCondition(condition)
end

function Player:resetTaintConditions()
for i = 1, 5 do
self:removeCondition(CONDITION_GOSHNARTAINT, CONDITIONID_DEFAULT, i)
end
end

function Player:getTaintLevel()
local taintLevel = nil
local soulWarQuest = self:soulWarQuestKV()
Expand All @@ -1004,17 +1018,17 @@ function Player:getTaintLevel()
return taintLevel
end

function Player:resetTaints()
function Player:resetTaints(skipCheckTime)
local soulWarQuest = self:soulWarQuestKV()
local firstTaintTime = soulWarQuest:get("firstTaintTime")
if firstTaintTime and os.time() >= (firstTaintTime + TaintDurationSeconds) then
-- Reset all taints
for _, taint in ipairs(soulWarTaints) do
if soulWarQuest:get(taint) then
soulWarQuest:remove(taint)
if skipCheckTime or firstTaintTime and os.time() >= (firstTaintTime + TaintDurationSeconds) then
-- Reset all taints and remove condition
for _, taintName in ipairs(soulWarTaints) do
if soulWarQuest:get(taintName) then
soulWarQuest:remove(taintName)
end
end

self:resetTaintConditions()
soulWarQuest:remove("firstTaintTime")
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your goshnar's taints have been reset. You didn't finish the quest in 14 days")
end
Expand All @@ -1028,7 +1042,7 @@ function Monster:tryTeleportToPlayer(sayMessage)
for i, spectator in ipairs(spectators) do
if spectator:isPlayer() then
local player = spectator:getPlayer()
if player:getTaintNameByNumber(1) then
if player:getTaintNameByNumber(1, true) then
local distance = self:getPosition():getDistance(player:getPosition())
if distance > maxDistance then
maxDistance = distance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ login:register()
local goshnarsMaliceReflection = CreatureEvent("Goshnar's-Malice")

function goshnarsMaliceReflection.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not attacker then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end

local player = attacker:getPlayer()
if player then
if primaryDamage > 0 and (primaryType == COMBAT_PHYSICALDAMAGE or primaryType == COMBAT_DEATHDAMAGE) then
Expand Down Expand Up @@ -261,11 +265,13 @@ function setTaint.onSay(player, words, param)
end

local taintLevel = split[2]:trim():lower()
local taintName = player:getTaintNameByNumber(tonumber(taintLevel))
local taintName = player:getTaintNameByNumber(tonumber(taintLevel), true)
if taintName ~= nil then
target:resetTaints(true)
target:soulWarQuestKV():set(taintName, true)
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You new taint level is: " .. taintLevel .. ", name: " .. taintName)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Added taint level: " .. taintLevel .. ", name: " .. taintName .. " to player: " .. target:getName())
target:setTaintIcon()
end
end

Expand Down
10 changes: 10 additions & 0 deletions data/scripts/talkactions/god/add_condition.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local talkaction = TalkAction("/testtaintconditions")

function talkaction.onSay(player, words, param)
player:setTaintIcon()
return false
end

talkaction:separator(" ")
talkaction:groupType("god")
talkaction:register()
23 changes: 22 additions & 1 deletion src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ std::shared_ptr<Condition> Condition::createCondition(ConditionId_t id, Conditio
case CONDITION_YELLTICKS:
case CONDITION_PACIFIED:
return std::make_shared<ConditionGeneric>(id, type, ticks, buff, subId);
case CONDITION_GOSHNARTAINT:
return std::make_shared<ConditionGeneric>(id, type, ticks, buff, subId);

default:
return nullptr;
Expand Down Expand Up @@ -390,7 +392,26 @@ uint32_t ConditionGeneric::getIcons() const {
case CONDITION_ROOTED:
icons |= ICON_ROOTED;
break;

case CONDITION_GOSHNARTAINT:
switch (subId) {
case 1:
icons = ICON_GOSHNARTAINT_1;
break;
case 2:
icons = ICON_GOSHNARTAINT_2;
break;
case 3:
icons = ICON_GOSHNARTAINT_3;
break;
case 4:
icons = ICON_GOSHNARTAINT_4;
break;
case 5:
icons = ICON_GOSHNARTAINT_5;
break;
default:
break;
}
default:
break;
}
Expand Down
6 changes: 1 addition & 5 deletions src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ enum ConditionType_t : uint8_t {
CONDITION_LESSERHEX = 31,
CONDITION_INTENSEHEX = 32,
CONDITION_GREATERHEX = 33,
CONDITION_GOSHNAR1 = 34,
CONDITION_GOSHNAR2 = 35,
CONDITION_GOSHNAR3 = 36,
CONDITION_GOSHNAR4 = 37,
CONDITION_GOSHNAR5 = 38,
CONDITION_GOSHNARTAINT = 34,

// Need the last ever
CONDITION_COUNT = 39
Expand Down
34 changes: 3 additions & 31 deletions src/lua/functions/core/game/lua_enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,37 +316,9 @@ void LuaEnums::initFactionEnums(lua_State* L) {
}

void LuaEnums::initConditionEnums(lua_State* L) {
registerEnum(L, CONDITION_NONE);
registerEnum(L, CONDITION_POISON);
registerEnum(L, CONDITION_FIRE);
registerEnum(L, CONDITION_ENERGY);
registerEnum(L, CONDITION_BLEEDING);
registerEnum(L, CONDITION_HASTE);
registerEnum(L, CONDITION_PARALYZE);
registerEnum(L, CONDITION_OUTFIT);
registerEnum(L, CONDITION_INVISIBLE);
registerEnum(L, CONDITION_LIGHT);
registerEnum(L, CONDITION_MANASHIELD);
registerEnum(L, CONDITION_INFIGHT);
registerEnum(L, CONDITION_DRUNK);
registerEnum(L, CONDITION_EXHAUST);
registerEnum(L, CONDITION_REGENERATION);
registerEnum(L, CONDITION_SOUL);
registerEnum(L, CONDITION_DROWN);
registerEnum(L, CONDITION_MUTED);
registerEnum(L, CONDITION_CHANNELMUTEDTICKS);
registerEnum(L, CONDITION_YELLTICKS);
registerEnum(L, CONDITION_ATTRIBUTES);
registerEnum(L, CONDITION_FREEZING);
registerEnum(L, CONDITION_DAZZLED);
registerEnum(L, CONDITION_CURSED);
registerEnum(L, CONDITION_EXHAUST_COMBAT);
registerEnum(L, CONDITION_EXHAUST_HEAL);
registerEnum(L, CONDITION_PACIFIED);
registerEnum(L, CONDITION_SPELLCOOLDOWN);
registerEnum(L, CONDITION_SPELLGROUPCOOLDOWN);
registerEnum(L, CONDITION_ROOTED);
registerEnum(L, CONDITION_FEARED);
for (auto value : magic_enum::enum_values<ConditionType_t>()) {
registerMagicEnum(L, value);
}
}

void LuaEnums::initConditionIdEnums(lua_State* L) {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/utils_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ enum Icons_t {
ICON_GREATERHEX = 1 << 18,
ICON_ROOTED = 1 << 19,
ICON_FEARED = 1 << 20,
ICON_GOSHNAR1 = 1 << 21,
ICON_GOSHNAR2 = 1 << 22,
ICON_GOSHNAR3 = 1 << 23,
ICON_GOSHNAR4 = 1 << 24,
ICON_GOSHNAR5 = 1 << 25,
ICON_GOSHNARTAINT_1 = 1 << 21,
ICON_GOSHNARTAINT_2 = 1 << 22,
ICON_GOSHNARTAINT_3 = 1 << 23,
ICON_GOSHNARTAINT_4 = 1 << 24,
ICON_GOSHNARTAINT_5 = 1 << 25,
ICON_NEWMANASHIELD = 1 << 26,
};

Expand Down

0 comments on commit b1fb702

Please sign in to comment.