Skip to content

Commit b105b6f

Browse files
committed
fix: add condition for taint icon
1 parent 8319f29 commit b105b6f

7 files changed

Lines changed: 76 additions & 57 deletions

File tree

data-otservbr-global/scripts/lib/quests/soul-war.lua

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -970,11 +970,11 @@ end
970970

971971
TaintTeleportCooldown = {}
972972

973-
function Player:getTaintNameByNumber(taintNumber)
973+
function Player:getTaintNameByNumber(taintNumber, skipKvCheck)
974974
local haveTaintName = nil
975975
local soulWarQuest = self:soulWarQuestKV()
976976
local taintName = soulWarTaints[taintNumber]
977-
if taintName and soulWarQuest:get(taintName) then
977+
if skipKvCheck or taintName and soulWarQuest:get(taintName) then
978978
haveTaintName = taintName
979979
end
980980

@@ -983,15 +983,29 @@ end
983983

984984
function Player:addNextTaint()
985985
local soulWarQuest = self:soulWarQuestKV()
986-
for _, taint in ipairs(soulWarTaints) do
987-
if not soulWarQuest:get(taint) then
988-
soulWarQuest:set(taint, true)
989-
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have gained the " .. taint .. ".")
986+
for _, taintName in ipairs(soulWarTaints) do
987+
if not soulWarQuest:get(taintName) then
988+
soulWarQuest:set(taintName, true)
989+
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have gained the " .. taintName .. ".")
990+
self:setTaintIcon()
990991
break
991992
end
992993
end
993994
end
994995

996+
function Player:setTaintIcon(taintId)
997+
self:resetTaintConditions()
998+
local condition = Condition(CONDITION_GOSHNARTAINT, CONDITIONID_DEFAULT, taintId or self:getTaintLevel())
999+
condition:setTicks(14 * 24 * 60 * 60 * 1000)
1000+
self:addCondition(condition)
1001+
end
1002+
1003+
function Player:resetTaintConditions()
1004+
for i = 1, 5 do
1005+
self:removeCondition(CONDITION_GOSHNARTAINT, CONDITIONID_DEFAULT, i)
1006+
end
1007+
end
1008+
9951009
function Player:getTaintLevel()
9961010
local taintLevel = nil
9971011
local soulWarQuest = self:soulWarQuestKV()
@@ -1004,17 +1018,17 @@ function Player:getTaintLevel()
10041018
return taintLevel
10051019
end
10061020

1007-
function Player:resetTaints()
1021+
function Player:resetTaints(skipCheckTime)
10081022
local soulWarQuest = self:soulWarQuestKV()
10091023
local firstTaintTime = soulWarQuest:get("firstTaintTime")
1010-
if firstTaintTime and os.time() >= (firstTaintTime + TaintDurationSeconds) then
1011-
-- Reset all taints
1012-
for _, taint in ipairs(soulWarTaints) do
1013-
if soulWarQuest:get(taint) then
1014-
soulWarQuest:remove(taint)
1024+
if skipCheckTime or firstTaintTime and os.time() >= (firstTaintTime + TaintDurationSeconds) then
1025+
-- Reset all taints and remove condition
1026+
for _, taintName in ipairs(soulWarTaints) do
1027+
if soulWarQuest:get(taintName) then
1028+
soulWarQuest:remove(taintName)
10151029
end
10161030
end
1017-
1031+
self:resetTaintConditions()
10181032
soulWarQuest:remove("firstTaintTime")
10191033
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your goshnar's taints have been reset. You didn't finish the quest in 14 days")
10201034
end
@@ -1028,7 +1042,7 @@ function Monster:tryTeleportToPlayer(sayMessage)
10281042
for i, spectator in ipairs(spectators) do
10291043
if spectator:isPlayer() then
10301044
local player = spectator:getPlayer()
1031-
if player:getTaintNameByNumber(1) then
1045+
if player:getTaintNameByNumber(1, true) then
10321046
local distance = self:getPosition():getDistance(player:getPosition())
10331047
if distance > maxDistance then
10341048
maxDistance = distance

data-otservbr-global/scripts/quests/soul_war/soul_war_mechanics.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ login:register()
4444
local goshnarsMaliceReflection = CreatureEvent("Goshnar's-Malice")
4545

4646
function goshnarsMaliceReflection.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
47+
if not attacker then
48+
return primaryDamage, primaryType, secondaryDamage, secondaryType
49+
end
50+
4751
local player = attacker:getPlayer()
4852
if player then
4953
if primaryDamage > 0 and (primaryType == COMBAT_PHYSICALDAMAGE or primaryType == COMBAT_DEATHDAMAGE) then
@@ -261,11 +265,13 @@ function setTaint.onSay(player, words, param)
261265
end
262266

263267
local taintLevel = split[2]:trim():lower()
264-
local taintName = player:getTaintNameByNumber(tonumber(taintLevel))
268+
local taintName = player:getTaintNameByNumber(tonumber(taintLevel), true)
265269
if taintName ~= nil then
270+
target:resetTaints(true)
266271
target:soulWarQuestKV():set(taintName, true)
267272
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You new taint level is: " .. taintLevel .. ", name: " .. taintName)
268273
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Added taint level: " .. taintLevel .. ", name: " .. taintName .. " to player: " .. target:getName())
274+
target:setTaintIcon()
269275
end
270276
end
271277

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local talkaction = TalkAction("/testtaintconditions")
2+
3+
function talkaction.onSay(player, words, param)
4+
player:setTaintIcon()
5+
return false
6+
end
7+
8+
talkaction:separator(" ")
9+
talkaction:groupType("god")
10+
talkaction:register()

