From 0be85415ed0fa4f10989a6c4fccb097afcd84e10 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 29 Sep 2010 12:11:52 +0000
Subject: [PATCH] Added Tutorial mode

git-svn-id: http://svn.net-core.org/repos/t-engine4@1327 51575b47-30f0-44d4-a5cc-537603b46e54
---
 .../class/interface/WorldAchievements.lua     | 18 ++++----
 .../modules/tome/data/achievements/quests.lua |  6 ++-
 .../tome/data/maps/tutorial/tutorial1.lua     | 44 ++++++++++---------
 game/modules/tome/data/quests/tutorial.lua    |  7 +++
 .../modules/tome/data/texts/tutorial/done.lua | 31 +++++++++++++
 .../tome/data/texts/tutorial/quests.lua       | 29 ++++++++++++
 .../modules/tome/data/zones/tutorial/npcs.lua | 39 +++++++++++++++-
 .../tome/data/zones/tutorial/traps.lua        |  5 +++
 8 files changed, 148 insertions(+), 31 deletions(-)
 create mode 100644 game/modules/tome/data/texts/tutorial/done.lua
 create mode 100644 game/modules/tome/data/texts/tutorial/quests.lua

diff --git a/game/modules/tome/class/interface/WorldAchievements.lua b/game/modules/tome/class/interface/WorldAchievements.lua
index d8daf0b83e..1e8795af7c 100644
--- a/game/modules/tome/class/interface/WorldAchievements.lua
+++ b/game/modules/tome/class/interface/WorldAchievements.lua
@@ -31,13 +31,15 @@ function _M:newAchievement(t)
 
 	WA.newAchievement(self, t)
 
-	local t2 = table.clone(t)
-	t2.id = "NIGHTMARE_"..t2.id
-	t2.name = t2.name.." (Nightmare difficulty)"
-	WA.newAchievement(self, t2)
+	if not t.no_difficulty_duplicate then
+		local t2 = table.clone(t)
+		t2.id = "NIGHTMARE_"..t2.id
+		t2.name = t2.name.." (Nightmare difficulty)"
+		WA.newAchievement(self, t2)
 
-	local t2 = table.clone(t)
-	t2.id = "INSANE_"..t2.id
-	t2.name = t2.name.." (Insane difficulty)"
-	WA.newAchievement(self, t2)
+		local t2 = table.clone(t)
+		t2.id = "INSANE_"..t2.id
+		t2.name = t2.name.." (Insane difficulty)"
+		WA.newAchievement(self, t2)
+	end
 end
diff --git a/game/modules/tome/data/achievements/quests.lua b/game/modules/tome/data/achievements/quests.lua
index 0fd8bd2c9f..0d4e3cea91 100644
--- a/game/modules/tome/data/achievements/quests.lua
+++ b/game/modules/tome/data/achievements/quests.lua
@@ -19,9 +19,13 @@
 
 --------------- Tutorial objectives
 newAchievement{
-	name = "Baby steps",
+	name = "Baby steps", id = "TUTORIAL_DONE",
 	desc = [[Completed ToME4 tutorial mode.]],
 	tutorial = true,
+	no_difficulty_duplicate = true,
+	on_gain = function(_, src, personal)
+		game:setAllowedBuild("tutorial_done")
+	end,
 }
 
 --------------- Main objectives
diff --git a/game/modules/tome/data/maps/tutorial/tutorial1.lua b/game/modules/tome/data/maps/tutorial/tutorial1.lua
index f943900bb2..9cb00c12a6 100644
--- a/game/modules/tome/data/maps/tutorial/tutorial1.lua
+++ b/game/modules/tome/data/maps/tutorial/tutorial1.lua
@@ -25,7 +25,8 @@ defineTile(")", "GRASS", {random_filter={name="ash longbow"}}, nil, nil)
 defineTile("s", "GRASS", nil, "TUTORIAL_NPC_MAGE", nil)
 defineTile(",", "GRASS", nil, nil, nil)
 defineTile("S", "GRASS", nil, {random_filter={type="animal", subtype="snake", max_ood=2}}, nil)
-defineTile("T", "GRASS", nil, {random_filter={type="giant", subtype="troll", max_ood=2}}, nil)
+defineTile("T", "GRASS", nil, "TUTORIAL_NPC_TROLL", nil)
+defineTile("L", "GRASS", nil, "TUTORIAL_NPC_LONE_WOLF", nil)
 defineTile("1", "GRASS", nil, nil, "TUTORIAL_MELEE")
 defineTile("|", "GRASS", {random_filter={name="elm arrow"}}, nil, nil)
 defineTile("2", "GRASS", {random_filter={name="potion of lesser healing"}}, nil, "TUTORIAL_OBJECTS")
