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

Moon and Star (the artifacts) are now a pair and will provide additional bonus when used together

git-svn-id: http://svn.net-core.org/repos/t-engine4@2439 51575b47-30f0-44d4-a5cc-537603b46e54
parent f357eabb
No related branches found
No related tags found
No related merge requests found
......@@ -389,8 +389,8 @@ end
-- You cannot simply increase life_regen, so you use this method which will increase it AND
-- store the increase. it will return an "increase id" that can be passed to removeTemporaryValue()
-- to remove the effect.
-- @param prop the property to affect
-- @param v the value to add (only numbers supported for now)
-- @param prop the property to affect. This can be either a string or a table of strings, the latter allowing nested properties to be modified.
-- @param v the value to add. This should either be a number or a table of properties and numbers.
-- @param noupdate if true the actual property is not changed and needs to be changed by the caller
-- @return an id that can be passed to removeTemporaryValue() to delete this value
function _M:addTemporaryValue(prop, v, noupdate)
......@@ -402,32 +402,45 @@ function _M:addTemporaryValue(prop, v, noupdate)
t[id] = v
t.n = id
-- Update the base prop
if not noupdate then
-- Find the base, one removed from the last prop
local initial_base, initial_prop
if type(prop) == "table" then
initial_base = self
local idx = 1
while idx < #prop do
initial_base = initial_base[prop[idx]]
idx = idx + 1
end
initial_prop = prop[idx]
else
initial_base = self
initial_prop = prop
end
-- The recursive enclosure
local recursive
recursive = function(base, prop, v)
if type(v) == "number" then
-- Simple addition
self[prop] = (self[prop] or 0) + v
base[prop] = (base[prop] or 0) + v
self:onTemporaryValueChange(prop, nil, v)
print("addTmpVal", prop, v, " :=: ", #t, id)
print("addTmpVal", base, prop, v, " :=: ", #t, id)
elseif type(v) == "table" then
for k, e in pairs(v) do
self[prop][k] = (self[prop][k] or 0) + e
self:onTemporaryValueChange(prop, k, e)
print("addTmpValTable", prop, k, e, " :=: ", #t, id)
if #t == 0 then print("*******************************WARNING") end
print("addTmpValTable", base[prop], k, e)
base[prop] = base[prop] or {}
recursive(base[prop], k, e)
end
-- elseif type(v) == "boolean" then
-- -- False has precedence over true
-- if v == false then
-- self[prop] = false
-- elseif self[prop] ~= false then
-- self[prop] = true
-- end
else
error("unsupported temporary value type: "..type(v))
error("unsupported temporary value type: "..type(v).." :=: "..v)
end
end
-- Update the base prop
if not noupdate then
recursive(initial_base, initial_prop, v)
end
return id
end
......@@ -439,22 +452,43 @@ function _M:removeTemporaryValue(prop, id, noupdate)
local oldval = self.compute_vals[id]
print("removeTempVal", prop, oldval, " :=: ", id)
self.compute_vals[id] = nil
if not noupdate then
if type(oldval) == "number" then
self[prop] = self[prop] - oldval
self:onTemporaryValueChange(prop, nil, -oldval)
print("delTmpVal", prop, oldval)
elseif type(oldval) == "table" then
for k, e in pairs(oldval) do
self[prop][k] = self[prop][k] - e
self:onTemporaryValueChange(prop, k, -e)
print("delTmpValTable", prop, k, e)
-- Find the base, one removed from the last prop
local initial_base, initial_prop
if type(prop) == "table" then
initial_base = self
local idx = 1
while idx < #prop do
initial_base = initial_base[prop[idx]]
idx = idx + 1
end
initial_prop = prop[idx]
else
initial_base = self
initial_prop = prop
end
-- The recursive enclosure
local recursive
recursive = function(base, prop, v)
if type(v) == "number" then
-- Simple addition
base[prop] = base[prop] - v
self:onTemporaryValueChange(prop, nil, v)
print("delTmpVal", prop, v)
elseif type(v) == "table" then
for k, e in pairs(v) do
recursive(base[prop], k, e)
end
-- elseif type(oldval) == "boolean" then
else
error("unsupported temporary value type: "..type(oldval))
error("unsupported temporary value type: "..type(v).." :=: "..v)
end
end
-- Update the base prop
if not noupdate then
recursive(initial_base, initial_prop, oldval)
end
end
--- Called when a temporary value changes (added or deleted)
......
......@@ -649,7 +649,37 @@ newEntity{ base = "BASE_KNIFE",
},
}
newEntity{ base = "BASE_KNIFE",
-- The Twin blades Moon and Star
local activate_pair = function(moon, star, who)
local DamageType = require "engine.DamageType"
moon.paired = {}
star.paired = {}
-- The Moon knife's bonuses
moon.paired._special1 = {who, "lite", who:addTemporaryValue("lite", 1)}
moon.paired._special2 = {moon, "combat", moon:addTemporaryValue("combat", {melee_project={[DamageType.BLINDPHYSICAL]=2}})}
moon.paired._special3 = {who, {"inc_damage", DamageType.DARKNESS}, who:addTemporaryValue({"inc_damage", DamageType.DARKNESS}, 10)}
-- The Star knife's bonuses
star.paired._special1 = {who, "lite", who:addTemporaryValue("lite", 1)}
star.paired._special2 = {star, "combat", star:addTemporaryValue("combat", {melee_project={[DamageType.RANDOM_CONFUSION]=2}})}
star.paired._special3 = {who, "inc_damage", who:addTemporaryValue("inc_damage", {[DamageType.LIGHT]=10}) }
game.log("The two blades glow brightly as they are brought close together.")
end
local deactivate_pair = function(moon, star, who)
-- Remove the paired bonusese
for k, id in pairs(moon.paired) do
id[1]:removeTemporaryValue(id[2], id[3])
end
for k, id in pairs(star.paired) do
id[1]:removeTemporaryValue(id[2], id[3])
end
moon.paired = nil
star.paired = nil
game.log("The light from the two blades fades as they are separated.")
end
newEntity{ base = "BASE_KNIFE", define_as = "ART_PAIR_MOON",
unique = true,
name = "Moon",
unided_name = "crescent blade",
......@@ -672,9 +702,26 @@ newEntity{ base = "BASE_KNIFE",
[DamageType.DARKNESS] = 5,
},
},
activate_pair = activate_pair,
deactivate_pair = deactivate_pair,
on_wear = function(self, who)
-- Look for the Moon knife
local o, item, inven_id = who:findInAllInventoriesBy("define_as", "ART_PAIR_STAR")
if o and who:getInven(inven_id).worn then
self.activate_pair(o, self, who)
end
end,
on_takeoff = function(self, who)
if self.paired then
local o, item, inven_id = who:findInAllInventoriesBy("define_as", "ART_PAIR_STAR")
if o and who:getInven(inven_id).worn then
self.deactivate_pair(o, self, who)
end
end
end,
}
newEntity{ base = "BASE_KNIFE",
newEntity{ base = "BASE_KNIFE", define_as = "ART_PAIR_STAR",
unique = true,
name = "Star",
unided_name = "jagged blade",
......@@ -697,6 +744,23 @@ newEntity{ base = "BASE_KNIFE",
[DamageType.LIGHT] = 5,
},
},
activate_pair = activate_pair,
deactivate_pair = deactivate_pair,
on_wear = function(self, who)
-- Look for the Moon knife
local o, item, inven_id = who:findInAllInventoriesBy("define_as", "ART_PAIR_MOON")
if o and who:getInven(inven_id).worn then
self.activate_pair(o, self, who)
end
end,
on_takeoff = function(self, who)
if self.paired then
local o, item, inven_id = who:findInAllInventoriesBy("define_as", "ART_PAIR_MOON")
if o and who:getInven(inven_id).worn then
self.deactivate_pair(o, self, who)
end
end
end,
}
newEntity{ base = "BASE_RING",
......
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