Commit 213f3e29713ac080d51f513353aa5060379923c0

Authored by DarkGod
1 parent 6bc8c76c

Tier 1 zones are now the target of other adventurers! After doing 3 of them you …

…may find out others came to do the rest before you could. (No this will not make you loose escorts)
... ... @@ -60,6 +60,7 @@ function _M:grantQuest(quest, args)
60 60 self.quests[quest.id].gained_turn = game.turn
61 61 print("[QUEST] given to", self, quest.id)
62 62 self:check("on_quest_grant", quest)
  63 + return true
63 64 end
64 65
65 66 --- Sets the status of a quest for an actor
... ...
... ... @@ -1117,6 +1117,19 @@ function _M:changeLevelReal(lev, zone, params)
1117 1117 world:seenZone(self.zone.short_name)
1118 1118 force_recreate = true
1119 1119 elseif not params.temporary_zone_shift then -- We move to a new zone as normal
  1120 + local nztmp = nil
  1121 + if zone then
  1122 + if type(zone) == "string" then
  1123 + nztmp = Zone.new(zone)
  1124 + else
  1125 + nztmp = zone
  1126 + end
  1127 + if nztmp.tier1 and table.count(self.state.tier1_zones_entered or {}) >= 3 then
  1128 + Dialog:simplePopup("Empty place", "It looks like somebody came here first, the place is now empty.")
  1129 + return
  1130 + end
  1131 + end
  1132 +
1120 1133 if self.zone and self.zone.on_leave then
1121 1134 local nl, nz, stop = self.zone.on_leave(lev, old_lev, zone)
1122 1135 if stop then self.change_level_party = nil self.change_level_party_back = nil return end
... ... @@ -1131,11 +1144,7 @@ function _M:changeLevelReal(lev, zone, params)
1131 1144 self.zone:leaveLevel(false, lev, old_lev)
1132 1145 self.zone:leave()
1133 1146 end
1134   - if type(zone) == "string" then
1135   - self.zone = Zone.new(zone)
1136   - else
1137   - self.zone = zone
1138   - end
  1147 + self.zone = nztmp
1139 1148 if self.zone.tier1 then
1140 1149 if lev == 1 and game.state:tier1Killed(game.state.birth.start_tier1_skip or 3) then
1141 1150 self.zone.tier1 = nil
... ... @@ -1406,6 +1415,10 @@ function _M:changeLevelReal(lev, zone, params)
1406 1415 self.change_level_party = nil
1407 1416 self.change_level_party_back = nil
1408 1417
  1418 + if self.zone and self.zone.tier1 then
  1419 + self.state:registerT1ZoneVisit()
  1420 + end
  1421 +
1409 1422 self:dieClonesDie()
1410 1423 end
1411 1424
... ...
... ... @@ -68,6 +68,23 @@ function _M:tier1Killed(nb)
68 68 return self.tier1_done >= nb
69 69 end
70 70
  71 +--- Called each time a T1 level is entered
  72 +function _M:registerT1ZoneVisit()
  73 + self.tier1_zones_entered = self.tier1_zones_entered or {}
  74 + self.tier1_zones_entered[game.zone.short_name] = true
  75 +
  76 + local p = game:getPlayer(true)
  77 + if not p or not p.random_escort_levels then return end
  78 + if self.tier1_escorts_reshuffled then return end
  79 +
  80 + self.tier1_escorts_reshuffled = true
  81 + for _, zone in ipairs{"tier1.1", "tier1.2"} do
  82 + if p.random_escort_levels[zone] and not p.random_escort_levels[zone].seen_zone then
  83 + p:reshuffleEscortsZone(zone)
  84 + end
  85 + end
  86 +end
  87 +
71 88 --- Sets unique as dead
72 89 function _M:registerUniqueDeath(u)
73 90 if u.randboss then return end
... ... @@ -97,6 +114,9 @@ end
97 114
98 115 --- Discovered the far east
99 116 function _M:goneEast()
  117 + if self.birth.on_change_to_advanced then
  118 + self.birth.on_change_to_advanced()
  119 + end
