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

questing

git-svn-id: http://svn.net-core.org/repos/t-engine4@572 51575b47-30f0-44d4-a5cc-537603b46e54
parent 9e78091b
No related branches found
No related tags found
No related merge requests found
......@@ -156,8 +156,8 @@ end
-- This helps ensuring uniqueness of uniques
function _M:added()
if self.unique then
game.uniques[self.unique] = true
print("Added unique", self.unique)
game.uniques[self.__CLASSNAME.."/"..self.unique] = true
print("Added unique", self.__CLASSNAME.."/"..self.unique)
end
end
......@@ -174,8 +174,8 @@ function _M:removed()
end
if self.unique then
game.uniques[self.unique] = nil
print("Removed unique", self.unique)
game.uniques[self.__CLASSNAME.."/"..self.unique] = nil
print("Removed unique", self.__CLASSNAME.."/"..self.unique)
end
end
......
......@@ -123,7 +123,7 @@ end
--- Checks an entity against a filter
function _M:checkFilter(e, filter)
if e.unique and game.uniques[e.unique] then print("refused unique", e.name, e.unique) return false end
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
print("Filtering", filter.type, filter.subtype)
......@@ -131,8 +131,9 @@ function _M:checkFilter(e, filter)
if filter.type and filter.type ~= e.type then return false end
if filter.subtype and filter.subtype ~= e.subtype then return false end
if filter.name and filter.name ~= e.name then return false end
if e.checkFilter and not e:checkFilter(filter) then return end
if e.unique then print("accepted unique", e.name, e.unique) end
if e.unique then print("accepted unique", e.name, e.__CLASSNAME.."/"..e.unique) end
return true
end
......@@ -171,7 +172,7 @@ function _M:makeEntity(level, type, filter)
local list = level:getEntitiesList(type)
local e
local tries = 500
local tries = filter and filter.nb_tries or 500
-- CRUDE ! Brute force ! Make me smarter !
while tries > 0 do
e = self:pickEntity(list)
......@@ -198,7 +199,7 @@ function _M:makeEntityByName(level, type, name)
end
if not e then return nil end
if e.unique and game.uniques[e.unique] then print("refused unique", e.name, e.unique) return nil end
if e.unique and game.uniques[e.__CLASSNAME.."/"..e.unique] then print("refused unique", e.name, e.__CLASSNAME.."/"..e.unique) return nil end
e = self:finishEntity(level, type, e)
......
......@@ -62,7 +62,7 @@ end
--- Checks if the actor has this quest
function _M:hasQuest(id)
if not self.quests then return false end
return self.quests[id] and true or false
return self.quests[id]
end
--- Checks the status of the given quest
......
......@@ -28,5 +28,52 @@ function _M:init(t, no_default)
assert(t.on_encounter, "no encounter on_encounter")
engine.Entity.init(self, t, no_default)
self:parseCoords()
end
function _M:parseCoords()
self.on_map = {}
for i, coord in ipairs(self.coords) do
if coord.likelymap then
for y, line in ipairs(coord.likelymap) do
local i = 1
for c in line:gmatch(".") do
if c ~= ' ' then
self.on_map[(coord.x+i-1).."x"..(coord.y+y-1)] = tonumber(c)
print("coords", (coord.x+i-1).."x"..(coord.y+y-1), tonumber(c))
end
i = i + 1
end
end
elseif coord.w and coord.h then
for y = 1, coord.h do
for i = 1, coord.w do
self.on_map[(coord.x+i-1).."x"..(coord.y+y-1)] = 1
end
end
end
end
end
function _M:checkFilter(filter)
if filter.mapx and filter.mapy then
return self.on_map[filter.mapx.."x"..filter.mapy]
else
return true
end
end
function _M:findSpot(who, what)
what = what or "block_move"
local spots = {}
for i = -1, 1 do for j = -1, 1 do if i ~= 0 or j ~= 0 then
if not game.level.map:checkAllEntities(who.x + i, who.y + j, what, who) then
spots[#spots+1] = {who.x + i, who.y + j}
end
end end end
if #spots > 0 then
local s = rng.table(spots)
return s[1], s[2]
end
end
......@@ -99,6 +99,16 @@ function _M:move(x, y, force)
-- Update wilderness coords
if game.zone.short_name == "wilderness" then
self.wild_x, self.wild_y = self.x, self.y
local g = game.level.map(self.x, self.y, Map.TERRAIN)
if g and g.can_encounter then
local e = game.zone:makeEntity(game.level, "encounters", {mapx=self.x, mapy=self.y, nb_tries=10})
if e then
print("Made encounter:", e.name)
if e:check("on_encounter", self) then
e:added()
end
end
end
end
return moved
......
......@@ -21,8 +21,9 @@ newChat{ id="welcome",
text = [[#LIGHT_GREEN#*Before you stands a young man, a novice mage by his looks*#WHITE#
Good day to you fellow traveller!]],
answers = {
{"What brings an apprentice mage in the wilds?", cond=function(npc, player) return not player:hasQuest("mage-apprentice") end, jump="quest"},
{"Do you have any items to sell?", jump="store"},
{"What brings an apprentice mage in the wilds?", jump="quest", cond=function(npc, player) return not player:hasQuest("mage-apprentice") end},
{"I have a staff for you!", jump="offer", cond=function(npc, player) return player:hasQuest("mage-apprentice") and player:hasQuest("mage-apprentice"):can_offer(player) end},
-- {"Do you have any items to sell?", jump="store"},
{"Sorry I have to go!"},
}
}
......@@ -51,4 +52,11 @@ Anyway, I must collect 15 magic staves and I have yet to find one. If you could
}
}
newChat{ id="offer",
text = [[Thank you!]],
answers = {
{"Bye!"},
}
}
return "welcome"
......@@ -19,9 +19,10 @@
newEntity{
name = "Novice mage",
type = "harmless", subtype = "quest", unique = true,
level_range = {1, 10},
rarity = 4,
coords = {{ x=23, y=10, likelymap={
coords = {{ x=10, y=23, likelymap={
[[ 11111111 ]],
[[ 1111122222211 ]],
[[111111222222111]],
......@@ -34,7 +35,31 @@ newEntity{
[[ 1111111111111 ]],
[[ 111111111 ]],
}}},
-- Spawn the novice mage near the player
on_encounter = function(self, who)
local x, y = self:findSpot(who)
if not x then return end
local g = mod.class.NPC.new{
name="Novice mage",
type="humanoid", subtype="elf", faction="players",
display='@', color=colors.RED,
can_talk = "mage-apprentice-quest",
}
g:resolve() g:resolve(nil, true)
game.zone:addEntity(game.level, g, "actor", x, y)
return true
end,
}
newEntity{
name = "Lost merchant",
type = "harmless", subtype = "quest", unique = true,
level_range = {10, 20},
rarity = 4,
coords = {{ x=0, y=0, w=40, h=40}},
on_encounter = function(self, who)
return true
end,
}
......@@ -29,20 +29,20 @@ quickEntity('t', {show_tooltip=true, name='forest', display='#', color=colors.LI
quickEntity('v', {show_tooltip=true, name='old forest', display='#', color=colors.GREEN, image="terrain/tree_dark1.png", block_move=true})
quickEntity('i', {show_tooltip=true, name='iron mountains', display='^', color=colors.SLATE, image="terrain/mountain.png", block_move=true})
quickEntity('=', {show_tooltip=true, name='the great sea', display='~', color=colors.BLUE, image="terrain/river.png", block_move=true})
quickEntity('.', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", equilibrium_level=-10})
quickEntity('g', {show_tooltip=true, name='Forodwaith, the cold lands', display='.', color=colors.LIGHT_BLUE, equilibrium_level=-10})
quickEntity('q', {show_tooltip=true, name='Icebay of Forochel', display=';', color=colors.LIGHT_BLUE, equilibrium_level=-10})
quickEntity('w', {show_tooltip=true, name='ash', display='.', color=colors.WHITE, image="terrain/ash1.png"})
quickEntity('&', {show_tooltip=true, name='hills', display='^', color=colors.GREEN, image="terrain/hills.png", equilibrium_level=-10})
quickEntity('h', {show_tooltip=true, name='low hills', display='^', color=colors.GREEN, image="terrain/hills.png", equilibrium_level=-10})
quickEntity('.', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", can_encounter=true, equilibrium_level=-10})
quickEntity('g', {show_tooltip=true, name='Forodwaith, the cold lands', display='.', color=colors.LIGHT_BLUE, can_encounter=true, equilibrium_level=-10})
quickEntity('q', {show_tooltip=true, name='Icebay of Forochel', display=';', color=colors.LIGHT_BLUE, can_encounter=true, equilibrium_level=-10})
quickEntity('w', {show_tooltip=true, name='ash', display='.', color=colors.WHITE, image="terrain/ash1.png", can_encounter=true})
quickEntity('&', {show_tooltip=true, name='hills', display='^', color=colors.GREEN, image="terrain/hills.png", can_encounter=true, equilibrium_level=-10})
quickEntity('h', {show_tooltip=true, name='low hills', display='^', color=colors.GREEN, image="terrain/hills.png", can_encounter=true, equilibrium_level=-10})
quickEntity(' ', {show_tooltip=true, name='sea of Rhun', display='~', color=colors.BLUE, image="terrain/river.png", block_move=true})
quickEntity('_', {show_tooltip=true, name='river', display='~', color={r=0, g=80, b=255}, image="terrain/river.png", equilibrium_level=-10})
quickEntity('~', {show_tooltip=true, name='Anduin river', display='~', color={r=0, g=30, b=255}, image="terrain/river.png", equilibrium_level=-10})
quickEntity('-', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", equilibrium_level=-10})
quickEntity('|', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", equilibrium_level=-10})
quickEntity('x', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", equilibrium_level=-10})
quickEntity('s', {show_tooltip=true, name='dead marches', display='~', color=colors.DARK_GREEN, })
quickEntity('"', {show_tooltip=true, name='the valley of Nurn', display='.', color=colors.WHITE, image="terrain/ash1.png"})
quickEntity('_', {show_tooltip=true, name='river', display='~', color={r=0, g=80, b=255}, image="terrain/river.png", can_encounter=true, equilibrium_level=-10})
quickEntity('~', {show_tooltip=true, name='Anduin river', display='~', color={r=0, g=30, b=255}, image="terrain/river.png", can_encounter=true, equilibrium_level=-10})
quickEntity('-', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", can_encounter=true, equilibrium_level=-10})
quickEntity('|', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", can_encounter=true, equilibrium_level=-10})
quickEntity('x', {show_tooltip=true, name='plains', display='.', color=colors.LIGHT_GREEN, image="terrain/grass.png", can_encounter=true, equilibrium_level=-10})
quickEntity('s', {show_tooltip=true, name='dead marches', display='~', color=colors.DARK_GREEN, can_encounter=true})
quickEntity('"', {show_tooltip=true, name='the valley of Nurn', display='.', color=colors.WHITE, image="terrain/ash1.png", can_encounter=true})
quickEntity('A', {show_tooltip=true, name="Caves below the tower of Amon Sûl", display='>', color={r=0, g=255, b=255}, notice = true, change_level=1, change_zone="tower-amon-sul"})
quickEntity('B', {show_tooltip=true, name="Passageway into the Trollshaws", display='>', color={r=0, g=255, b=0}, notice = true, change_level=1, change_zone="trollshaws"})
......
......@@ -42,3 +42,11 @@ collect_staff = function(self, who, o)
self.nb_collect = self.nb_collect + 1
if self.nb_collect > 15 then who:setQuestStatus(self, self.COMPLETED) end
end
can_offer = function(self, who)
for inven_id, inven in pairs(who.inven) do
for item, o in ipairs(inven) do
if o.type == "weapon" and o.subtype == "staff" then return true end
end
end
end
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