summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp56
-rw-r--r--src/game.h2
-rw-r--r--src/graphic/graphic.cpp90
-rw-r--r--src/gui/char_select.cpp2
-rw-r--r--src/gui/char_server.cpp2
-rw-r--r--src/gui/shop.cpp88
-rw-r--r--src/gui/shop.h46
-rw-r--r--src/gui/skill.cpp2
-rw-r--r--src/gui/stats.h8
-rw-r--r--src/main.cpp2
-rw-r--r--src/main.h2
11 files changed, 276 insertions, 24 deletions
diff --git a/src/game.cpp b/src/game.cpp
index f86e4d1b..969c83c5 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -27,6 +27,7 @@
#include "./gui/chat.h"
#include "./gui/gui.h"
#include "./gui/inventory.h"
+#include "./gui/shop.h"
#include "./graphic/super_eagle.h"
#include "./graphic/graphic.h"
#include "./sound/sound.h"
@@ -41,6 +42,7 @@ bool refresh_beings = false;
unsigned char keyb_state;
volatile int tick_time;
volatile bool refresh = false, action_time = false;
+int current_npc;
#define MAX_TIME 10000
@@ -300,7 +302,6 @@ void do_parse() {
NODE *node = NULL;
int len;
-
// We need at least 2 bytes to identify a packet
if(in_size>=2) {
// Check if the received packet is complete
@@ -317,10 +318,10 @@ void do_parse() {
fprintf(file, "%x|%i|%c ", RFIFOB(i), RFIFOB(i), RFIFOB(i));
if((i+1)%10==0)fprintf(file, "\n");
}
- fclose(file);
- file = fopen("packet.list", "ab");
+ fclose(file);*/
+ FILE *file = fopen("packet.list", "ab");
fprintf(file, "%x\n", RFIFOW(0));
- fclose(file);*/
+ fclose(file);
// Parse packet based on their id
switch(id) {
@@ -458,17 +459,13 @@ void do_parse() {
break;
case 0x01ee: //Get the items
for(int loop = 0; loop < RFIFOW(4); loop++)
- {
inventory.addItem(loop,RFIFOW(10+18*loop));
- }
break;
case 0x00a8: // could I use the item?
// index RFIFOW(2)
// succes or not RFIFOB(6);
if(RFIFOB(6))
- {
- inventory.addItem(RFIFOW(2),RFIFOW(4));
- }
+ inventory.addItem(RFIFOW(2),RFIFOW(4));
break;
// Warp
case 0x0091:
@@ -597,6 +594,9 @@ void do_parse() {
break;
// Status change
case 0x00b1:
+ /*char sto[40];
+ sprintf(sto, "%i %i", RFIFOW(2), RFIFOL(4));
+ alert(sto,"","","","",0,0);*/
switch(RFIFOW(2)) {
case 1:
char_info->xp = RFIFOL(4);
@@ -604,7 +604,7 @@ void do_parse() {
case 2:
char_info->job_xp = RFIFOL(4);
break;
- case 14:
+ case 20:
char_info->zeny = RFIFOL(4);
break;
// case 16 and 17 missing
@@ -649,6 +649,42 @@ void do_parse() {
break;
}
break;
+ // Buy/Sell dialog
+ case 0x00c4:
+ show_npc_dialog = 2;
+ current_npc = RFIFOL(2);
+ break;
+ // Buy dialog
+ case 0x00c6:
+ n_items = (len-4)/11;
+ show_npc_dialog = 3;
+ for(int k=0;k<n_items;k++)
+ add_item(RFIFOW(4+11*k+9), RFIFOL(4+11*k));
+ break;
+ // Sell dialog
+ case 0x00c7:
+ n_items = (len-4)/10;
+ show_npc_dialog = 4;
+ for(int k=0;k<n_items;k++)
+ add_item(RFIFOW(4+10*k), RFIFOL(4+10*k+2));
+ break;
+ // Answer to buy
+ case 0x00ca:
+ if(RFIFOB(2)==0)
+ ok("Transaction", "Thanks for buying");
+ else
+ ok("Transaction", "Unable to buy");
+ break;
+ // Answer to sell
+ case 0x00cb:
+ if(RFIFOB(2)==0)
+ ok("Transaction", "Thanks for selling");
+ else
+ ok("Transaction", "Unable to sell");
+ break;
+ // Add item to inventory
+ case 0x00a0:
+ break;
// Manage non implemented packets
default:
//alert(pkt_nfo,"","","","",0,0);
diff --git a/src/game.h b/src/game.h
index f468c6a2..9f1f6d4f 100644
--- a/src/game.h
+++ b/src/game.h
@@ -71,7 +71,7 @@
extern char map_path[480];
extern DIALOG skill_dialog[];
-extern int fps, frame;
+extern int fps, frame, current_npc;
extern char walk_status;
extern unsigned short src_x, src_y, x, y;
extern volatile int tick_time;
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 3c9232de..43768f54 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -38,13 +38,14 @@
#include "../being.h"
#include "../gui/chat.h"
#include "../gui/inventory.h"
+#include "../gui/shop.h"
#include "../../data/graphic/gfx_data.h"
BITMAP *buffer, *double_buffer, *chat_background;
DATAFILE *tileset;
char page_num;
int map_x, map_y, camera_x, camera_y;
-DIALOG_PLAYER *chat_player, *npc_player, *skill_player;
+DIALOG_PLAYER *chat_player, *npc_player, *skill_player, *buy_sell_player, *buy_player, *sell_player;
char speech[255] = "";
char npc_text[1000] = "";
TmwInventory inventory;
@@ -60,6 +61,33 @@ DIALOG npc_dialog[] = {
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
+DIALOG buy_sell_dialog[] = {
+ /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
+ { tmw_dialog_proc, 350, 200, 100, 80, 0, 0, 0, 0, 0, 0, (char *)"Shop", NULL, NULL },
+ { tmw_button_proc, 360, 225, 80, 20, 255, 0, 0, D_EXIT, 0, 0, (char *)"&BUY", NULL, NULL },
+ { tmw_button_proc, 360, 250, 80, 20, 255, 0, 0, D_EXIT, 0, 0, (char *)"&SELL", NULL, NULL },
+ { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
+};
+
+DIALOG buy_dialog[] = {
+ /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
+ { tmw_dialog_proc, 300, 200, 260, 150, 0, 0, 0, 0, 0, 0, (char *)"Buy", NULL, NULL },
+ { tmw_button_proc, 450, 326, 50, 20, 255, 0, 'o', D_EXIT, 0, 0, (char *)"&Ok", NULL, NULL },
+ { tmw_button_proc, 508, 326, 50, 20, 255, 0, 'c', D_EXIT, 0, 0, (char *)"&Cancel", NULL, NULL },
+ { tmw_list_proc, 304, 224, 252, 100, 0, 0, 0, 0, 0, 0, (char *)shop_list, NULL, NULL },
+ { tmw_text_proc, 304, 326, 180, 100, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
+ { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
+};
+
+DIALOG sell_dialog[] = {
+ /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
+ { tmw_dialog_proc, 300, 200, 260, 150, 0, 0, 0, 0, 0, 0, (char *)"Sell", NULL, NULL },
+ { tmw_button_proc, 450, 326, 50, 20, 255, 0, 'o', D_EXIT, 0, 0, (char *)"&Ok", NULL, NULL },
+ { tmw_button_proc, 508, 326, 50, 20, 255, 0, 'c', D_EXIT, 0, 0, (char *)"&Cancel", NULL, NULL },
+ { tmw_list_proc, 304, 224, 252, 100, 0, 0, 0, 0, 0, 0, (char *)shop_list, NULL, NULL },
+ { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
+};
+
DIALOG chat_dialog[] = {
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
{ tmw_edit_proc, 0, 574, 592, 25, 0, 0, 'c', 0, 90, 0, speech, NULL, NULL },
@@ -117,6 +145,9 @@ void init_graphic() {
npc_player = init_dialog(npc_dialog, -1);
position_dialog(npc_dialog, 300, 200);
skill_player = init_dialog(skill_dialog, -1);
+ buy_sell_player = init_dialog(buy_sell_dialog, -1);
+ buy_player = init_dialog(buy_dialog, -1);
+ sell_player = init_dialog(sell_dialog, -1);
gui_bitmap = double_buffer;
alfont_text_mode(-1);
inventory.create(100, 100);
@@ -236,9 +267,60 @@ void do_graphic(void) {
chatlog.chat_draw(double_buffer, 8, gui_font);
gui_update(chat_player);
- if(show_npc_dialog) {
- dialog_message(npc_dialog,MSG_DRAW,0,0);
- if(!(show_npc_dialog = gui_update(npc_player)))strcpy(npc_text, "");
+ switch(show_npc_dialog) {
+ case 1:
+ dialog_message(npc_dialog, MSG_DRAW, 0, 0);
+ if(!(show_npc_dialog = gui_update(npc_player)))strcpy(npc_text, "");
+ break;
+ case 2:
+ dialog_message(buy_sell_dialog, MSG_DRAW, 0, 0);
+ if(!gui_update(buy_sell_player)) {
+ show_npc_dialog = shutdown_dialog(buy_sell_player);
+ if(show_npc_dialog==1 || show_npc_dialog==2) {
+ WFIFOW(0) = net_w_value(0x00c5);
+ WFIFOL(2) = net_l_value(current_npc);
+ WFIFOB(6) = net_b_value(show_npc_dialog-1);
+ WFIFOSET(7);
+ }
+ show_npc_dialog = 0;
+ buy_sell_player = init_dialog(buy_sell_dialog, -1);
+ }
+ break;
+ case 3:
+ char money[20];
+ sprintf(money, "%i gp", char_info->zeny);
+ buy_dialog[4].dp = &money;
+ dialog_message(buy_dialog, MSG_DRAW, 0, 0);
+ if(!gui_update(buy_player)) {
+ show_npc_dialog = shutdown_dialog(buy_player);
+ if(show_npc_dialog==1) {
+ WFIFOW(0) = net_w_value(0x00c8);
+ WFIFOW(2) = net_w_value(8);
+ WFIFOW(4) = net_w_value(1);
+ WFIFOW(6) = net_w_value(get_item_id(buy_dialog[3].d1));
+ WFIFOSET(8);
+ }
+ show_npc_dialog = 0;
+ buy_player = init_dialog(buy_dialog, -1);
+ close_shop();
+ }
+ break;
+ case 4:
+ dialog_message(sell_dialog, MSG_DRAW, 0, 0);
+ if(!gui_update(sell_player)) {
+ show_npc_dialog = shutdown_dialog(sell_player);
+ if(show_npc_dialog==1) {
+ WFIFOW(0) = net_w_value(0x00c9);
+ WFIFOW(2) = net_w_value(8);
+ WFIFOW(4) = net_w_value(1);
+ WFIFOW(6) = net_w_value(get_item_id(sell_dialog[3].d1));
+ WFIFOSET(8);
+ }
+ show_npc_dialog = 0;
+ sell_player = init_dialog(sell_dialog, -1);
+ close_shop();
+ }
+ break;
}
if(show_skill_dialog) {
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index a23c4713..6aa8c176 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -184,7 +184,7 @@ void server_char_delete() {
while((in_size<3)||(out_size>0))flush();
if(RFIFOW(0)==0x006d) {
while(in_size<108)flush();
- char_info = (CHAR_INFO *)malloc(sizeof(CHAR_INFO));
+ char_info = (PLAYER_INFO *)malloc(sizeof(PLAYER_INFO));
char_info->id = account_ID;
memset(char_info->name, '\0', 24);
strcpy(char_info[0].name, RFIFOP(2+74));
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 4fbb2267..752604f1 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -94,7 +94,7 @@ void server_char_server() {
if(RFIFOW(0)==0x006b) {
while(in_size<RFIFOW(2))flush();
n_character = (RFIFOW(2)-24)/106;
- char_info = (CHAR_INFO *)malloc(sizeof(CHAR_INFO)*n_character);
+ char_info = (PLAYER_INFO *)malloc(sizeof(PLAYER_INFO)*n_character);
for(int i=0;i<n_character;i++) {
char_info[i].id = RFIFOL(24+106*i);
strcpy(char_info[i].name, RFIFOP(24+106*i+74));
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
new file mode 100644
index 00000000..84fe279e
--- /dev/null
+++ b/src/gui/shop.cpp
@@ -0,0 +1,88 @@
+/**
+
+ The Mana World
+ Copyright 2004 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.
+
+ The Mana World 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 The Mana World; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ By ElvenProgrammer aka Eugenio Favalli (umperio@users.sourceforge.net)
+
+*/
+
+#include "shop.h"
+
+#include <allegro.h>
+
+int n_items;
+ITEM_SHOP *shop = NULL;
+
+char *item_db[] = { "Candy", "Medical Herb", "Chocolate" };
+
+char *shop_list(int index, int *list_size) {
+ if(index<0) {
+ *list_size = n_items;
+ return NULL;
+ } else {
+ int iterator = 0;
+ ITEM_SHOP *item_shop = shop;
+ while(iterator<index) {
+ item_shop = item_shop->next;
+ iterator++;
+ }
+ return item_shop->name;
+ }
+}
+
+void add_item(short id, int price) {
+ ITEM_SHOP *item_shop = (ITEM_SHOP *)malloc(sizeof(ITEM_SHOP));
+ if(id-501>=0 && id-501<=2)
+ sprintf(item_shop->name, "%s %i gp", item_db[id-501], price);
+ else
+ sprintf(item_shop->name, "Unknown item %i gp", price);
+ item_shop->price = price;
+ item_shop->id = id;
+ item_shop->next = NULL;
+ if(shop==NULL)
+ shop = item_shop;
+ else {
+ ITEM_SHOP *temp = shop;
+ while(temp->next)
+ temp = temp->next;
+ temp->next = item_shop;
+ }
+}
+
+void close_shop() {
+ ITEM_SHOP *temp, *next;
+ temp = shop;
+ while(temp) {
+ next = temp->next;
+ free(temp);
+ temp = next;
+ }
+ shop = NULL;
+}
+
+short get_item_id(int index) {
+ int iterator = 0;
+ ITEM_SHOP *item_shop = shop;
+ while(iterator<index) {
+ item_shop = item_shop->next;
+ iterator++;
+ }
+ return item_shop->id;
+}
diff --git a/src/gui/shop.h b/src/gui/shop.h
new file mode 100644
index 00000000..b8051536
--- /dev/null
+++ b/src/gui/shop.h
@@ -0,0 +1,46 @@
+/**
+
+ The Mana World
+ Copyright 2004 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.
+
+ The Mana World 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 The Mana World; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ By ElvenProgrammer aka Eugenio Favalli (umperio@users.sourceforge.net)
+
+*/
+
+#ifndef _SHOP_H
+#define _SHOP_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+struct ITEM_SHOP {
+ char name[30];
+ int price;
+ short id;
+ ITEM_SHOP *next;
+};
+
+extern int n_items;
+
+char *shop_list(int index, int *list_size);
+void add_item(short id, int price);
+void close_shop();
+short get_item_id(int index);
+
+#endif
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 35abb975..bf9c2d86 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -25,7 +25,7 @@
#include "skill.h"
-extern CHAR_INFO *char_info;
+extern PLAYER_INFO *char_info;
char str_string[8];
char agi_string[8];
diff --git a/src/gui/stats.h b/src/gui/stats.h
index 09ec8950..e6a2ee39 100644
--- a/src/gui/stats.h
+++ b/src/gui/stats.h
@@ -21,21 +21,21 @@
*/
-#ifndef __STATS_H
-#define __STATS_H
+#ifndef _STATS_H
+#define _STATS_H
#include <allegro.h>
#include "../main.h"
#include "gui.h"
-typedef struct CHAR_INFO {
+typedef struct {
int id;
char name[24];
short hp, max_hp, sp, max_sp, lv;
int xp, zeny, job_xp, job_lv;
short statp, skillp;
char STR, AGI, VIT, INT, DEX, LUK;
-};
+} PLAYER_INFO;
int charstats_display(CHAR_INFO *);
diff --git a/src/main.cpp b/src/main.cpp
index df46d6bb..5fd3386c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,7 +31,7 @@
int account_ID, session_ID1, session_ID2;
char sex, n_server, n_character;
SERVER_INFO *server_info;
-CHAR_INFO *char_info = new CHAR_INFO;
+PLAYER_INFO *char_info = new PLAYER_INFO;
BITMAP *playerset;
DATAFILE *graphic, *emotions;
diff --git a/src/main.h b/src/main.h
index 65019a77..999f061d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -68,7 +68,7 @@ extern char map_name[16];
extern int account_ID, session_ID1, session_ID2;
extern char sex, n_server, n_character;
extern SERVER_INFO *server_info;
-extern CHAR_INFO *char_info;
+extern PLAYER_INFO *char_info;
extern unsigned char state;
extern unsigned short x, y;
extern unsigned char direction;