summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--npc/boss/_import.txt1
-rw-r--r--npc/boss/manamarket.txt107
-rw-r--r--npc/functions/input.txt39
-rw-r--r--sql-files/main.sql31
4 files changed, 178 insertions, 0 deletions
diff --git a/npc/boss/_import.txt b/npc/boss/_import.txt
index c3051c8d7..60544f5ea 100644
--- a/npc/boss/_import.txt
+++ b/npc/boss/_import.txt
@@ -1,3 +1,4 @@
// Map boss: Boss Arena
// This file is generated automatically. All manually added changes will be removed when running the Converter.
+"npc/boss/manamarket.txt",
"npc/boss/throne.txt",
diff --git a/npc/boss/manamarket.txt b/npc/boss/manamarket.txt
new file mode 100644
index 000000000..6f9f3a940
--- /dev/null
+++ b/npc/boss/manamarket.txt
@@ -0,0 +1,107 @@
+// TMW2 Scripts.
+// Author:
+// Jesusalva
+// Description:
+// ManaMarket sketch
+
+boss,41,41,0 script ManaMarket NPC_TEDDYGIRL,{
+ function MMCooldown;
+ function MMBuy;
+ function MMBuyMenu;
+
+ if (!is_staff()) end;
+ mesn;
+ mesq l("Hello! How can I help you?");
+ if (MM_DELAY > gettimetick(2)) close;
+ next;
+ select
+ l("Buy"),
+ l("Sell"),
+ l("Nothing");
+ mes "";
+ if (@menu == 1)
+ MMBuy();
+ close;
+
+
+// Set the cooldown value to the same as interserver value
+function MMCooldown {
+ MM_DELAY=gettimetick(2)+300;
+ return;
+}
+
+// MMBuy(page=0)
+function MMBuy {
+ .@p=getarg(0,0);
+ .@v=MMBuyMenu(.@p);
+
+ // Special results
+ switch (.@v) {
+ case -1:
+ return;
+ case -2:
+ // FIXME
+ MMBuy(.@p+1);
+ break;
+ default:
+ break;
+ }
+
+ .@it=$@MM_nameid[.@v];
+ // Can't buy stuff you already have
+ if (countitem(.@it)) {
+ mesn;
+ mesq l("You already have this.");
+ return;
+ }
+
+
+ // Report
+ mesn;
+ mesq l("Purchase %02d %s for %d GP?",
+ $@MM_amount[.@v], getitemlink(.@it), $@MM_price[.@v]);
+ next;
+ if (askyesno() == ASK_YES) {
+ // TODO: Check if still in stock
+ mesn;
+ mesq l("Sorry. The arrays can't have zeros.");
+ // getitem2
+ }
+ return;
+}
+
+// MMBuyMenu ( page=0 )
+function MMBuyMenu {
+ deletearray @mm_menu$;
+ setarray @mm_menu$, l("Cancel"), -1;
+ .@pg=getarg(0, 0);
+ .@limit=min(getarraysize($@MM_id), (.@pg+1)*20);
+
+ // Prepare the information array
+ for (.@i=.@pg*20; .@i < .@limit; .@i++) {
+ //@mm_menu$+=getitemname($@MM_nameid[.@i])+":";
+ array_push(@mm_menu$, getitemname($@MM_nameid[.@i]));
+ array_push(@mm_menu$, str(.@i));
+ }
+
+ // Still more pages
+ if (.@limit < getarraysize($@MM_id)) {
+ array_push(@mm_menu$, "Next Page >>");
+ array_push(@mm_menu$, -2);
+ }
+
+ // Handle input
+ menuint2("@mm_menu$");
+ deletearray @mm_menu$;
+ return @menuret;
+}
+
+OnInit:
+ .distance=6;
+ .sex = G_FEMALE;
+
+ // Load ManaMarket (max 100 entries)
+ .@nb = query_sql("SELECT `id`, `account_id`, `price`, `expire_time`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `opt_idx0`, `opt_val0`, `opt_idx1`, `opt_val1`, `opt_idx2`, `opt_val2`, `opt_idx3`, `opt_val3`, `opt_idx4`, `opt_val4` FROM `manamarket` ORDER BY `id` DESC LIMIT 100", $@MM_id, $@MM_account_id, $@MM_price, $@MM_expire_time, $@MM_nameid, $@MM_amount, $@MM_equip, $@MM_identify, $@MM_refine, $@MM_attribute, $@MM_card0, $@MM_card1, $@MM_card2, $@MM_card3, $@MM_opt_idx0, $@MM_opt_val0, $@MM_opt_idx1, $@MM_opt_val1, $@MM_opt_idx2, $@MM_opt_val2, $@MM_opt_idx3, $@MM_opt_val3, $@MM_opt_idx4, $@MM_opt_val4);
+ end;
+}
+
diff --git a/npc/functions/input.txt b/npc/functions/input.txt
index cf0382d25..1ccfc0578 100644
--- a/npc/functions/input.txt
+++ b/npc/functions/input.txt
@@ -1,6 +1,7 @@
// Evol functions.
// Author:
// 4144
+// Jesusalva
// Description:
// Input utility functions
// Variables:
@@ -64,3 +65,41 @@ function script menustr {
@menuret$ = .@vals$[@menu];
return @menuret$;
}
+
+// menuint2(<array>)
+function script menuint2 {
+ .@ar$=getarg(0);
+ .@vals=0;
+ .@menustr$="";
+
+ if (getarraysize(.@ar$) % 2 != 0)
+ Exception("Invalid array size", RB_DEFAULT|RB_ISFATAL);
+
+ freeloop(true);
+ for (.@f=0; .@f < getarraysize(.@ar$); .@f++) {
+ // String vs Int
+ if (.@f % 2 == 0) {
+ .@menustr$+=getd(.@ar$+"["+.@f+"]")+":";
+ } else {
+ array_push(.@vals, getd(.@ar$+"["+.@f+"]"));
+ }
+ }
+ freeloop(false);
+
+ // Do the request
+ // We have: .@vals and .@menustr$
+ .@vals[.@cnt] = -1;
+ @menu = 255;
+ @menuret = -1;
+ select(.@menustr$);
+ if (@menu == 255)
+ return -1;
+
+ @menu --;
+ if (@menu < 0 || @menu >= getarraysize(.@vals) - 1)
+ return -1;
+
+ @menuret = .@vals[@menu];
+ return @menuret;
+}
+
diff --git a/sql-files/main.sql b/sql-files/main.sql
index 6810f74a6..a353e6a1c 100644
--- a/sql-files/main.sql
+++ b/sql-files/main.sql
@@ -1053,3 +1053,34 @@ CREATE TABLE IF NOT EXISTS `npc_barter_data` (
`priceAmount` INT(11) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`name`, `itemid`, `priceId`, `priceAmount`)
) ENGINE=MyISAM;
+
+-- Bound items cannot go to ManaMarket anyway
+-- PS. id autofilled, accountid/price/expire by MM
+-- options by index, all others by getinventorylist()
+CREATE TABLE IF NOT EXISTS `manamarket` (
+ `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `account_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `price` INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `expire_time` INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `amount` SMALLINT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `equip` INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `identify` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
+ `refine` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+ `attribute` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',
+ `card0` INT(11) NOT NULL DEFAULT '0',
+ `card1` INT(11) NOT NULL DEFAULT '0',
+ `card2` INT(11) NOT NULL DEFAULT '0',
+ `card3` INT(11) NOT NULL DEFAULT '0',
+ `opt_idx0` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
+ `opt_val0` SMALLINT(5) NOT NULL DEFAULT '0',
+ `opt_idx1` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
+ `opt_val1` SMALLINT(5) NOT NULL DEFAULT '0',
+ `opt_idx2` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
+ `opt_val2` SMALLINT(5) NOT NULL DEFAULT '0',
+ `opt_idx3` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
+ `opt_val3` SMALLINT(5) NOT NULL DEFAULT '0',
+ `opt_idx4` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
+ `opt_val4` SMALLINT(5) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM;