Skip to content
Snippets Groups Projects
Commit 318a4fde authored by dg's avatar dg
Browse files

Stealth & invis are now only checked every few turns, giving miore chances to rogues

git-svn-id: http://svn.net-core.org/repos/t-engine4@853 51575b47-30f0-44d4-a5cc-537603b46e54
parent 8f60e201
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,15 @@ function _M:init(t, no_default)
Entity.init(self, t, no_default)
self.compute_vals = {n=0}
self.can_see_cache = {}
self:loaded()
end
--- Called when loaded
-- Will setup the metatable on can_see_cache to be weak keys
function _M:loaded()
setmetatable(self.can_see_cache, {__mode='k'})
end
--- Called when it is time to act
......@@ -259,8 +268,11 @@ end
-- This does not check LOS or such, only the actual ability to see it.<br/>
-- By default this returns true, but a module can override it to check for telepathy, invisibility, stealth, ...
-- @param actor the target actor to check
-- @param def the default
-- @param def_pct the default percent chance
-- @param nocache if true does not save value in the cache (not used, it's up to the module to use the cache)
-- @return true or false and a number from 0 to 100 representing the "chance" to be seen
function _M:canSee(actor)
function _M:canSee(actor, def, def_pct, nocache)
return true, 100
end
......
......@@ -528,7 +528,7 @@ function _M:applyESP(x, y, v)
if not self.actor_player then return end
if x < 0 or x >= self.w or y < 0 or y >= self.h then return end
local a = self(x, y, ACTOR)
if a and self.actor_player:canSee(a, false, 0) then
if a and self.actor_player:canSee(a, false, 0, true) then
self.seens[x + y * self.w] = v or 1
self._map:setSeen(x, y, v or 1)
end
......
......@@ -960,8 +960,11 @@ end
--- Can the actor see the target actor
-- This does not check LOS or such, only the actual ability to see it.<br/>
-- Check for telepathy, invisibility, stealth, ...
function _M:canSee(actor, def, def_pct)
function _M:canSee(actor, def, def_pct, nocache)
if not actor then return false, 0 end
if not nocache and self.can_see_cache[actor] and self.can_see_cache[actor].turn >= game.turn then
return self.can_see_cache[actor].seen, self.can_see_cache[actor].chance
end
-- ESP, see all, or only types/subtypes
if self:attr("esp") then
......@@ -971,22 +974,33 @@ function _M:canSee(actor, def, def_pct)
if game.level then
game.level.map.seens(actor.x, actor.y, 1)
end
if not nocache then self.can_see_cache[actor] = {turn=game.turn, seen=true, chance=100} end
return true, 100
end
-- Type based ESP
if esp[actor.type] and esp[actor.type] > 0 then return true, 100 end
if esp[actor.type.."/"..actor.subtype] and esp[actor.type.."/"..actor.subtype] > 0 then return true, 100 end
if esp[actor.type] and esp[actor.type] > 0 then
if not nocache then self.can_see_cache[actor] = {turn=game.turn, seen=true, chance=100} end
return true, 100
end
if esp[actor.type.."/"..actor.subtype] and esp[actor.type.."/"..actor.subtype] > 0 then
if not nocache then self.can_see_cache[actor] = {turn=game.turn, seen=true, chance=100} end
return true, 100
end
end
-- Blindness means can't see anything
if self:attr("blind") then return false, 0 end
if self:attr("blind") then
if not nocache then self.can_see_cache[actor] = {turn=game.turn, seen=false, chance=0} end
return false, 0
end
-- Check for stealth. Checks against the target cunning and level
if actor:attr("stealth") and actor ~= self then
local def = self.level / 2 + self:getCun(25)
local hit, chance = self:checkHit(def, actor:attr("stealth") + (actor:attr("inc_stealth") or 0), 0, 100)
if not hit then
if not nocache then self.can_see_cache[actor] = {turn=game.turn+100, seen=false, chance=chance} end
return false, chance
end
end
......@@ -997,12 +1011,15 @@ function _M:canSee(actor, def, def_pct)
if not self:attr("see_invisible") then return false, 0 end
local hit, chance = self:checkHit(self:attr("see_invisible"), actor:attr("invisible"), 0, 100)
if not hit then
if not nocache then self.can_see_cache[actor] = {turn=game.turn+100, seen=false, chance=chance} end
return false, chance
end
end
if def ~= nil then
if not nocache then self.can_see_cache[actor] = {turn=game.turn+100, seen=def, chance=def_pct} end
return def, def_pct
else
if not nocache then self.can_see_cache[actor] = {turn=game.turn+100, seen=true, chance=100} end
return true, 100
end
end
......
......@@ -56,8 +56,8 @@ newEntity{ base = "BASE_NPC_RITCH",
resolvers.talents{
[Talents.T_ROTTING_DISEASE]=3,
[Talents.T_SHRIEK]=1,
},
}
newEntity{ base = "BASE_NPC_RITCH",
......@@ -74,6 +74,7 @@ newEntity{ base = "BASE_NPC_RITCH",
[Talents.T_ROTTING_DISEASE]=4,
[Talents.T_RUSH]=5,
[Talents.T_FLAME]=5,
[Talents.T_SHRIEK]=3,
},
}
......@@ -100,6 +101,7 @@ newEntity{ base = "BASE_NPC_RITCH",
[Talents.T_ROTTING_DISEASE]=5,
[Talents.T_FLAME]=5,
[Talents.T_SUMMON]=1,
[Talents.T_SHRIEK]=4,
},
}
......@@ -636,6 +636,7 @@ newTalent{
tactical = {
ATTACK = 10,
},
message = "@Source@ howls",
range = 20,
action = function(self, t)
local rad = self:getTalentLevel(t) + 5
......@@ -658,3 +659,36 @@ newTalent{
return ([[Howl a call to your hunting pack.]])
end,
}
newTalent{
name = "Shriek",
type = {"wild-gift/other", },
points = 5,
equilibrium = 5,
cooldown = 10,
tactical = {
ATTACK = 10,
},
message = "@Source@ shrieks.",
range = 20,
action = function(self, t)
local rad = self:getTalentLevel(t) + 5
for i = self.x - rad, self.x + rad do for j = self.y - rad, self.y + rad do if game.level.map:isBound(i, j) then
local actor = game.level.map(i, j, game.level.map.ACTOR)
if actor and not actor.player then
if self:reactionToward(actor) >= 0 then
local tx, ty, a = self:getTarget()
if a then
actor:setTarget(a)
end
else
actor:setTarget(self)
end
end
end end end
return true
end,
info = function(self, t)
return ([[Shriek to call your allies.]])
end,
}
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment