npc.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _NPC_H_
  4. #define _NPC_H_
  5. #include "map.h" // struct block_list
  6. #include "status.h" // struct status_change
  7. #include "unit.h" // struct unit_data
  8. struct block_list;
  9. struct npc_data;
  10. struct view_data;
  11. struct npc_timerevent_list {
  12. int timer,pos;
  13. };
  14. struct npc_label_list {
  15. char name[NAME_LENGTH];
  16. int pos;
  17. };
  18. /// Item list for NPC sell/buy list
  19. struct npc_item_list {
  20. unsigned short nameid;
  21. unsigned int value;
  22. #if PACKETVER >= 20131223
  23. unsigned short qty; ///< Stock counter (Market shop)
  24. uint8 flag; ///< 1: Item added by npcshopitem/npcshopadditem, force load! (Market shop)
  25. #endif
  26. };
  27. /// List of bought/sold item for NPC shops
  28. struct s_npc_buy_list {
  29. unsigned short qty; ///< Amount of item will be bought
  30. unsigned short nameid; ///< ID of item will be bought
  31. };
  32. struct npc_data {
  33. struct block_list bl;
  34. struct unit_data ud; //Because they need to be able to move....
  35. struct view_data *vd;
  36. struct status_change sc; //They can't have status changes, but.. they want the visual opt values.
  37. struct npc_data *master_nd;
  38. short class_,speed,instance_id;
  39. char name[NAME_LENGTH+1];// display name
  40. char exname[NAME_LENGTH+1];// unique npc name
  41. int chat_id,touching_id;
  42. unsigned int next_walktime;
  43. unsigned size : 2;
  44. struct status_data status;
  45. unsigned int level,stat_point;
  46. struct s_npc_params {
  47. unsigned short str, agi, vit, int_, dex, luk;
  48. } params;
  49. void* chatdb; // pointer to a npc_parse struct (see npc_chat.c)
  50. char* path;/* path dir */
  51. enum npc_subtype subtype;
  52. int src_id;
  53. union {
  54. struct {
  55. struct script_code *script;
  56. short xs,ys; // OnTouch area radius
  57. int guild_id;
  58. int timer,timerid,timeramount,rid;
  59. unsigned int timertick;
  60. struct npc_timerevent_list *timer_event;
  61. int label_list_num;
  62. struct npc_label_list *label_list;
  63. } scr;
  64. struct {
  65. struct npc_item_list *shop_item;
  66. uint16 count;
  67. unsigned short itemshop_nameid; // Item Shop cost item ID
  68. char pointshop_str[32]; // Point Shop cost variable name
  69. bool discount;
  70. } shop;
  71. struct {
  72. short xs,ys; // OnTouch area radius
  73. short x,y; // destination coords
  74. unsigned short mapindex; // destination map
  75. } warp;
  76. struct {
  77. struct mob_data *md;
  78. time_t kill_time;
  79. char killer_name[NAME_LENGTH];
  80. } tomb;
  81. } u;
  82. };
  83. #define START_NPC_NUM 110000000
  84. enum actor_classes
  85. {
  86. WARP_CLASS = 45,
  87. HIDDEN_WARP_CLASS = 139,
  88. WARP_DEBUG_CLASS = 722,
  89. FLAG_CLASS = 722,
  90. INVISIBLE_CLASS = 32767,
  91. };
  92. // Old NPC range
  93. #define MAX_NPC_CLASS 1000
  94. // New NPC range
  95. #define MAX_NPC_CLASS2_START 10000
  96. #define MAX_NPC_CLASS2_END 10203
  97. //Checks if a given id is a valid npc id. [Skotlex]
  98. //Since new npcs are added all the time, the max valid value is the one before the first mob (Scorpion = 1001)
  99. #define npcdb_checkid(id) ( ( (id) >= 46 && (id) <= 125) || (id) == HIDDEN_WARP_CLASS || ( (id) > 400 && (id) < MAX_NPC_CLASS ) || (id) == INVISIBLE_CLASS || ( id > MAX_NPC_CLASS2_START && id < MAX_NPC_CLASS2_END ) )
  100. #ifdef PCRE_SUPPORT
  101. void npc_chat_finalize(struct npc_data* nd);
  102. #endif
  103. //Script NPC events.
  104. enum npce_event {
  105. NPCE_LOGIN,
  106. NPCE_LOGOUT,
  107. NPCE_LOADMAP,
  108. NPCE_BASELVUP,
  109. NPCE_JOBLVUP,
  110. NPCE_DIE,
  111. NPCE_KILLPC,
  112. NPCE_KILLNPC,
  113. NPCE_STATCALC,
  114. NPCE_MAX
  115. };
  116. struct view_data* npc_get_viewdata(int class_);
  117. int npc_chat_sub(struct block_list* bl, va_list ap);
  118. int npc_event_dequeue(struct map_session_data* sd);
  119. int npc_event(struct map_session_data* sd, const char* eventname, int ontouch);
  120. int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y);
  121. int npc_touch_areanpc2(struct mob_data *md); // [Skotlex]
  122. int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range);
  123. int npc_touchnext_areanpc(struct map_session_data* sd,bool leavemap);
  124. int npc_click(struct map_session_data* sd, struct npc_data* nd);
  125. int npc_scriptcont(struct map_session_data* sd, int id, bool closing);
  126. struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* bl);
  127. int npc_buysellsel(struct map_session_data* sd, int id, int type);
  128. uint8 npc_buylist(struct map_session_data* sd, uint16 n, struct s_npc_buy_list *item_list);
  129. uint8 npc_selllist(struct map_session_data* sd, int n, unsigned short *item_list);
  130. void npc_parse_mob2(struct spawn_data* mob);
  131. bool npc_viewisid(const char * viewid);
  132. struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y);
  133. int npc_globalmessage(const char* name,const char* mes);
  134. void npc_setcells(struct npc_data* nd);
  135. void npc_unsetcells(struct npc_data* nd);
  136. void npc_movenpc(struct npc_data* nd, int16 x, int16 y);
  137. int npc_enable(const char* name, int flag);
  138. void npc_setdisplayname(struct npc_data* nd, const char* newname);
  139. void npc_setclass(struct npc_data* nd, short class_);
  140. struct npc_data* npc_name2id(const char* name);
  141. int npc_isnear_sub(struct block_list* bl, va_list args);
  142. bool npc_isnear(struct block_list * bl);
  143. int npc_get_new_npc_id(void);
  144. int npc_addsrcfile(const char* name);
  145. void npc_delsrcfile(const char* name);
  146. int npc_parsesrcfile(const char* filepath, bool runOnInit);
  147. void do_clear_npc(void);
  148. void do_final_npc(void);
  149. void do_init_npc(void);
  150. void npc_event_do_oninit(void);
  151. int npc_do_ontimer(int npc_id, int option);
  152. int npc_event_do(const char* name);
  153. int npc_event_do_id(const char* name, int rid);
  154. int npc_event_doall(const char* name);
  155. int npc_event_doall_id(const char* name, int rid);
  156. int npc_timerevent_start(struct npc_data* nd, int rid);
  157. int npc_timerevent_stop(struct npc_data* nd);
  158. void npc_timerevent_quit(struct map_session_data* sd);
  159. int npc_gettimerevent_tick(struct npc_data* nd);
  160. int npc_settimerevent_tick(struct npc_data* nd, int newtimer);
  161. int npc_remove_map(struct npc_data* nd);
  162. void npc_unload_duplicates (struct npc_data* nd);
  163. int npc_unload(struct npc_data* nd, bool single);
  164. int npc_reload(void);
  165. void npc_read_event_script(void);
  166. int npc_script_event(struct map_session_data* sd, enum npce_event type);
  167. int npc_duplicate4instance(struct npc_data *snd, int16 m);
  168. int npc_instanceinit(struct npc_data* nd);
  169. int npc_cashshop_buy(struct map_session_data *sd, unsigned short nameid, int amount, int points);
  170. void npc_shop_currency_type(struct map_session_data *sd, struct npc_data *nd, int cost[2], bool display);
  171. extern struct npc_data* fake_nd;
  172. int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, unsigned short* item_list);
  173. bool npc_shop_discount(enum npc_subtype type, bool discount);
  174. #if PACKETVER >= 20131223
  175. void npc_market_tosql(const char *exname, struct npc_item_list *list);
  176. void npc_market_delfromsql_(const char *exname, unsigned short nameid, bool clear);
  177. #endif
  178. #ifdef SECURE_NPCTIMEOUT
  179. int npc_rr_secure_timeout_timer(int tid, unsigned int tick, int id, intptr_t data);
  180. #endif
  181. // @commands (script-based)
  182. int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const char* message, const char* eventname);
  183. bool npc_unloadfile( const char* path );
  184. #endif /* _NPC_H_ */