@@ -36,6 +37,7 @@ defineTile("5", "DEEP_WATER", nil, nil, "TUTORIAL_TERRAIN")
 defineTile("6", "GRASS", nil, nil, "TUTORIAL_TACTICS1")
 defineTile("7", "GRASS", nil, nil, "TUTORIAL_TACTICS2")
 defineTile("8", "GRASS", nil, nil, "TUTORIAL_RANGED")
+defineTile("9", "GRASS", nil, nil, "TUTORIAL_QUESTS")
 defineTile("?", nil, nil, nil, nil)
 defineTile("j", "GRASS", nil, {random_filter={type="immovable", subtype="jelly", max_ood=2}}, nil)
 defineTile(" ", "DEEP_WATER", nil, {random_filter={type="immovable", subtype="jelly", max_ood=2}}, nil)
@@ -61,26 +63,26 @@ return [[
 &&&&&&&&,,,,,,,,,,,,,,,&&&&&&&&&&&&&&&&&,,,,,&&&&&
 &&&&&&&&&,,,,,,,,,,,,,&&&&&&&&&&,,,,,,,,7,,,&&&&&&
 &&&&&&&&&&&&&&,,,,,&&&&&&&&&&&&,,&&&&&&&,,,,&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,&&&&&&&&,,,&&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,&&&&&&&&&&&&&&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&&&&&&&&&&&&&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&&&&&&&&&&&&&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,&&&&&&&&&&&&&&&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&&&&&&,,,,,,,&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&!&&&&&&&,,j,,,,,,&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&&&&,,,2,,,,,,1,,,,
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&,,,,,,j,,,,,&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&,&&&,,,,,,,,&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&,&&&&,,,,,,&&&&&&&
-&&&&&&&&&&&&&&&&&&&&&&&&&&&&,&&&,&&&&&&&&&&&&&&&&&
-&&&&&&&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&&&&&&&
+&&&&&,,,,,,,,,&&,&,,&&&&&&&,,&&&,,&&&&&&&&&&&&&&&&
+&&&&&&,,&,,,,,,,,,&,,&&&&&&,&&&&&,,&&&&&&&&&&&&&&&
+&&&&&,,,,,,&&,,,,&,,&&&&&SSS&&&&&&,,,&&&&&&&&&&&&&
+&&&&&&,,,,,,,,,,&,&&&&&&SSSSSS&&&&&&,,,&&&&&&&&&&&
+&&&&&&,,&,&,,&&,,,&&&&&&SSSSSSS&&&&&&&,,j,j3,,&&&&
+&&&&&&&,,,,,,&&&,&&&&&&SSSSSSSS&&&&&&&&&&&&&&j,&&&
+&&&&&&&&,L,,,,,,,,&&&&&SSSSSS,,&&&&&&&&&&&&&&&,&&&
+&&&&&&&,,,,,,&&&&&&&&&&&SSS,,,,&&&&&&&&&&&&&&&,,&&
 &&&&&&&&&&&&&&&&&&&&&&&SS,,,!,&&&&&&&&&&&&&&&&&4&&
 &&&&&&&&&&&&&&&&&&&&&&&&,,,,,,&&&&&&&&&~~~&&&&&,,&
 &&&&&&&&&&&&&&&&&&&&&&&&&,,,,,&&&&&&&&&~~~~~&&&&j&
diff --git a/game/modules/tome/data/quests/tutorial.lua b/game/modules/tome/data/quests/tutorial.lua
index 3964c7ff23..87ac12b43d 100644
--- a/game/modules/tome/data/quests/tutorial.lua
+++ b/game/modules/tome/data/quests/tutorial.lua
@@ -23,3 +23,10 @@ desc = function(self, who)
 	desc[#desc+1] = "You must venture in the heart of the forest and kill the Lone Wolf, who randomly attacks villagers."
 	return table.concat(desc, "\n")
 end
+
+on_status_change = function(self, who, status, sub)
+	if self:isCompleted() then
+		who:setQuestStatus(self.id, engine.Quest.DONE)
+		world:gainAchievement("TUTORIAL_DONE", game.player)
+	end
+end
diff --git a/game/modules/tome/data/texts/tutorial/done.lua b/game/modules/tome/data/texts/tutorial/done.lua
new file mode 100644
index 0000000000..814a248ea9
--- /dev/null
+++ b/game/modules/tome/data/texts/tutorial/done.lua
@@ -0,0 +1,31 @@
+-- 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
+
+return [[#GOLD#Congratulations !#WHITE#
+
+You have completed this small tutorial, you should now know the basics of ToME4. You are ready to step forward into the world to find glory, treaures and be mercilessly slaughtered by hordes of creatures you thought you could handle!
+During this tutorial you met some creatures that where adjusted to the need of the teachings, beware, in the real world trolls are not usualy this nice!
+
+If you need a reminder of which key does what you can always access the game menu by pressing #GOLD#Escape#WHITE# and checking the key binds (you can also adjust them to your needs).
+
+As this is probably your first time with the game you will find there is a limited number of races and classes available to play, many many more do exist but you will unlock them while playing.
+
+Now go boldly and remember: #GOLD#Have fun!#WHITE#
+Press Escape, save & exit and create a new character!
+]]
diff --git a/game/modules/tome/data/texts/tutorial/quests.lua b/game/modules/tome/data/texts/tutorial/quests.lua
new file mode 100644
index 0000000000..63c2e38444
--- /dev/null
+++ b/game/modules/tome/data/texts/tutorial/quests.lua
@@ -0,0 +1,29 @@
+-- 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
+
+return [[During your adventures in the world you will find quests.
+A quest can come either automatically from an action, from finding an item, from speaking to somebody, ...
+
+You can view your current quests either by pressing Control+Q or right-clicking on yourself.
+
+Once a quest is finished or failed it will disappear from the quest log. A lot of quests in ToME are optional, if you do not think you can survive one, do not do it.
+
+When this tutorial started you where tasked to kill the Lone Wolf, you are nearing its position.
+#GOLD#Beware and fight with honour!#WHITE#
+]]
diff --git a/game/modules/tome/data/zones/tutorial/npcs.lua b/game/modules/tome/data/zones/tutorial/npcs.lua
index c857ade1fa..28857f0db4 100644
--- a/game/modules/tome/data/zones/tutorial/npcs.lua
+++ b/game/modules/tome/data/zones/tutorial/npcs.lua
@@ -21,7 +21,7 @@ load("/data/general/npcs/all.lua", rarity(0))
 
 local Talents = require("engine.interface.ActorTalents")
 
-newEntity{ base = "BASE_NPC_SKELETON", define_as="TUTORIAL_NPC_MAGE",
+newEntity{ base = "BASE_NPC_SKELETON", define_as = "TUTORIAL_NPC_MAGE",
 	name = "skeleton mage", color=colors.LIGHT_RED,
 	level_range = {1, nil}, exp_worth = 1,
 	max_life = resolvers.rngavg(50,60),
@@ -35,3 +35,40 @@ newEntity{ base = "BASE_NPC_SKELETON", define_as="TUTORIAL_NPC_MAGE",
 	autolevel = "caster",
 	ai = "dumb_talented_simple", ai_state = { talent_in=1, },
 }
+
+newEntity{ base = "BASE_NPC_TROLL", defined_as = "TUTORIAL_NPC_TROLL",
+	name = "half-dead forest troll", color=colors.YELLOW_GREEN, image="npc/troll_f.png",
+	desc = [[Green-skinned and ugly, this massive humanoid glares at you, clenching wart-covered green fists.
+He looks hurt.]],
+	level_range = {1, nil}, exp_worth = 1,
+	max_life = resolvers.rngavg(10,20),
+	combat_armor = 3, combat_def = 0,
+}
+
+newEntity{ base = "BASE_NPC_CANINE", defined_as = "TUTORIAL_NPC_LONE_WOLF",
+	name = "Lone Wolf", color=colors.VIOLET, unique=true, image="npc/canine_rungof.png",
+	desc = [[It is a large wolf with eyes full of cunning, only 3 times bigger than a normal wolf. It looks hungry. You look tasty!]],
+	level_range = {3, nil}, exp_worth = 2,
+	rank = 4,
+	size_category = 4,
+	max_life = 220,
+	combat_armor = 8, combat_def = 0,
+	combat = { dam=20, atk=15, apr=4 },
+
+	stats = { str=25, dex=20, cun=15, mag=10, con=15 },
+
+	resolvers.talents{
+		[Talents.T_GLOOM]=1,
+		[Talents.T_RUSH]=1,
+		[Talents.T_CRIPPLE]=1,
+	},
+	resolvers.sustains_at_birth(),
+
+	ai = "dumb_talented_simple", ai_state = { talent_in=4, ai_move="move_astar", },
+
+	on_die = function(self, who)
+		game.player:resolveSource():setQuestStatus("tutorial", engine.Quest.COMPLETED)
+		local d = require("engine.dialogs.ShowText").new("Tutorial: "..self.name, "tutorial/"..self.text)
+		game:registerDialog(d)
+	end,
+}
diff --git a/game/modules/tome/data/zones/tutorial/traps.lua b/game/modules/tome/data/zones/tutorial/traps.lua
index a14496d8a7..57307aa2b0 100644
--- a/game/modules/tome/data/zones/tutorial/traps.lua
+++ b/game/modules/tome/data/zones/tutorial/traps.lua
@@ -79,3 +79,8 @@ newEntity{ base = "TRAP_TUTORIAL", define_as = "TUTORIAL_RANGED",
 	name = "Ranged Combat",
 	text = "ranged",
 }
+
+newEntity{ base = "TRAP_TUTORIAL", define_as = "TUTORIAL_QUESTS",
+	name = "Quests",
+	text = "quests",
+}
-- 
GitLab