Skip to content
Snippets Groups Projects
Commit 6e7f2dc0 authored by Alex Ksandra's avatar Alex Ksandra
Browse files

First steps in da place!

parent fbb7dcc7
No related branches found
No related tags found
1 merge request!180[FOR REVIEW, NOT FOR 1.3] Staff, obey my command!
......@@ -2481,7 +2481,7 @@ local standard_flavors = {
}
-- from command-staff.lua
local function update_staff_table(d_table_old, d_table_new, old_element, new_element, tab, v, is_greater)
local function update_staff_table(o, d_table_old, d_table_new, old_element, new_element, tab, v, is_greater)
if is_greater then
for i = 1, #d_table_old do
o.wielder[tab][d_table_old[i]] = math.max(0, o.wielder[tab][d_table_old[i]] - v)
......@@ -2491,6 +2491,8 @@ local function update_staff_table(d_table_old, d_table_new, old_element, new_ele
o.wielder[tab][d_table_new[i]] = (o.wielder[tab][d_table_new[i]] or 0) + v
end
else
table.print(o.wielder[tab])
game.log("%s %s", old_element, new_element)
o.wielder[tab][old_element] = math.max(0, o.wielder[tab][old_element] - v)
o.wielder[tab][new_element] = (o.wielder[tab][new_element] or 0) + v
if o.wielder[tab][old_element] == 0 then o.wielder[tab][old_element] = nil end
......@@ -2504,29 +2506,43 @@ function _M:getStaffFlavor(o, flavor)
else return flavors[flavor] end
end
local function staff_command(o) -- compat
if o.command_staff then return o.command_staff end
if o.no_command then return {} end
o.command_staff = {
inc_damage = 1,
resists = o.of_protection and 0.5 or nil,
resists_pen = o.of_breaching and 0.5 or nil,
of_warding = o.of_warding and {add=2, mult=0, "wards"} or nil,
of_greater_warding = o.of_greater_warding and {add=3, mult=0, "wards"} or nil,
}
return o.command_staff
end
-- Command a staff to another element
function _M:commandStaff(o, element, flavor)
if o.type ~= "staff" then return end
local old_element = o.combat_element
if o.subtype ~= "staff" then game.log("type fail %s", o.type) return end
local old_element = o.combat.element
-- Art staves may define new flavors or redefine meaning of existing ones; "true" means standard, otherwise it should be a list of damage types.
local old_flavor = self:getStaffFlavor(o, o.flavor_name)
local new_flavor = self:getStaffFlavor(o, flavor)
if not old_flavor or not new_flavor then return end
if not old_flavor or not new_flavor then game.log("flavor fail %s %s", o.flavor_name, flavor) return end
local staff_power = o.staff_power or o.combat.dam
local is_greater = o.is_greater
for k, v in pairs(staff.commands) do
for k, v in pairs(staff_command(o)) do
if type(v) == "table" then
local power = staff_power * (v.mult or 1) + v.add
update_staff_table(old_flavor, new_flavor, old_element, element, v[1] or k, power, is_greater)
update_staff_table(o, old_flavor, new_flavor, old_element, element, v[1] or k, power, is_greater)
elseif type(v) == "number" then -- shortcut for previous case
update_staff_table(old_flavor, new_flavor, old_element, element, k, staff_power * v, is_greater)
update_staff_table(o, old_flavor, new_flavor, old_element, element, k, staff_power * v, is_greater)
else
v(o, element, flavor, update_staff_table)
end
end
o.combat.element = element
if o.melee_element then o.combat.damtype = element
if o.melee_element then o.combat.damtype = element end
if not o.unique then o.name = o.name:gsub(o.flavor_name, flavor) end
o.flavor_name = flavor
end
\ No newline at end of file
......@@ -100,52 +100,17 @@ local function is_sentient()
return o.combat.sentient
end
local function update_table(d_table_old, d_table_new, old_element, new_element, tab, v, is_greater)
if is_greater then
for i = 1, #d_table_old do
o.wielder[tab][d_table_old[i]] = o.wielder[tab][d_table_old[i]] - v
if o.wielder[tab][d_table_old[i]] == 0 then o.wielder[tab][d_table_old[i]] = nil end
end
for i = 1, #d_table_new do
o.wielder[tab][d_table_new[i]] = (o.wielder[tab][d_table_new[i]] or 0) + v
end
else
o.wielder[tab][old_element] = o.wielder[tab][old_element] - v
o.wielder[tab][new_element] = (o.wielder[tab][new_element] or 0) + v
if o.wielder[tab][old_element] == 0 then o.wielder[tab][old_element] = nil end
end
end
local function set_element(element, new_flavor, player)
state.set_element = true
local old_reset = player.no_power_reset_on_wear
player.no_power_reset_on_wear = true
local prev_name = o:getName{no_count=true, force_id=true, no_add_name=true}
local dam = o.combat.dam
local inven = player:getInven("MAINHAND")
local o = player:takeoffObject(inven, 1)
local dam_tables = {
magestaff = {engine.DamageType.FIRE, engine.DamageType.COLD, engine.DamageType.LIGHTNING, engine.DamageType.ARCANE},
starstaff = {engine.DamageType.LIGHT, engine.DamageType.DARKNESS, engine.DamageType.TEMPORAL, engine.DamageType.PHYSICAL},
vilestaff = {engine.DamageType.DARKNESS, engine.DamageType.BLIGHT, engine.DamageType.ACID, engine.DamageType.FIRE}, -- yes it overlaps, it's okay
}
update_table(dam_tables[o.flavor_name], dam_tables[new_flavor], o.combat.element, element, "inc_damage", dam, o.combat.is_greater)
if o.combat.of_warding then update_table(dam_tables[o.flavor_name], dam_tables[new_flavor], o.combat.element, element, "wards", 2, o.combat.is_greater) end
if o.combat.of_greater_warding then update_table(dam_tables[o.flavor_name], dam_tables[new_flavor], o.combat.element, element, "wards", 3, o.combat.is_greater) end
if o.combat.of_breaching then update_table(dam_tables[o.flavor_name], dam_tables[new_flavor], o.combat.element, element, "resists_pen", dam/2, o.combat.is_greater) end
if o.combat.of_protection then update_table(dam_tables[o.flavor_name], dam_tables[new_flavor], o.combat.element, element, "resists", dam/2, o.combat.is_greater) end
--o.combat.damtype = element
o.combat.element = element
if not o.unique then o.name = o.name:gsub(o.flavor_name, new_flavor) end
o.flavor_name = new_flavor
o:resolve()
o:resolve(nil, true)
local _, item, inven_id = player:findInAllInventoriesByObject(o)
if inven_id then player:onTakeoff(o, inven_id, true) end
player:commandStaff(o, element, new_flavor)
local next_name = o:getName{no_count=true, force_id=true, no_add_name=true}
if player.hotkey then
......@@ -155,130 +120,66 @@ local function set_element(element, new_flavor, player)
end
end
player:addObject(inven, o)
player.no_power_reset_on_wear = nil
if inven_id then player:onWear(o, inven_id, true) end
player.no_power_reset_on_wear = old_reset
print("(in chat's set_element) state.set_element is ", state.set_element)
coroutine.resume(co, true)
end
newChat{ id="welcome",
text = intro(o),
answers = {
{"How is it that you speak?", cond = function() return is_sentient() and not o.no_command end, jump="how_speak"},
{"I'd like you to bring forth a different aspect.", cond = function() return is_sentient() and not o.no_command end, jump="which_aspect"},
{"I'd like to alter your basic properties.", cond = function() return is_sentient() and not o.no_command end,
action = function()
coroutine.resume(co, true)
local SentientWeapon = require "mod.dialogs.SentientWeapon"
local ds = SentientWeapon.new({actor=game.player, o=o})
game:registerDialog(ds)
end,
},
{"[Mage]", cond = function() return not is_sentient() and not o.no_command and (not o.only_element or o.only_element == "element_mage") end, jump="element_mage"},
{"[Star]", cond = function() return not is_sentient() and not o.no_command and (not o.only_element or o.only_element == "element_star") end, jump="element_star"},
{"[Vile]", cond = function() return not is_sentient() and not o.no_command and (not o.only_element or o.only_element == "element_vile") end, jump="element_vile"},
{"Never mind"},
}
}
newChat{ id="element_mage",
text = [[Call forth which element?]],
answers = {
{"[Fire]",
action = function()
set_element(DamageType.FIRE, "magestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "teleport")
end,
},
{"[Lightning]",
action = function()
set_element(DamageType.LIGHTNING, "magestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "teleport")
end,
},
{"[Cold]",
action = function()
set_element(DamageType.COLD, "magestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "teleport")
end,
},
{"[Arcane]",
action = function()
set_element(DamageType.ARCANE, "magestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "teleport")
end,
},
{"[Choose different aspect]", jump="welcome"},
{"Never mind"},
}
}
newChat{ id="element_star",
text = [[Call forth which element?]],
answers = {
{"[Light]",
action = function()
set_element(DamageType.LIGHT, "starstaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "temporal_teleport")
end,
},
{"[Darkness]",
action = function()
set_element(DamageType.DARKNESS, "starstaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "temporal_teleport")
end,
},
{"[Temporal]",
action = function()
set_element(DamageType.TEMPORAL, "starstaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "temporal_teleport")
end,
},
{"[Physical]",
action = function()
set_element(DamageType.PHYSICAL, "starstaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "temporal_teleport")
end,
},
{"[Choose different aspect]", jump="welcome"},
{"Never mind"},
}
}
local DamageType = require "engine.DamageType"
local flavors = o.flavors or {magestaff=true, starstaff=true, vilestaff=true}
local flavor_list = table.keys(flavors)
table.sort(flavor_list)
local aspect_answers = {}
local aspect_chat_id = not is_sentient() and "welcome" or "which-aspect"
for _, flavor in ipairs(flavor_list) do
local damtypes = game.player:getStaffFlavor(o, flavor)
local answers = {}
for i, dtype in ipairs(damtypes) do
local name = ("[%s]"):format(DamageType:get(dtype).name:capitalize())
answers[i] = {name, action = function() set_element(dtype, flavor, game.player) end}
end
answers[#answers + 1] = {"Choose different aspect", jump = aspect_chat_id}
answers[#answers + 1] = {"Never mind."}
newChat{id="element_"..flavor, text = "Call forth which element?", answers = answers}
local flavor_name = flavor:gsub("staff", ""):capitalize()
aspect_answers[#aspect_answers + 1] = {("[%s]"):format(flavor_name), jump = "element_"..flavor}
end
newChat{ id="element_vile",
text = [[Call forth which element?]],
answers = {
{"[Darkness]",
action = function()
set_element(DamageType.DARKNESS, "vilestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "demon_teleport")
end,
},
{"[Blight]",
action = function()
set_element(DamageType.BLIGHT, "vilestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "demon_teleport")
end,
},
{"[Acid]",
action = function()
set_element(DamageType.ACID, "vilestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "demon_teleport")
end,
},
{"[Fire]",
action = function()
set_element(DamageType.FIRE, "vilestaff", game.player)
game.level.map:particleEmitter(game.player.x, game.player.y, 1, "demon_teleport")
end,
},
{"[Choose different aspect]", jump="welcome"},
{"Never mind"},
aspect_answers[#aspect_answers + 1] = {"Never mind."}
if is_sentient() then
newChat{ id="welcome",
text = intro(o),
answers = {
{"How is it that you speak?", cond = function() return is_sentient() and not o.no_command end, jump="how_speak"},
{"I'd like you to bring forth a different aspect.", cond = function() return is_sentient() and not o.no_command end, jump="which_aspect"},
{"I'd like to alter your basic properties.", cond = function() return is_sentient() and not o.no_command end,
action = function()
coroutine.resume(co, true)
local SentientWeapon = require "mod.dialogs.SentientWeapon"
local ds = SentientWeapon.new({actor=game.player, o=o})
game:registerDialog(ds)
end,
},
{"Never mind."},
}
}
}
newChat{ id="which_aspect",
text = which_aspect(o),
answers = aspect_answers,
}
else
newChat{ id="welcome",
text = intro(o),
answers = aspect_answers,
}
end
newChat{ id="how_speak",
text = how_speak(o),
......@@ -287,16 +188,5 @@ newChat{ id="how_speak",
}
}
newChat{ id="which_aspect",
text = which_aspect(o),
answers = {
{"[Mage]", jump="element_mage"},
{"[Star]", jump="element_star"},
{"[Vile]", jump="element_vile"},
{"Back up a second.", jump="welcome"},
{"Never mind"},
}
}
return "welcome"
......@@ -38,6 +38,7 @@ newEntity{
damrange = 1.2,
sound = {"actions/melee", pitch=0.6, vol=1.2}, sound_miss = {"actions/melee", pitch=0.6, vol=1.2},
},
command_staff = {inc_damage = 1,},
desc = [[Staves designed for wielders of magic, by the greats of the art.]],
egos = "/data/general/objects/egos/staves.lua", egos_chance = { prefix=resolvers.mbonus(40, 5), suffix=resolvers.mbonus(40, 5) },
}
......
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