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

lost merchant can setup a rare goods store in minas tirith

git-svn-id: http://svn.net-core.org/repos/t-engine4@649 51575b47-30f0-44d4-a5cc-537603b46e54
parent 13746adc
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,7 @@ end
-- @param reaction a numerical value representing the reaction, 0 is neutral, <0 is aggressive, >0 is friendly
-- @param mutual if true the same status will be set for f2 toward f1
function _M:setFactionReaction(f1, f2, reaction, mutual)
print("[FACTION]", f1, f2, reaction, mutual)
-- Faction always like itself
if f1 == f2 then return end
if not self.factions[f1] then return end
......
......@@ -129,6 +129,8 @@ function _M:checkFilter(e, filter)
if e.unique and game.uniques[e.__CLASSNAME.."/"..e.unique] then print("refused unique", e.name, e.__CLASSNAME.."/"..e.unique) return false end
if not filter then return true end
if filter.ignore and self:checkFilter(e, filter.ignore) then return false end
print("Filtering", filter.type, filter.subtype)
if filter.type and filter.type ~= e.type then return false end
......
......@@ -57,19 +57,13 @@ function _M:init(chat, id)
}
end
function _M:use()
local a = self.chat:get(self.cur_id).answers[self.list[self.sel].answer]
function _M:use(a)
a = a or self.chat:get(self.cur_id).answers[self.list[self.sel].answer]
if not a then return end
self.changed = true
print("[CHAT] selected", a[1], a.action, a.jump)
if a.jump then
self.cur_id = a.jump
self:regen()
else
game:unregisterDialog(self)
end
if a.action then
local id = a.action(self.npc, self.player, self)
if id then
......@@ -78,6 +72,13 @@ function _M:use()
return
end
end
if a.jump then
self.cur_id = a.jump
self:regen()
else
game:unregisterDialog(self)
return
end
end
function _M:regen()
......@@ -87,7 +88,20 @@ function _M:regen()
self.scroll = 1
end
function _M:resolveAuto()
if not self.chat:get(self.cur_id).auto then return end
for i, a in ipairs(self.chat:get(self.cur_id).answers) do
if not a.cond or a.cond(self.npc, self.player) then
if not self:use(a) then return
else return self:resolveAuto()
end
end
end
end
function _M:generateList()
self:resolveAuto()
-- Makes up the list
local list = {}
for i, a in ipairs(self.chat:get(self.cur_id).answers) do
......@@ -96,6 +110,7 @@ function _M:generateList()
end
end
self.list = list
return true
end
function _M:drawDialog(s)
......
......@@ -30,6 +30,8 @@ function _M:loadStores(f)
end
function _M:init(t, no_default)
t.buy_percent = t.buy_percent or 10
t.sell_percent = t.sell_percent or 100
Store.init(self, t, no_default)
end
......@@ -40,7 +42,7 @@ end
-- @param nb number of items (if stacked) to buy
-- @return true if allowed to buy
function _M:onBuy(who, o, item, nb)
local price = o:getPrice()
local price = o:getPrice() * self.sell_percent / 100
if who.money >= price * nb then
who.money = who.money - price * nb
return nb
......@@ -56,7 +58,7 @@ end
-- @param nb number of items (if stacked) to sell
-- @return true if allowed to sell
function _M:onSell(who, o, item, nb)
local price = o:getPrice() / 10
local price = o:getPrice() * self.buy_percent / 100
if price <= 0 or nb <= 0 then return end
who.money = who.money + price * nb
o:identify(true)
......@@ -70,11 +72,11 @@ end
-- @return a string (possibly multiline) describing the object
function _M:descObject(who, what, o)
if what == "buy" then
local desc = ("Buy for: %0.2f gold (You have %0.2f gold)\n\n"):format(o:getPrice(), who.money)
local desc = ("Buy for: %0.2f gold (You have %0.2f gold)\n\n"):format(o:getPrice() * self.sell_percent / 100, who.money)
desc = desc .. o:getDesc()
return desc
else
local desc = ("Sell for: %0.2f gold (You have %0.2f gold)\n\n"):format(o:getPrice() / 10, who.money)
local desc = ("Sell for: %0.2f gold (You have %0.2f gold)\n\n"):format(o:getPrice() * self.buy_percent / 100, who.money)
desc = desc .. o:getDesc()
return desc
end
......
-- ToME - Tales of Middle-Earth
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
newChat{ id="start",
auto = true, text="",
answers = {
{cond=function(npc, player) local q = player:hasQuest("lost-merchant"); return q and q:isStatus(q.COMPLETED, "saved") end, jump="welcome"},
{jump="closed"},
},
}
newChat{ id="closed",
text = [[*This store seems to not be open yet*]],
answers = {
{"[leave]"},
}
}
newChat{ id="welcome",
text = [[Ah my good friend @playername@!
Thansk to you I made it safely to this great city, I am to open my shop soon, but I owe you a bit so I could maybe open early for you if you are in need of some rare goods.]],
answers = {
{"Yes please, let me see your wares.", action=function(npc, player)
npc.store:loadup(game.level, game.zone)
npc.store:interact(player)
end},
{"Sorry I have to go!"},
}
}
return "start"
......@@ -132,3 +132,21 @@ newEntity{
},
},
}
----------- Lost Merchant
newEntity{
define_as = "LOST_MERCHANT",
name = "rare goods",
display = '7', color=colors.BLUE,
store = {
restock_after = 1000,
empty_before_restock = true,
buy_percent = 10,
sell_percent = 140,
min_fill = 10,
max_fill = 20,
filters = {
{ego_chance=80, id=true, ignore={type="money"}},
},
},
}
......@@ -47,7 +47,7 @@ quickEntity('a', {show_tooltip=true, name="Closed store", display='*', color=col
quickEntity('b', {show_tooltip=true, name="Hall of the King", display='*', color=colors.LIGHT_UMBER, block_move=true, block_sight=true, image="terrain/wood_store_closed.png"})
quickEntity('c', {show_tooltip=true, name="Closed store", display='*', color=colors.LIGHT_UMBER, block_move=true, block_sight=true, image="terrain/wood_store_closed.png"})
quickEntity('d', {show_tooltip=true, name="Closed store", display='*', color=colors.LIGHT_UMBER, block_move=true, block_sight=true, image="terrain/wood_store_closed.png"})
quickEntity('e', {show_tooltip=true, name="Closed store", display='*', color=colors.LIGHT_UMBER, block_move=true, block_sight=true, image="terrain/wood_store_closed.png"})
quickEntity('e', {show_tooltip=true, name="Rare goods", display='*', color=colors.AQUAMARINE, resolvers.store("LOST_MERCHANT"), resolvers.chatfeature("minas-tirith-lost-merchant"), image="terrain/wood_store_weapon.png"})
quickEntity('E', {show_tooltip=true, name="The Elder", display='*', color=colors.VIOLET, resolvers.chatfeature("minas-tirith-elder"), image="terrain/wood_store_closed.png"})
......@@ -84,7 +84,7 @@ return {
[[#^^^########----OOO--#-------OOO--#-StSS--OOOOO-TT-#-----,,#------------O------- ]],
[[#^^############-OOO--##-StSSS-OOO-#-ssss--OOOOO--T-#----,,##---ssssssss-O-------- ]],
[[#^^^#########---OOO---#-sssss-OOO-#-ssss--OOOOOO---#,,,,,##----SSSSStSS-O--------- ]],
[[#^^#########----OOO---#-###6#-OOO-#-####---OOOOOO--#######-----ssssssss-O---------- ]],
[[#^^#########----OOO---#-###6#-OOO-#-##e#---OOOOOO--#######-----ssssssss-O---------- ]],
[[#^^^#######-----OOO---#-------OOO-#---------OOOOOOOOOOOOOOOOO--########-O----------- ]],
[[#^^#######bOOOOOOOO-^^^^^^^^^^MMM^^^^^^^^^^^^OOOOOOOOOOOOOOOOOOOOOOOOOOOO----------- ]],
[[#^^#######bOOOOOOO############III############^OOOOOOOOOOOOOOOOOOOOOOOOOOOOO--------- ]],
......
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