Przeglądaj źródła

Updated callshop selling list variables (#2480)

* Updated callshop selling list variables
* Updated script command callshop OnSellItem list to include random item options.
* See documentation for more information.
Aleos 7 lat temu
rodzic
commit
fa425b834f
4 zmienionych plików z 58 dodań i 17 usunięć
  1. 24 9
      doc/script_commands.txt
  2. 28 8
      src/map/npc.c
  3. 3 0
      src/map/script.cpp
  4. 3 0
      src/map/script.h

+ 24 - 9
doc/script_commands.txt

@@ -6552,15 +6552,30 @@ The label "OnBuyItem" sets the following arrays:
 	@bought_quantity - amount bought
 
 The label "OnSellItem" sets the following arrays:
-	@sold_nameid     - item ID sold
-	@sold_quantity   - amount sold
-	@sold_refine     - refine count
-	@sold_attribute  - if the item is broken (1) or not (0)
-	@sold_identify   - if the item is identified (1) or not (0)
-	@sold_card1      - card slot 1
-	@sold_card2      - card slot 2
-	@sold_card3      - card slot 3
-	@sold_card4      - card slot 4
+	@sold_nameid        - item ID sold
+	@sold_quantity      - amount sold
+	@sold_refine        - refine count
+	@sold_attribute     - if the item is broken (1) or not (0)
+	@sold_identify      - if the item is identified (1) or not (0)
+	@sold_card1         - card slot 1
+	@sold_card2         - card slot 2
+	@sold_card3         - card slot 3
+	@sold_card4         - card slot 4
+	@sold_option_id1    - random option ID 1
+	@sold_option_val1   - random option value 1
+	@sold_option_param1 - random option param 1
+	@sold_option_id2    - random option ID 2
+	@sold_option_val2   - random option value 2
+	@sold_option_param2 - random option param 2
+	@sold_option_id3    - random option ID 3
+	@sold_option_val3   - random option value 3
+	@sold_option_param3 - random option param 3
+	@sold_option_id4    - random option ID 4
+	@sold_option_val4   - random option value 4
+	@sold_option_param4 - random option param 4
+	@sold_option_id5    - random option ID 5
+	@sold_option_val5   - random option value 5
+	@sold_option_param5 - random option param 5
 
 Note: These labels will only be triggered if an npcshop* command is executed because these
 commands set a special data on the shop NPC, named master_nd in the source. The above labels

+ 28 - 8
src/map/npc.c

@@ -767,11 +767,11 @@ void npc_timerevent_quit(struct map_session_data* sd)
 		char buf[EVENT_NAME_LENGTH];
 		struct event_data *ev;
 
-		snprintf(buf, ARRAYLENGTH(buf), "%s::OnTimerQuit", nd->exname);
+		snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, script_config.timer_quit_event_name);
 		ev = (struct event_data*)strdb_get(ev_db, buf);
 		if( ev && ev->nd != nd )
 		{
-			ShowWarning("npc_timerevent_quit: Unable to execute \"OnTimerQuit\", two NPCs have the same event name [%s]!\n",buf);
+			ShowWarning("npc_timerevent_quit: Unable to execute \"%s\", two NPCs have the same event name [%s]!\n",script_config.timer_quit_event_name,buf);
 			ev = NULL;
 		}
 		if( ev )
@@ -1719,7 +1719,7 @@ static int npc_buylist_sub(struct map_session_data* sd, uint16 n, struct s_npc_b
 	}
 
 	// invoke event
-	snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnBuyItem", nd->exname);
+	snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::%s", nd->exname, script_config.onbuy_event_name);
 	npc_event(sd, npc_ev, 0);
 
 	return 0;
@@ -1883,6 +1883,7 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
 {
 	char npc_ev[EVENT_NAME_LENGTH];
 	char card_slot[NAME_LENGTH];
+	char option_id[NAME_LENGTH], option_val[NAME_LENGTH], option_param[NAME_LENGTH];
 	int i, j;
 	int key_nameid = 0;
 	int key_amount = 0;
@@ -1890,6 +1891,7 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
 	int key_attribute = 0;
 	int key_identify = 0;
 	int key_card[MAX_SLOTS];
+	int key_option_id[MAX_ITEM_RDM_OPT], key_option_val[MAX_ITEM_RDM_OPT], key_option_param[MAX_ITEM_RDM_OPT];
 
 	// discard old contents
 	script_cleararray_pc(sd, "@sold_nameid", (void*)0);
@@ -1905,12 +1907,21 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
 		script_cleararray_pc(sd, card_slot, (void*)0);
 	}
 
