summaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-02-15 23:53:07 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-02-15 23:53:07 +0100
commite9992c6c5fe44dd440a0bbe2d86a1f2909338efe (patch)
treea2be7dc81c9d14fd45505c25480370f9ee9d1e94 /example
parentf8ad53ea03253d3c792a7c0df9384d63aee12e85 (diff)
downloadmanaserv-e9992c6c5fe44dd440a0bbe2d86a1f2909338efe.tar.gz
manaserv-e9992c6c5fe44dd440a0bbe2d86a1f2909338efe.tar.xz
manaserv-e9992c6c5fe44dd440a0bbe2d86a1f2909338efe.zip
Added a merchant and a blacksmith on the template map.
They're both using a fully working merchant lua function. Resolves: Mana-mantis #295.
Diffstat (limited to 'example')
-rw-r--r--example/clientdata/items.xml19
-rw-r--r--example/clientdata/npcs.xml4
-rw-r--r--example/serverdata/scripts/maps/desert.lua14
-rw-r--r--example/serverdata/scripts/npcs/merchant.lua99
-rw-r--r--example/serverdata/scripts/npcs/seller.lua73
5 files changed, 130 insertions, 79 deletions
diff --git a/example/clientdata/items.xml b/example/clientdata/items.xml
index 504ced4..8ab3fd1 100644
--- a/example/clientdata/items.xml
+++ b/example/clientdata/items.xml
@@ -67,10 +67,12 @@
script="candy.lua"
weight="1"
max-per-slot="30"
+ value="15"
/>
<item id="2" max-per-slot="1" name="Regenerative trinket"
description="A trinket with refreshing powers."
- image="usable/usable-regenerative-trinket.png">
+ image="usable/usable-regenerative-trinket.png"
+ value="25">
<effect trigger="existence">
<modifier attribute="hpr2" value="1.05" />
<modifier attribute="cap1" value="-50" />
@@ -78,7 +80,8 @@
</item>
<item id="3" max-per-slot="99" name="Minor health potion"
description="A small bottle containing a lightly tinted red fluid. A faint sparkle can be seen occasionally, and the very smell of the contents make you feel more alive, vibrant, and healthy."
- image="usable/usable-minor-health-potion.png">
+ image="usable/usable-minor-health-potion.png"
+ value="40">
<effect trigger="activation">
<modifier attribute="hpr3" value="2.5" duration="30" />
<modifier attribute="hpr4" value="2.0" duration="30" />
@@ -90,7 +93,8 @@
</item>
<item id="4" max-per-slot="1" name="Token of speed"
description="An old, cracked, rectangular slab. It has a faint blue glow, and a strangle symbol set into one of the sides. A circular pattern in the centre is just big enough for someone to put their hand on."
- image="usable/usable-token-of-speed.png">
+ image="usable/usable-token-of-speed.png"
+ value="50">
<effect trigger="activation">
<modifier attribute="mspd" value="1.3" duration="50" />
<cooldown value="150" />
@@ -103,7 +107,8 @@
<!-- Example of weapons -->
<item id="5" max-per-slot="1" name="Sword" attack-action="attack_stab"
description="A simple sword."
- image="equipment/weapons/weapon-sword-sword.png">
+ image="equipment/weapons/weapon-sword-sword.png"
+ value="70">
<equip>
<slot type="hand" required="2" />
</equip>
@@ -119,7 +124,8 @@
</item>
<item id="6" max-per-slot="1" name="Bow" attack-action="attack_bow"
description="A simple bow made of fine oak wood."
- image="equipment/weapons/weapon-bow-bow.png">
+ image="equipment/weapons/weapon-bow-bow.png"
+ value="80">
<equip>
<slot type="hand" required="2" />
</equip>
@@ -137,7 +143,8 @@
<!-- Example of equippable items -->
<item id="7" max-per-slot="1" name="Leather shirt"
description="A simple shirt made of leather."
- image="equipment/chest/chest-leathershirt.png">
+ image="equipment/chest/chest-leathershirt.png"
+ value="80">
<equip>
<slot type="torso" required="1" />
</equip>
diff --git a/example/clientdata/npcs.xml b/example/clientdata/npcs.xml
index 0af855f..f94ce49 100644
--- a/example/clientdata/npcs.xml
+++ b/example/clientdata/npcs.xml
@@ -9,6 +9,10 @@
<npcs>
<npc id="1"><sprite variant="0">npcs/static-npcs.xml</sprite></npc><!-- Barber 1&2 -->
<!-- ... -->
+ <npc id="3"><sprite variant="2">npcs/static-npcs.xml</sprite></npc><!-- Merchant -->
+ <!-- ... -->
+ <npc id="5"><sprite variant="4">npcs/static-npcs.xml</sprite></npc><!-- Smith -->
+ <!-- ... -->
<npc id="8"><sprite variant="7">npcs/static-npcs.xml</sprite></npc><!-- Banker -->
<!-- ... -->
<npc id="11"><sprite variant="10">npcs/static-npcs.xml</sprite></npc><!-- Welcoming girl -->
diff --git a/example/serverdata/scripts/maps/desert.lua b/example/serverdata/scripts/maps/desert.lua
index 710f552..812bfa6 100644
--- a/example/serverdata/scripts/maps/desert.lua
+++ b/example/serverdata/scripts/maps/desert.lua
@@ -15,13 +15,27 @@ require "scripts/lua/npclib"
-- From example/serverdata/scripts
require "scripts/npcs/banker"
require "scripts/npcs/barber"
+require "scripts/npcs/merchant"
atinit(function()
+
-- Barber examples
create_npc("Barber Twin", 1, 14 * TILESIZE + TILESIZE / 2, 9 * TILESIZE + TILESIZE / 2, Barber, nil)
create_npc("Barber Twin", 1, 20 * TILESIZE + TILESIZE / 2, 11 * TILESIZE + TILESIZE / 2, npclib.talk(Barber, {14, 15, 16}, {}), nil)
+
-- A simple banker
create_npc("Banker", 8, 35 * TILESIZE + TILESIZE / 2, 24 * TILESIZE + TILESIZE / 2, Banker, nil)
+
+ -- A simple merchant.
+ merchant_buy_table = { {1, 10, 20}, {2, 10, 30}, {3, 10, 50} }
+ merchant_sell_table = { {1, 10, 19}, {5, 10, 30}, {6, 10, 200}, {7, 10, 300} }
+ create_npc("Merchant", 3, 4 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, merchant_buy_table, merchant_sell_table), nil)
+
+ -- Another Merchant, selling some equipment, and buying everything...
+ smith_buy_table = { {5, 10, 50}, {7, 10, 70} }
+ create_npc("Smith", 5, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, smith_buy_table), nil)
+
+
-- The most simple NPC - Welcoming new ones around.
create_npc("Harmony", 11, 4 * TILESIZE + TILESIZE / 2, 25 * TILESIZE + TILESIZE / 2, npclib.talk(Harmony, "Welcome in the template world!\nI hope you'll find here whatever you were searching for.", "Do look around to find some interesting things coming along!"), Harmony_update)
end)
diff --git a/example/serverdata/scripts/npcs/merchant.lua b/example/serverdata/scripts/npcs/merchant.lua
new file mode 100644
index 0000000..46f8554
--- /dev/null
+++ b/example/serverdata/scripts/npcs/merchant.lua
@@ -0,0 +1,99 @@
+----------------------------------------------------------
+-- Merchant Function Sample --
+----------------------------------------------------------------------------------
+-- Copyright 2009-2010 The Mana World Development Team --
+-- --
+-- This file is part of The Mana World. --
+-- --
+-- The Mana World 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 2 of the License, or any later version. --
+----------------------------------------------------------------------------------
+
+function Merchant(npc, ch, buy_sell_table)
+
+-- Important note: You can add two tables made of trinoms here when calling the
+-- merchant function. E.g.: Merchant(npc, ch, buy_table, sell_table)
+-- Even though, the function here will see only one table:
+-- buy_sell_table[1] will corresponds to the first table (used to list
+-- boughtable items, and buy_sell_table[2] listing sellable items.
+
+ local rights = mana.chr_get_rights(ch);
+
+ if (rights >= 128) then
+ do_message(npc, ch, "Oh mighty server administrator, how can I avoid your wrath?")
+ elseif (rights >= 8) then
+ do_message(npc, ch, "How can I be of assistance, sir gamemaster?")
+ elseif (rights >= 4) then
+ do_message(npc, ch, "What feature would you like to debug, developer?")
+ elseif (rights >= 2) then
+ do_message(npc, ch, "How can I assist you in your testing duties?")
+ elseif (rights >= 1) then
+ if mana.chr_get_gender(ch) == GENDER_FEMALE then
+ do_message(npc, ch, "What do you want, Madam?")
+ else
+ do_message(npc, ch, "Wat do you want, Sir?")
+ end
+ else
+ do_message(npc, ch, "...Aren't you supposed to be banned??")
+ end
+
+ -- Constructing the choice list
+ local choice_table = {}
+ table.insert (choice_table, "To Buy...")
+
+ if (buy_sell_table[2] == nil) then
+ table.insert (choice_table, "To sell stuff...")
+ else
+ table.insert (choice_table, "Can you make me a price for what I have?")
+ end
+ table.insert (choice_table, "Nevermind...")
+
+ local v = do_choice(npc, ch, choice_table)
+
+ --Debug and learning purpose
+ --for i,k in ipairs(choice_table) do print(i,k) end
+ -- The buy table first line content
+ --print (((buy_sell_table[1])[1])[1], ((buy_sell_table[1])[1])[2], ((buy_sell_table[1])[1])[3])
+ -- The sell table first line content
+ --print (((buy_sell_table[2])[1])[1], ((buy_sell_table[2])[1])[2], ((buy_sell_table[2])[1])[3])
+
+ if v == 1 then
+ -- "To buy."
+ local buycase = mana.npc_trade(npc, ch, false, buy_sell_table[1])
+ if buycase == 0 then
+ do_message(npc, ch, "What do you want to buy?")
+ elseif buycase == 1 then
+ do_message(npc, ch, "I've got no items to sell.")
+ else
+ do_message(npc, ch, "Hmm, something went wrong... Ask a scripter to fix the buying mode!")
+ end
+
+ elseif v == 2 then
+
+ if buy_sell_table[2] == nil then
+ -- "To sell stuff..."
+ local sellcase = mana.npc_trade(npc, ch, true)
+ if sellcase == 0 then
+ do_message(npc, ch, "Ok, what do you want to sell?")
+ elseif sellcase == 1 then
+ do_message(npc, ch, "I'm not interested by any of your items.")
+ else
+ do_message(npc, ch, "Hmm, something went wrong... Ask a scripter to fix this!")
+ end
+ else
+ -- "Can you make me a price for what I have?"
+ local sellcase = mana.npc_trade(npc, ch, true, buy_sell_table[2])
+ if sellcase == 0 then
+ do_message(npc, ch, "Here we go:")
+ elseif sellcase == 1 then
+ do_message(npc, ch, "I'm not that interested in any of your items.")
+ else
+ do_message(npc, ch, "Hmm, something went wrong... Ask a scripter to fix me!")
+ end
+ end
+
+ end
+ do_message(npc, ch, "See you later!")
+ do_npc_close(npc, ch)
+end
diff --git a/example/serverdata/scripts/npcs/seller.lua b/example/serverdata/scripts/npcs/seller.lua
deleted file mode 100644
index c809f3e..0000000
--- a/example/serverdata/scripts/npcs/seller.lua
+++ /dev/null
@@ -1,73 +0,0 @@
-----------------------------------------------------------
--- Seller Function Sample --
-----------------------------------------------------------------------------------
--- Copyright 2009-2010 The Mana World Development Team --
--- --
--- This file is part of The Mana World. --
--- --
--- The Mana World 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 2 of the License, or any later version. --
-----------------------------------------------------------------------------------
-
-function Seller(npc, ch)
- do_message(npc, ch, "Hello! What can I provide you today?")
- local rights = mana.chr_get_rights(ch);
-
- if (rights >= 128) then
- do_message(npc, ch, "Oh mighty server administrator, how can I avoid your wrath?")
- elseif (rights >= 8) then
- do_message(npc, ch, "How can I be of assistance, sir gamemaster?")
- elseif (rights >= 4) then
- do_message(npc, ch, "What feature would you like to debug, developer?")
- elseif (rights >= 2) then
- do_message(npc, ch, "How can I assist you in your testing duties?")
- elseif (rights >= 1) then
- do_message(npc, ch, "What do you want, lowly player?")
- else
- do_message(npc, ch, "...Aren't you supposed to be banned??")
- end
-
- local v = do_choice(npc, ch, "To buy...",
- "To sell stuff...",
- "Can you make me a price for what I have?")
- if v == 1 then
- -- "To buy."
- local buycase = mana.npc_trade(npc, ch, false, { {1, 10, 20}, {2, 10, 30}, {3, 10, 50} })
- if buycase == 0 then
- do_message(npc, ch, "What do you want to buy?")
- elseif buycase == 1 then
- do_message(npc, ch, "I've got no items to sell.")
- else
- do_message(npc, ch, "Hmm, something went wrong... Ask a scripter to fix the buying mode!")
- end
-
- elseif v == 2 then
-
- -- "To sell stuff..."
- local sellcase = mana.npc_trade(npc, ch, true)
- if sellcase == 0 then
- do_message(npc, ch, "Ok, what do you want to sell?")
- elseif sellcase == 1 then
- do_message(npc, ch, "I'm not interested by any of your items.")
- else
- do_message(npc, ch, "Hmm, something went wrong... Ask a scripter to fix this!")
- end
-
- elseif v == 3 then
-
- -- "Can you make me a price for what I have?"
- local sellcase = mana.npc_trade(npc, ch, true, { {4, 10, 20}, {5, 10, 30}, {6, 10, 200}, {7, 10, 300} })
- if sellcase == 0 then
- do_message(npc, ch, "Here we go:")
- elseif sellcase == 1 then
- do_message(npc, ch, "I'm not that interested in any of your items.")
- else
- do_message(npc, ch, "Hmm, something went wrong... Ask a scripter to fix me!")
- end
-
- end
- do_message(npc, ch, "See you later!")
- do_npc_close(npc, ch)
-end
-