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

stores

git-svn-id: http://svn.net-core.org/repos/t-engine4@375 51575b47-30f0-44d4-a5cc-537603b46e54
parent 9c79699b
No related branches found
No related tags found
No related merge requests found
require "engine.class"
require "engine.Dialog"
module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, action)
self.store_inven = store_inven
self.actor_inven = actor_inven
self.store_filter = store_filter
self.actor_filter = actor_filter
engine.Dialog.init(self, title or "Store", game.w * 0.8, game.h * 0.8, nil, nil, nil, core.display.newFont("/data/font/VeraMono.ttf", 12))
self:generateList()
self.list = self.store_list
self.sel = 1
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list)
self:use()
end
end,
},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_LEFT = function() end,
MOVE_RIGHT = function() end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "left" then self:use()
elseif button == "right" then
end
end },
}
end
function _M:use()
game:unregisterDialog(self)
if self.list[self.sel] then
self.action(self.list[self.sel].object, self.list[self.sel].item)
end
end
function _M:generateList()
-- Makes up the list
local list = {}
local i = 0
for item, o in ipairs(self.store_inven) do
if not self.store_filter or self.store_filter(o) then
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..o:getName(), color=o:getDisplayColor(), object=o, item=item }
i = i + 1
end
end
self.store_list = list
-- Makes up the list
local list = {}
local i = 0
for item, o in ipairs(self.actor_inven) do
if not self.actor_filter or self.actor_filter(o) then
list[#list+1] = { name=string.char(string.byte('a') + i)..") "..o:getName(), color=o:getDisplayColor(), object=o, item=item }
i = i + 1
end
end
self.actor_list = list
end
function _M:drawDialog(s)
-- Description part
self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
local help = [[Keyboard: #00FF00#up key/down key#FFFFFF# to select an object; #00FF00#enter#FFFFFF# to use.
Mouse: #00FF00#Left click#FFFFFF# to use.
]]
local talentshelp = help:splitLines(self.iw / 2 - 10, self.font)
-- local lines = {}
-- local h = 2
-- for i = 1, #talentshelp do
-- s:drawColorString(self.font, talentshelp[i], self.iw / 2 + 5, h)
-- h = h + self.font:lineSkip()
-- end
-- h = h + self.font:lineSkip()
-- if self.store_list[self.store_sel] then
-- lines = self.store_list[self.store_sel].object:getDesc():splitLines(self.iw / 2 - 10, self.font)
-- else
-- lines = {}
-- end
-- self:drawWBorder(s, self.iw / 2 + self.iw / 6, h - 0.5 * self.font:lineSkip(), self.iw / 6)
-- for i = 1, #lines do
-- s:drawColorString(self.font, lines[i], self.iw / 2 + 5, 2 + h)
-- h = h + self.font:lineSkip()
-- end
self:drawSelectionList(s, 2, 5, self.font_h, self.store_list, self.sel, "name", self.scroll, self.max)
self:drawSelectionList(s, self.iw / 2 + 5, 5, self.font_h, self.actor_list, self.sel, "name", self.scroll, self.max)
end
......@@ -646,6 +646,7 @@ end
--- Can the target be applied some effects
-- @param what a string describing what is being tried
function _M:canBe(what)
if what == "poison" and self:attr("poison_immune") then return false end
if what == "cut" and self:attr("cut_immune") then return false end
if what == "blind" and self:attr("blind_immune") then return false end
if what == "stun" and self:attr("stun_immune") then return false end
......
......@@ -29,9 +29,17 @@ function _M:loadup(level, zone)
local filter = rng.table(s.filters)
local e = zone:makeEntity(level, "object", filter)
if e then
if filter.id then e:identify(filter.id) end
self:addObject(inven, e)
print("[STORE] stocking up: ", e.name)
end
end
self:sortInven(inven)
self.last_filled = game.turn
end
function _M:interact(who)
local D = require "engine.dialogs.ShowStore"
local d = D.new("Store: "..self.name, self:getInven("INVEN"), who:getInven("INVEN"), nil, nil, function() end)
game:registerDialog(d)
end
......@@ -24,6 +24,16 @@ Autolevel:registerScheme{ name = "rogue", levelup = function(self)
learnStats(self, { self.STAT_DEX, self.STAT_CUN, self.STAT_CUN })
end}
Autolevel:registerScheme{ name = "archer", levelup = function(self)
-- 2 STR for 1 DEX
learnStats(self, { self.STAT_DEX, self.STAT_DEX, self.STAT_CUN })
end}
Autolevel:registerScheme{ name = "slinger", levelup = function(self)
-- 2 STR for 1 DEX
learnStats(self, { self.STAT_DEX, self.STAT_DEX, self.STAT_STR })
end}
Autolevel:registerScheme{ name = "caster", levelup = function(self)
-- 2 MAG for 1 WIL
learnStats(self, { self.STAT_MAG, self.STAT_MAG, self.STAT_WIL })
......
......@@ -221,6 +221,7 @@ newDamageType{
newDamageType{
name = "poison", type = "POISON",
projector = function(src, x, y, type, dam)
if not target:canBe("poison") then return end
DamageType:get(DamageType.NATURE).projector(src, x, y, DamageType.NATURE, dam / 6)
dam = dam - dam / 6
local target = game.level.map(x, y, Map.ACTOR)
......@@ -325,3 +326,4 @@ newDamageType{
end
end,
}
......@@ -8,8 +8,8 @@ newEntity{
min_fill = 10,
max_fill = 20,
filters = {
{type="potion"},
{type="scroll"},
{type="potion", id=true},
{type="scroll", id=true},
},
-- fixed = {
-- },
......
......@@ -23,6 +23,14 @@ quickEntity('D', {name="A path into the Old Forest", display='>', color={r=0,
quickEntity('E', {name="A mysterious hole in the beach", display='>', color={r=200, g=255, b=55}, change_level=1, change_zone="sandworm-lair"})
quickEntity('F', {name="The entry to the old tower of Tol Falas",display='>', color={r=0, g=255, b=255}, change_level=1, change_zone="tol-falas"})
quickEntity('1', {name="General Store", display='1', color={r=0, g=255, b=255},
on_move = function(self, x, y, who)
self.store:loadup(game.level, game.zone)
self.store:interact(who)
end,
store = game.stores_def[1]:clone(),
})
return {
[[========q=qqqqqqqqqgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg]],
[[=========q=qq=qqqqggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg]],
......
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