diff --git a/game/engine/dialogs/ShowStore.lua b/game/engine/dialogs/ShowStore.lua new file mode 100644 index 0000000000000000000000000000000000000000..2907e27c2ba46f3f93d62957066a71d98925be88 --- /dev/null +++ b/game/engine/dialogs/ShowStore.lua @@ -0,0 +1,106 @@ +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 diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index 1bb70afa668d832d9b8e2b726eebe8bd29e8dc35..da98960653ac8c77a094aa1d2ff95e00df125dfe 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -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 diff --git a/game/modules/tome/class/Store.lua b/game/modules/tome/class/Store.lua index 52840c154d91f5686f6e05beb82b0c1d6dc5b5c4..1edc7229b4743ad63662d2ef62c10ebff23bfccb 100644 --- a/game/modules/tome/class/Store.lua +++ b/game/modules/tome/class/Store.lua @@ -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 diff --git a/game/modules/tome/data/autolevel_schemes.lua b/game/modules/tome/data/autolevel_schemes.lua index 511c328fc7755ccd7f84a9f9e6523c2a85500dfa..69a382be93598727f3bd5d1dcf8f1ac0e1f9a868 100644 --- a/game/modules/tome/data/autolevel_schemes.lua +++ b/game/modules/tome/data/autolevel_schemes.lua @@ -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 }) diff --git a/game/modules/tome/data/damage_types.lua b/game/modules/tome/data/damage_types.lua index fc552293b441e7decf7fc9051e84d5891f669443..a451b3bccaa18d5f5ffe98b7b97123a2272fbd26 100644 --- a/game/modules/tome/data/damage_types.lua +++ b/game/modules/tome/data/damage_types.lua @@ -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, } + diff --git a/game/modules/tome/data/general/stores/basic.lua b/game/modules/tome/data/general/stores/basic.lua index ef321574bd4655685d4550ec252e42aae53f0e8f..b88f0e92369e88c5d5154022ee98256bd0b7f261 100644 --- a/game/modules/tome/data/general/stores/basic.lua +++ b/game/modules/tome/data/general/stores/basic.lua @@ -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 = { -- }, diff --git a/game/modules/tome/data/maps/wilderness/main.lua b/game/modules/tome/data/maps/wilderness/main.lua index 34704b291632116f205063f4f2fc240b23eeb566..ebdfbcd4dd6382530335d8bdfcd000d15a2613a4 100644 --- a/game/modules/tome/data/maps/wilderness/main.lua +++ b/game/modules/tome/data/maps/wilderness/main.lua @@ -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]],