+	for (j = 0; j < MAX_ITEM_RDM_OPT; j++) { // Clear each of the item option entries
+		key_option_id[j] = key_option_val[j] = key_option_param[j] = 0;
+
+		snprintf(option_id, sizeof(option_id), "@sold_option_id%d", j + 1);
+		script_cleararray_pc(sd, option_id, (void *)0);
+		snprintf(option_val, sizeof(option_val), "@sold_option_val%d", j + 1);
+		script_cleararray_pc(sd, option_val, (void *)0);
+		snprintf(option_param, sizeof(option_param), "@sold_option_param%d", j + 1);
+		script_cleararray_pc(sd, option_param, (void *)0);
+	}
+
 	// save list of to be sold items
 	for( i = 0; i < n; i++ )
 	{
-		int idx;
-
-		idx = item_list[i*2]-2;
+		int idx = item_list[i * 2] - 2;
 
 		script_setarray_pc(sd, "@sold_nameid", i, (void*)(intptr_t)sd->inventory.u.items_inventory[idx].nameid, &key_nameid);
 		script_setarray_pc(sd, "@sold_quantity", i, (void*)(intptr_t)item_list[i*2+1], &key_amount);
@@ -1926,11 +1937,20 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
 				snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
 				script_setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->inventory.u.items_inventory[idx].card[j], &key_card[j]);
 			}
+
+			for (j = 0; j < MAX_ITEM_RDM_OPT; j++) { // Store each of the item options in the array
+				snprintf(option_id, sizeof(option_id), "@sold_option_id%d", j + 1);
+				script_setarray_pc(sd, option_id, i, (void*)(intptr_t)sd->inventory.u.items_inventory[idx].option[j].id, &key_option_id[j]);
+				snprintf(option_val, sizeof(option_val), "@sold_option_val%d", j + 1);
+				script_setarray_pc(sd, option_val, i, (void*)(intptr_t)sd->inventory.u.items_inventory[idx].option[j].value, &key_option_val[j]);
+				snprintf(option_param, sizeof(option_param), "@sold_option_param%d", j + 1);
+				script_setarray_pc(sd, option_param, i, (void*)(intptr_t)sd->inventory.u.items_inventory[idx].option[j].param, &key_option_param[j]);
+			}
 		}
 	}
 
 	// invoke event
-	snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnSellItem", nd->exname);
+	snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::%s", nd->exname, script_config.onsell_event_name);
 	npc_event(sd, npc_ev, 0);
 	return 0;
 }
@@ -3065,7 +3085,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 		char evname[EVENT_NAME_LENGTH];
 		struct event_data *ev;
 
-		snprintf(evname, ARRAYLENGTH(evname), "%s::OnInit", nd->exname);
+		snprintf(evname, ARRAYLENGTH(evname), "%s::%s", nd->exname, script_config.init_event_name);
 
 		if( ( ev = (struct event_data*)strdb_get(ev_db, evname) ) ) {
 

+ 3 - 0
src/map/script.cpp

@@ -266,6 +266,8 @@ struct Script_Config script_config = {
 	"OnTouchNPC", //ontouchnpc_event_name (run whenever a monster walks into the OnTouch area)
 	"OnWhisperGlobal",	//onwhisper_event_name (is executed when a player sends a whisper message to the NPC)
 	"OnCommand", //oncommand_event_name (is executed by script command cmdothernpc)
+	"OnBuyItem", //onbuy_event_name (is executed when items are bought)
+	"OnSellItem", //onsell_event_name (is executed when items are sold)
 	// Init related
 	"OnInit", //init_event_name (is executed on all npcs when all npcs were loaded)
 	"OnInterIfInit", //inter_init_event_name (is executed on inter server connection)
@@ -283,6 +285,7 @@ struct Script_Config script_config = {
 	"OnAgitEnd3", //agit_end3_event_name (is executed when WoE TE has ended)
 	// Timer related
 	"OnTimer", //timer_event_name (is executed by a timer at the specific second)
+	"OnTimerQuit", //timer_quit_event_name (is executed when a timer is aborted)
 	"OnMinute", //timer_minute_event_name (is executed by a timer at the specific minute)
 	"OnHour", //timer_hour_event_name (is executed by a timer at the specific hour)
 	"OnClock", //timer_clock_event_name (is executed by a timer at the specific hour and minute)

+ 3 - 0
src/map/script.h

@@ -169,6 +169,8 @@ extern struct Script_Config {
 	const char* ontouchnpc_event_name;
 	const char* onwhisper_event_name;
 	const char* oncommand_event_name;
+	const char* onbuy_event_name;
+	const char* onsell_event_name;
 
 	// Init related
 	const char* init_event_name;
@@ -189,6 +191,7 @@ extern struct Script_Config {
 
 	// Timer related
 	const char* timer_event_name;
+	const char* timer_quit_event_name;
 	const char* timer_minute_event_name;
 	const char* timer_hour_event_name;
 	const char* timer_clock_event_name;