src/creatures/combat/condition.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ std::shared_ptr<Condition> Condition::createCondition(ConditionId_t id, Conditio
242242
case CONDITION_YELLTICKS:
243243
case CONDITION_PACIFIED:
244244
return std::make_shared<ConditionGeneric>(id, type, ticks, buff, subId);
245+
case CONDITION_GOSHNARTAINT:
246+
return std::make_shared<ConditionGeneric>(id, type, ticks, buff, subId);
245247

246248
default:
247249
return nullptr;
@@ -390,7 +392,26 @@ uint32_t ConditionGeneric::getIcons() const {
390392
case CONDITION_ROOTED:
391393
icons |= ICON_ROOTED;
392394
break;
393-
395+
case CONDITION_GOSHNARTAINT:
396+
switch(subId) {
397+
case 1:
398+
icons = ICON_GOSHNARTAINT_1;
399+
break;
400+
case 2:
401+
icons = ICON_GOSHNARTAINT_2;
402+
break;
403+
case 3:
404+
icons = ICON_GOSHNARTAINT_3;
405+
break;
406+
case 4:
407+
icons = ICON_GOSHNARTAINT_4;
408+
break;
409+
case 5:
410+
icons = ICON_GOSHNARTAINT_5;
411+
break;
412+
default:
413+
break;
414+
}
394415
default:
395416
break;
396417
}

src/creatures/creatures_definitions.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ enum ConditionType_t : uint8_t {
112112
CONDITION_LESSERHEX = 31,
113113
CONDITION_INTENSEHEX = 32,
114114
CONDITION_GREATERHEX = 33,
115-
CONDITION_GOSHNAR1 = 34,
116-
CONDITION_GOSHNAR2 = 35,
117-
CONDITION_GOSHNAR3 = 36,
118-
CONDITION_GOSHNAR4 = 37,
119-
CONDITION_GOSHNAR5 = 38,
115+
CONDITION_GOSHNARTAINT = 34,
120116

121117
// Need the last ever
122118
CONDITION_COUNT = 39

src/lua/functions/core/game/lua_enums.cpp

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -316,37 +316,9 @@ void LuaEnums::initFactionEnums(lua_State* L) {
316316
}
317317

318318
void LuaEnums::initConditionEnums(lua_State* L) {
319-
registerEnum(L, CONDITION_NONE);
320-
registerEnum(L, CONDITION_POISON);
321-
registerEnum(L, CONDITION_FIRE);
322-
registerEnum(L, CONDITION_ENERGY);
323-
registerEnum(L, CONDITION_BLEEDING);
324-
registerEnum(L, CONDITION_HASTE);
325-
registerEnum(L, CONDITION_PARALYZE);
326-
registerEnum(L, CONDITION_OUTFIT);
327-
registerEnum(L, CONDITION_INVISIBLE);
328-
registerEnum(L, CONDITION_LIGHT);
329-
registerEnum(L, CONDITION_MANASHIELD);
330-
registerEnum(L, CONDITION_INFIGHT);
331-
registerEnum(L, CONDITION_DRUNK);
332-
registerEnum(L, CONDITION_EXHAUST);
333-
registerEnum(L, CONDITION_REGENERATION);
334-
registerEnum(L, CONDITION_SOUL);
335-
registerEnum(L, CONDITION_DROWN);
336-
registerEnum(L, CONDITION_MUTED);
337-
registerEnum(L, CONDITION_CHANNELMUTEDTICKS);
338-
registerEnum(L, CONDITION_YELLTICKS);
339-
registerEnum(L, CONDITION_ATTRIBUTES);
340-
registerEnum(L, CONDITION_FREEZING);
341-
registerEnum(L, CONDITION_DAZZLED);
342-
registerEnum(L, CONDITION_CURSED);
343-
registerEnum(L, CONDITION_EXHAUST_COMBAT);
344-
registerEnum(L, CONDITION_EXHAUST_HEAL);
345-
registerEnum(L, CONDITION_PACIFIED);
346-
registerEnum(L, CONDITION_SPELLCOOLDOWN);
347-
registerEnum(L, CONDITION_SPELLGROUPCOOLDOWN);
348-
registerEnum(L, CONDITION_ROOTED);
349-
registerEnum(L, CONDITION_FEARED);
319+
for (auto value : magic_enum::enum_values<ConditionType_t>()) {
320+
registerMagicEnum(L, value);
321+
}
350322
}
351323

352324
void LuaEnums::initConditionIdEnums(lua_State* L) {

src/utils/utils_definitions.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ enum Icons_t {
3232
ICON_GREATERHEX = 1 << 18,
3333
ICON_ROOTED = 1 << 19,
3434
ICON_FEARED = 1 << 20,
35-
ICON_GOSHNAR1 = 1 << 21,
36-
ICON_GOSHNAR2 = 1 << 22,
37-
ICON_GOSHNAR3 = 1 << 23,
38-
ICON_GOSHNAR4 = 1 << 24,
39-
ICON_GOSHNAR5 = 1 << 25,
35+
ICON_GOSHNARTAINT_1 = 1 << 21,
36+
ICON_GOSHNARTAINT_2 = 1 << 22,
37+
ICON_GOSHNARTAINT_3 = 1 << 23,
38+
ICON_GOSHNARTAINT_4 = 1 << 24,
39+
ICON_GOSHNARTAINT_5 = 1 << 25,
4040
ICON_NEWMANASHIELD = 1 << 26,
4141
};
4242

0 commit comments

Comments
 (0)