100 120 self.is_advanced = true
101 121 end
102 122
... ... @@ -116,12 +136,11 @@ function _M:canEastPatrol()
116 136 end
117 137
118 138 --- Setup a backup guardian for the given zone
119   -function _M:activateBackupGuardian(guardian, on_level, zonelevel, rumor, action)
  139 +function _M:activateBackupGuardian(guardian, zone, on_level, zonelevel, rumor, action)
120 140 if self.is_advanced then return end
121 141 print("Zone guardian dead, setting up backup guardian", guardian, zonelevel)
122   - self.allow_backup_guardians[game.zone.short_name] =
  142 + self.allow_backup_guardians[zone] =
123 143 {
124   - name = game.zone.name,
125 144 guardian = guardian,
126 145 on_level = on_level,
127 146 new_level = zonelevel,
... ...
... ... @@ -137,6 +137,31 @@ function _M:onBirth(birther)
137 137 self._on_birth = nil
138 138 end
139 139
  140 +function _M:reshuffleEscortsZone(zone)
  141 + -- Make a list of random escort levels
  142 + local birther = require "engine.Birther"
  143 + local race_def = birther.birth_descriptor_def.race[self.descriptor.race]
  144 + local subrace_def = birther.birth_descriptor_def.subrace[self.descriptor.subrace]
  145 + local world = birther.birth_descriptor_def.world[self.descriptor.world]
  146 + local def = subrace_def.random_escort_possibilities or race_def.random_escort_possibilities
  147 + if world.random_escort_possibilities then def = world.random_escort_possibilities end -- World overrides
  148 + if def then
  149 + local zones = {}
  150 + for i, zd in ipairs(def) do if zd[1] ~= "tier1.1" and zd[1] ~= "tier1.2" then
  151 + for j = zd[2], zd[3] do if not self.random_escort_levels[zd[1]] or not self.random_escort_levels[zd[1]][j] then
  152 + zones[#zones+1] = {zd[1], j}
  153 + end end
  154 + end end
  155 + for i, _ in pairs(self.random_escort_levels[zone]) do
  156 + local z = rng.tableRemove(zones)
  157 + print("Random escort on", z[1], z[2])
  158 + self.random_escort_levels[z[1]] = self.random_escort_levels[z[1]] or {}
  159 + self.random_escort_levels[z[1]][z[2]] = true
  160 + end
  161 + self.random_escort_levels[zone] = nil
  162 + end
  163 +end
  164 +
140 165 function _M:onEnterLevel(zone, level)
141 166 -- Save where we entered
142 167 self.entered_level = {x=self.x, y=self.y}
... ... @@ -166,8 +191,11 @@ function _M:onEnterLevel(zone, level)
166 191 end
167 192
168 193 -- Fire random escort quest
169   - if self.random_escort_levels and self.random_escort_levels[escort_zone_name] and self.random_escort_levels[escort_zone_name][level.level - escort_zone_offset] then
170   - self:grantQuest("escort-duty")
  194 + if self.random_escort_levels and self.random_escort_levels[escort_zone_name] then
  195 + self.random_escort_levels[escort_zone_name].seen_zone = true
  196 + if self.random_escort_levels[escort_zone_name][level.level - escort_zone_offset] then
  197 + self:grantQuest("escort-duty")
  198 + end
171 199 end
172 200
173 201 -- Cancel effects
... ...
... ... @@ -64,6 +64,7 @@ function _M:grantQuest(quest, args)
64 64 self.quests[quest.id].gained_turn = game.turn
65 65 print("[QUEST] given to", self, quest.id)
66 66 self:check("on_quest_grant", quest)
  67 + return true
67 68 end
68 69
69 70 --- Sets the status of a quest for an actor
... ...
... ... @@ -89,6 +89,26 @@ newBirthDescriptor{
89 89 local x, y = mod.class.Encounter:findSpot(where)
90 90 return x, y
91 91 end,
  92 + on_change_to_advanced = function()
  93 + game.state:activateBackupGuardian("ALUIN", "trollmire", 1, 35, "... and we thought the trollmire was safer now!")
  94 + game.state:activateBackupGuardian("SPELLBLAZE_SIMULACRUM", "scintillating-caves", 1, 35, "I heard that some old crystals are nearly alive now in the scintillating caves.")
  95 + game.state:activateBackupGuardian("CORRUPTED_SAND_WYRM", "sandworm-lair", 1, 45, "Did you hear? Something seems to have devoured all the last sandworms!", function(gen)
  96 + if gen then return end
  97 + for i = #game.level.e_array, 1, -1 do
  98 + local e = game.level.e_array[i]
  99 + if not e.unique and not e.player then game.level:removeEntity(e) end
  100 + end
  101 + end)
  102 + game.state:activateBackupGuardian("KOR_FURY", "ruins-kor-pul", 1, 35, ".. yes I tell you! The old ruins of Kor'Pul are still haunted!")
  103 + game.state:activateBackupGuardian("LITHFENGEL", "reknor", 4, 35, "They say that after it has been confirmed orcs still inhabited Reknor, they found a mighty demon there.", function(gen)
  104 + if gen then require("engine.ui.Dialog"):simpleLongPopup("Danger...", "When last you saw it, this cavern was littered with the corpses of orcs that you had slain. Now many, many more corpses carpet the floor, all charred and reeking of sulfur. An orange glow dimly illuminates the far reaches of the cavern to the east.", 400) end
  105 + end)
  106 + game.state:activateBackupGuardian("SNAPROOT", "old-forest", 1, 50, "Have you heard, the old forest seems to have been claimed by a new evil!")
  107 + game.state:activateBackupGuardian("NIMISIL", "maze", 1, 40, "Have you hard about the patrol that disappeared in the maze in the west?")
  108 + game.state:activateBackupGuardian("PALE_DRAKE", "dreadfell", 1, 40, "It has been months since the hero cleansed the Dreadfell, yet rumours are growing: evil is back.")
  109 + game.state:activateBackupGuardian("ABOMINATION", "deep-bellow", 1, 35, "I have heard a dwarf whispering about some abomination in the deep bellow.")
  110 + game.state:activateBackupGuardian("MASSOK", "daikara", 1, 43, "I have heard there is a dragon hunter in the Daikara that is unhappy about the wyrm being already dead.")
  111 + end,
92 112 zone_tiers = {
93 113 {name="tier1", "trollmire", "norgos-lair", "scintillating-caves", "rhaloren-camp", "heart-gloom", "ruins-kor-pul"},
94 114 {name="tier2", "sandworm-lair", "old-forest", "maze", "daikara", "halfling-ruins"},
... ...
... ... @@ -333,6 +333,7 @@ local function getPortalSpot(npc, dist, min_dist)
333 333 end
334 334
335 335 on_grant = function(self, who)
  336 +-- do return true end
336 337 local x, y = util.findFreeGrid(who.x, who.y, 10, true, {[engine.Map.ACTOR]=true})
337 338 if not x then return true end
338 339
... ...
... ... @@ -83,7 +83,6 @@ newEntity{ define_as = "RANTHA_THE_WORM",
83 83 resolvers.inscriptions(1, "infusion"),
84 84
85 85 on_die = function(self, who)
86   - game.state:activateBackupGuardian("MASSOK", 4, 43, "I have heard there is a dragon hunter in the Daikara that is unhappy about the wyrm being already dead.")
87 86 game.player:resolveSource():grantQuest("starter-zones")
88 87 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "daikara")
89 88
... ... @@ -146,7 +145,6 @@ newEntity{ define_as = "VARSHA_THE_WRITHING",
146 145 resolvers.inscriptions(1, "infusion"),
147 146
148 147 on_die = function(self, who)
149   - game.state:activateBackupGuardian("MASSOK", 4, 43, "I have heard there is a dragon hunter in the Daikara that is unhappy about the wyrm being already dead.")
150 148 game.player:resolveSource():grantQuest("starter-zones")
151 149 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "daikara")
152 150 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "daikara-volcano")
... ...
... ... @@ -80,7 +80,6 @@ newEntity{ base="BASE_NPC_CORRUPTED_HORROR", define_as = "THE_MOUTH",
80 80
81 81 on_die = function(self, who)
82 82 game.player:resolveSource():setQuestStatus("deep-bellow", engine.Quest.COMPLETED)
83   - game.state:activateBackupGuardian("ABOMINATION", 3, 35, "I have heard a dwarf whispering about some abomination in the deep bellow.")
84 83
85 84 if game:getPlayer(true).female then
86 85 game:setAllowedBuild("cosmetic_race_dwarf_female_beard", true)
... ...
... ... @@ -113,8 +113,6 @@ newEntity{ define_as = "THE_MASTER",
113 113 resolvers.inscriptions(1, {"manasurge rune"}),
114 114
115 115 on_die = function(self, who)
116   - game.state:activateBackupGuardian("PALE_DRAKE", 1, 40, "It has been months since the hero cleansed the Dreadfell, yet rumours are growing: evil is back.")
117   -
118 116 world:gainAchievement("VAMPIRE_CRUSHER", game.player:resolveSource())
119 117 game.player:resolveSource():grantQuest("dreadfell")
120 118 game.player:resolveSource():setQuestStatus("dreadfell", engine.Quest.COMPLETED)
... ...
... ... @@ -90,7 +90,6 @@ newEntity{ define_as = "HORNED_HORROR",
90 90 resolvers.inscriptions(1, {"invisibility rune"}),
91 91
92 92 on_die = function(self, who)
93   - game.state:activateBackupGuardian("NIMISIL", 2, 40, "Have you hard about the patrol that disappeared in the maze in the west?")
94 93 game.player:resolveSource():grantQuest("starter-zones")
95 94 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "maze")
96 95 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "maze-horror")
... ... @@ -143,7 +142,6 @@ newEntity{ define_as = "MINOTAUR_MAZE",
143 142 resolvers.inscriptions(2, "infusion"),
144 143
145 144 on_die = function(self, who)
146   - game.state:activateBackupGuardian("NIMISIL", 2, 40, "Have you hard about the patrol that disappeared in the maze in the west?")
147 145 game.player:resolveSource():grantQuest("starter-zones")
148 146 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "maze")
149 147 end,
... ...
... ... @@ -82,7 +82,6 @@ newEntity{ define_as = "SHARDSKIN",
82 82 resolvers.inscriptions(1, "rune"),
83 83
84 84 on_die = function(self, who)
85   - game.state:activateBackupGuardian("SNAPROOT", 3, 50, "Have you heard, the old forest seems to have been claimed by a new evil!")
86 85 game.player:resolveSource():grantQuest("starter-zones")
87 86 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "old-forest")
88 87 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "old-forest-crystal")
... ... @@ -133,7 +132,6 @@ newEntity{ define_as = "WRATHROOT",
133 132 resolvers.inscriptions(1, "infusion"),
134 133
135 134 on_die = function(self, who)
136   - game.state:activateBackupGuardian("SNAPROOT", 3, 50, "Have you heard, the old forest seems to have been claimed by a new evil!")
137 135 game.player:resolveSource():grantQuest("starter-zones")
138 136 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "old-forest")
139 137 end,
... ...
... ... @@ -99,10 +99,6 @@ newEntity{ define_as = "GOLBUG",
99 99 end,
100 100
101 101 on_die = function(self, who)
102   - game.state:activateBackupGuardian("LITHFENGEL", 4, 35, "They say that after it has been confirmed orcs still inhabited Reknor, they found a mighty demon there.", function(gen)
103   - if gen then require("engine.ui.Dialog"):simpleLongPopup("Danger...", "When last you saw it, this cavern was littered with the corpses of orcs that you had slain. Now many, many more corpses carpet the floor, all charred and reeking of sulfur. An orange glow dimly illuminates the far reaches of the cavern to the east.", 400) end
104   - end)
105   -
106 102 world:gainAchievement("DESTROYER_BANE", game.player:resolveSource())
107 103 game.player:setQuestStatus("orc-hunt", engine.Quest.DONE)
108 104 game.player:grantQuest("wild-wild-east")
... ...
... ... @@ -85,7 +85,6 @@ newEntity{ define_as = "SHADE",
85 85 low_level_tactics_override = {escape=0, safe_range=1},
86 86
87 87 on_die = function(self, who)
88   - game.state:activateBackupGuardian("KOR_FURY", 3, 35, ".. yes I tell you! The old ruins of Kor'Pul are still haunted!")
89 88 game.player:resolveSource():setQuestStatus("start-allied", engine.Quest.COMPLETED, "kor-pul")
90 89 end,
91 90 }
... ... @@ -129,7 +128,6 @@ newEntity{ base = "BASE_NPC_THIEF", define_as = "THE_POSSESSED",
129 128 low_level_tactics_override = {escape=0, safe_range=1},
130 129
131 130 on_die = function(self, who)
132   - game.state:activateBackupGuardian("KOR_FURY", 3, 35, ".. yes I tell you! The old ruins of Kor'Pul are still haunted!")
133 131 game.player:resolveSource():setQuestStatus("start-allied", engine.Quest.COMPLETED, "kor-pul")
134 132 game.player:resolveSource():setQuestStatus("start-allied", engine.Quest.COMPLETED, "kor-pul-invaded")
135 133 end,
... ...
... ... @@ -157,13 +157,6 @@ newEntity{ define_as = "SANDWORM_QUEEN",
157 157 end,
158 158
159 159 on_die = function(self, who)
160   - game.state:activateBackupGuardian("CORRUPTED_SAND_WYRM", 1, 45, "Did you hear? Something seems to have devoured all the last sandworms!", function(gen)
161   - if gen then return end
162   - for i = #game.level.e_array, 1, -1 do
163   - local e = game.level.e_array[i]
164   - if not e.unique and not e.player then game.level:removeEntity(e) end
165   - end
166   - end)
167 160 game.player:resolveSource():grantQuest("starter-zones")
168 161 game.player:resolveSource():setQuestStatus("starter-zones", engine.Quest.COMPLETED, "sandworm-lair")
169 162 end,
... ...
... ... @@ -65,7 +65,6 @@ newEntity{ base="BASE_NPC_CRYSTAL", define_as = "SPELLBLAZE_CRYSTAL",
65 65
66 66 on_die = function(self, who)
67 67 game.player:resolveSource():setQuestStatus("start-shaloren", engine.Quest.COMPLETED, "spellblaze")
68   - game.state:activateBackupGuardian("SPELLBLAZE_SIMULACRUM", 3, 35, "I heard that some old crystals are nearly alive now in the scintillating caves.")
69 68 end,
70 69 }
71 70
... ...
... ... @@ -104,7 +104,6 @@ newEntity{ define_as = "TROLL_PROX",
104 104 game.zone:addEntity(game.level, n, "object", self.x, self.y)
105 105 end
106 106 end
107   - game.state:activateBackupGuardian("ALUIN", 2, 35, "... and we thought the trollmire was safer now!")
108 107 game.player:resolveSource():setQuestStatus("start-allied", engine.Quest.COMPLETED, "trollmire")
109 108 end,
110 109 }
... ... @@ -170,7 +169,6 @@ newEntity{ define_as = "TROLL_SHAX",
170 169 game.zone:addEntity(game.level, n, "object", self.x, self.y)
171 170 end
172 171 end
173   - game.state:activateBackupGuardian("ALUIN", 2, 35, "... and we thought the trollmire was safer now!")
174 172 game.player:resolveSource():setQuestStatus("start-allied", engine.Quest.COMPLETED, "trollmire")
175 173 game.player:resolveSource():setQuestStatus("start-allied", engine.Quest.COMPLETED, "trollmire-flooded")
176 174 end,
... ...