From fa767f0202da5d8c016a003044d2bc3a8a7763a5 Mon Sep 17 00:00:00 2001 From: DarkGod <darkgod@net-core.org> Date: Thu, 17 Oct 2013 12:37:25 +0200 Subject: [PATCH] New achievements for Normal (Roguelike), Nightmare/Insane/Madness (Adventure) Achievements list onyl shows the ones for the current difficulty to reduce clutter --- game/modules/tome/class/Game.lua | 2 +- game/modules/tome/class/World.lua | 4 + .../class/interface/WorldAchievements.lua | 57 ++++++++++++- .../modules/tome/dialogs/ShowAchievements.lua | 79 +++++++++++++++++++ 4 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 game/modules/tome/dialogs/ShowAchievements.lua diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index 16d4a47d4b..26fb61a1f1 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -1656,7 +1656,7 @@ do return end local menu local l = { "resume", - "achievements", + { "Show Achievements", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.ShowAchievements").new("Tales of Maj'Eyal Achievements", self.player)) end }, { "Show known Lore", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.ShowLore").new("Tales of Maj'Eyal Lore", self.party)) end }, { "Show ingredients", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.ShowIngredients").new(self.party)) end }, "highscores", diff --git a/game/modules/tome/class/World.lua b/game/modules/tome/class/World.lua index a28fc511d5..8c5705c71e 100644 --- a/game/modules/tome/class/World.lua +++ b/game/modules/tome/class/World.lua @@ -55,8 +55,12 @@ function _M:gainAchievement(id, src, ...) if game.difficulty == game.DIFFICULTY_EASY and not a.tutorial then return end if game.permadeath == game.PERMADEATH_INFINITE then id = "EXPLORATION_"..id end + if game.difficulty == game.DIFFICULTY_NORMAL and game.permadeath == game.PERMADEATH_ONE then id = "NORMAL_ROGUELIKE_"..id end + if game.difficulty == game.DIFFICULTY_NIGHTMARE and game.permadeath == game.PERMADEATH_MANY then id = "NIGHTMARE_ADVENTURE_".. id end if game.difficulty == game.DIFFICULTY_NIGHTMARE and game.permadeath == game.PERMADEATH_ONE then id = "NIGHTMARE_"..id end + if game.difficulty == game.DIFFICULTY_INSANE and game.permadeath == game.PERMADEATH_MANY then id = "INSANE_ADVENTURE_"..id end if game.difficulty == game.DIFFICULTY_INSANE and game.permadeath == game.PERMADEATH_ONE then id = "INSANE_"..id end + if game.difficulty == game.DIFFICULTY_MADNESS and game.permadeath == game.PERMADEATH_MANY then id = "MADNESS_ADVENTURE_"..id end if game.difficulty == game.DIFFICULTY_MADNESS and game.permadeath == game.PERMADEATH_ONE then id = "MADNESS_"..id end local knew = self.achieved[id] diff --git a/game/modules/tome/class/interface/WorldAchievements.lua b/game/modules/tome/class/interface/WorldAchievements.lua index 01a1acf863..fd04d26f6c 100644 --- a/game/modules/tome/class/interface/WorldAchievements.lua +++ b/game/modules/tome/class/interface/WorldAchievements.lua @@ -23,6 +23,17 @@ local WA = require "engine.interface.WorldAchievements" --- Handles achievements in a world module(..., package.seeall, class.inherit(class.make{}, WA)) +-- Duplicate from Game.lua because Game.lua is not loaded yet +local DIFFICULTY_EASY = 1 +local DIFFICULTY_NORMAL = 2 +local DIFFICULTY_NIGHTMARE = 3 +local DIFFICULTY_INSANE = 4 +local DIFFICULTY_MADNESS = 5 +local PERMADEATH_INFINITE = 1 +local PERMADEATH_MANY = 2 +local PERMADEATH_ONE = 3 + + --- Make a new achievement with a name and desc function _M:newAchievement(t) t.id = t.id or t.name @@ -31,24 +42,64 @@ function _M:newAchievement(t) WA.newAchievement(self, t) if not t.no_difficulty_duplicate then + -- Normal + local t2 = table.clone(t) + t2.id = "NORMAL_ROGUELIKE_"..t2.id + t2.name = t2.name.." (Roguelike)" + t2.difficulty = DIFFICULTY_NORMAL + t2.permadeath = PERMADEATH_ONE + WA.newAchievement(self, t2) + + -- Exploration local t2 = table.clone(t) t2.id = "EXPLORATION_"..t2.id t2.name = t2.name.." (Exploration mode)" + t2.permadeath = PERMADEATH_INFINITE + WA.newAchievement(self, t2) + + -- Nightmare + local t2 = table.clone(t) + t2.id = "NIGHTMARE_ADVENTURE_"..t2.id + t2.name = t2.name.." (Nightmare (Adventure) difficulty)" + t2.difficulty = DIFFICULTY_NIGHTMARE + t2.permadeath = PERMADEATH_MANY WA.newAchievement(self, t2) local t2 = table.clone(t) t2.id = "NIGHTMARE_"..t2.id - t2.name = t2.name.." (Nightmare difficulty)" + t2.name = t2.name.." (Nightmare (Roguelike) difficulty)" + t2.difficulty = DIFFICULTY_NIGHTMARE + t2.permadeath = PERMADEATH_ONE + WA.newAchievement(self, t2) + + -- Insane + local t2 = table.clone(t) + t2.id = "INSANE_ADVENTURE_"..t2.id + t2.name = t2.name.." (Insane (Adventure) difficulty)" + t2.difficulty = DIFFICULTY_INSANE + t2.permadeath = PERMADEATH_MANY WA.newAchievement(self, t2) local t2 = table.clone(t) t2.id = "INSANE_"..t2.id - t2.name = t2.name.." (Insane difficulty)" + t2.name = t2.name.." (Insane (Roguelike) difficulty)" + t2.difficulty = DIFFICULTY_INSANE + t2.permadeath = PERMADEATH_ONE + WA.newAchievement(self, t2) + + -- Madness + local t2 = table.clone(t) + t2.id = "MADNESS_ADVENTURE_"..t2.id + t2.name = t2.name.." (Madness (Adventure) difficulty)" + t2.difficulty = DIFFICULTY_MADNESS + t2.permadeath = PERMADEATH_MANY WA.newAchievement(self, t2) local t2 = table.clone(t) t2.id = "MADNESS_"..t2.id - t2.name = t2.name.." (Madness difficulty)" + t2.name = t2.name.." (Madness (Roguelike) difficulty)" + t2.difficulty = DIFFICULTY_MADNESS + t2.permadeath = PERMADEATH_ONE WA.newAchievement(self, t2) end end diff --git a/game/modules/tome/dialogs/ShowAchievements.lua b/game/modules/tome/dialogs/ShowAchievements.lua new file mode 100644 index 0000000000..2f7218bd12 --- /dev/null +++ b/game/modules/tome/dialogs/ShowAchievements.lua @@ -0,0 +1,79 @@ +-- TE4 - T-Engine 4 +-- Copyright (C) 2009, 2010, 2011, 2012, 2013 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 + +require "engine.class" +local Tiles = require "engine.Tiles" +local ShowAchievements = require "engine.dialogs.ShowAchievements" + +module(..., package.seeall, class.inherit(ShowAchievements)) + +function _M:generateList(kind) + local tiles = Tiles.new(16, 16, nil, nil, true) + local cache = {} + + -- Makes up the list + local list = {} + local i = 0 + local function handle(id, data) + local a = world:getAchievementFromId(id) + local color = nil + if self.player and self.player.achievements and self.player.achievements[id] then + color = colors.simple(colors.LIGHT_GREEN) + end + local img = a.image or "trophy_gold.png" + local tex = cache[img] + if not tex then + local image = tiles:loadImage(img) + if image then + tex = {image:glTexture()} + cache[img] = tex + end + end + if not data.notdone or a.show then + if a.show == "full" or not data.notdone then + list[#list+1] = { name=a.name, color=color, desc=a.desc, when=data.when, who=data.who, order=a.order, id=id, tex=tex, a=a } + elseif a.show == "none" then + list[#list+1] = { name="???", color=color, desc="-- Unknown --", when=data.when, who=data.who, order=a.order, id=id, tex=tex, a=a } + elseif a.show == "name" then + list[#list+1] = { name=a.name, color=color, desc="-- Unknown --", when=data.when, who=data.who, order=a.order, id=id, tex=tex, a=a } + else + list[#list+1] = { name=a.name, color=color, desc=a.desc, when=data.when, who=data.who, order=a.order, id=id, tex=tex, a=a } + end + i = i + 1 + end + end + if kind == "self" and self.player and self.player.achievements then + for id, data in pairs(self.player.achievements) do handle(id, world.achieved[id] or {notdone=true, when="--", who="--"}) end + elseif kind == "main" then + for id, data in pairs(world.achieved) do + local a = world.achiev_defs[id] + if a.no_difficulty_duplicate or ((a.difficulty or a.permadeath) and (not a.difficulty or a.difficulty == game.difficulty) and (not a.permadeath or a.permadeath == game.permadeath)) then + handle(id, data or {notdone=true, when="--", who="--"}) + end + end + elseif kind == "all" then + for _, a in ipairs(world.achiev_defs) do + if a.no_difficulty_duplicate or ((a.difficulty or a.permadeath) and (not a.difficulty or a.difficulty == game.difficulty) and (not a.permadeath or a.permadeath == game.permadeath)) then + handle(a.id, world.achieved[a.id] or {notdone=true, when="--", who="--"}) + end + end + end + table.sort(list, function(a, b) return a.name < b.name end) + self.list = list +end -- GitLab