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

more achievements

git-svn-id: http://svn.net-core.org/repos/t-engine4@498 51575b47-30f0-44d4-a5cc-537603b46e54
parent e5bd5ebb
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@ function _M:defaultSavedFields(t)
w=true, h=true, zone=true, player=true, level=true, entities=true,
energy_to_act=true, energy_per_tick=true, turn=true, paused=true, save_name=true,
always_target=true, gfxmode=true, uniques=true, object_known_types=true,
current_music=true, memory_levels=true,
current_music=true, memory_levels=true, achievement_data=true,
}
table.merge(def, t)
return def
......
......@@ -44,6 +44,7 @@ function _M:newAchievement(t)
assert(t.name, "no achivement name")
assert(t.desc, "no achivement desc")
t.mode = t.mode or "none"
t.id = t.id or t.name
t.id = t.id:upper():gsub("[ ]", "_")
t.order = #self.achiev_defs+1
......@@ -64,14 +65,32 @@ end
--- Gain an achievement
-- @param id the achivement to gain
-- @param src who did it
function _M:gainAchievement(id, src)
if not self.achiev_defs[id] then error("Unknown achievement "..id) return end
if self.achiev_defs[id].can_gain and not self.achiev_defs[id].can_gain(src) then return end
function _M:gainAchievement(id, src, ...)
local a = self.achiev_defs[id]
if not a then error("Unknown achievement "..id) return end
if self.achieved[id] then return end
if a.can_gain then
local data = nil
if a.mode == "world" then
self.achievement_data = self.achievement_data or {}
self.achievement_data[id] = self.achievement_data[id] or {}
data = self.achievement_data[id]
elseif a.mode == "game" then
game.achievement_data = game.achievement_data or {}
game.achievement_data[id] = game.achievement_data[id] or {}
data = game.achievement_data[id]
elseif a.mode == "player" then
src.achievement_data = src.achievement_data or {}
src.achievement_data[id] = src.achievement_data[id] or {}
data = src.achievement_data[id]
end
if not a.can_gain(data, src, ...) then return end
end
self.achieved[id] = {turn=game.turn, who=self:achievementWho(src), when=os.date("%Y-%m-%d %H:%M:%S")}
game.log("#LIGHT_GREEN#New Achievement: %s!", self.achiev_defs[id].name)
Dialog:simplePopup("New Achievement: #LIGHT_GREEN#"..self.achiev_defs[id].name, self.achiev_defs[id].desc)
game.log("#LIGHT_GREEN#New Achievement: %s!", a.name)
Dialog:simplePopup("New Achievement: #LIGHT_GREEN#"..a.name, a.desc)
end
--- Format an achievement source
......
......@@ -363,8 +363,9 @@ function _M:die(src)
end
-- Achievements
if src and src:resolveSource().player and src:resolveSource().life == 1 then
world:gainAchievement("THAT_WAS_CLOSE", src:resolveSource())
if src and src:resolveSource().player then
if src:resolveSource().life == 1 then world:gainAchievement("THAT_WAS_CLOSE", src:resolveSource()) end
world:gainAchievement("PEST_CONTROL", src:resolveSource(), self)
end
return true
......@@ -461,6 +462,11 @@ function _M:onAddObject(o)
engine.interface.ActorInventory.onAddObject(self, o)
self:checkEncumbrance()
-- Achievement checks
if self.player then
world:gainAchievement("DEUX_EX_MACHINA", self, o)
end
end
--- Call when an object is removed
......
-- 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
newAchievement{
name = "Deux Ex Machina",
desc = [[Found both ever-refilling potions.]],
mode = "player",
can_gain = function(self, who, obj)
if obj:getName{force_id=true} == "Ever Refilling Potion of Mana" then self.mana = true end
if obj:getName{force_id=true} == "Ever Refilling Potion of Healing" then self.life = true end
return self.mana and self.life
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
newAchievement{
name = "That was close",
desc = [[Kill your target while having only 1 life left.]],
}
newAchievement{
name = "Size matters",
desc = [[Do over 600 damage in one attack]],
}
newAchievement{
name = "Exterminator",
desc = [[Killed 1000 creatures]],
mode = "player",
can_gain = function(self, who)
self.nb = (self.nb or 0) + 1
if self.nb >= 1000 then return true end
end
}
newAchievement{
name = "Pest Control",
desc = [[Killed 1000 reproducing vermins]],
mode = "player",
can_gain = function(self, who, target)
if target:hasTalent(target.T_MULTIPLY) then
self.nb = (self.nb or 0) + 1
if self.nb >= 1000 then return true end
end
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
newAchievement{
name = "Level 10",
desc = [[Got a character to level 10.]],
}
newAchievement{
name = "Level 20",
desc = [[Got a character to level 20.]],
}
newAchievement{
name = "Level 30",
desc = [[Got a character to level 30.]],
}
newAchievement{
name = "Level 40",
desc = [[Got a character to level 40.]],
}
newAchievement{
name = "Level 50",
desc = [[Got a character to level 50.]],
}
newAchievement{
name = "Unstoppable",
desc = [[Has returned from the dead.]],
}
......@@ -106,6 +106,8 @@ function _M:resurrectBasic()
game.level:addEntity(self.actor)
game:unregisterDialog(self)
game.level.map:redisplay()
world:gainAchievement("UNSTOPPABLE", self.actor)
end
function _M:use()
......
......@@ -59,8 +59,8 @@ function _M:init(actor, on_finish)
ACCEPT = "EXIT",
EXIT = function() game:unregisterDialog(self)
-- Achievements checks
world:gainAchievement("ELEMENTALIST", self)
world:gainAchievement("WARPER", self)
world:gainAchievement("ELEMENTALIST", self.actor)
world:gainAchievement("WARPER", self.actor)
if on_finish then on_finish() 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