npc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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+1];
  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[NPC_NAME_LENGTH+1];// display name
  40. char exname[NPC_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. int spawn_timer;
  81. } tomb;
  82. } u;
  83. };
  84. #define START_NPC_NUM 110000000
  85. enum actor_classes
  86. {
  87. WARP_CLASS = 45,
  88. HIDDEN_WARP_CLASS = 139,
  89. WARP_DEBUG_CLASS = 722,
  90. FLAG_CLASS = 722,
  91. INVISIBLE_CLASS = 32767,
  92. };
  93. // Old NPC range
  94. #define MAX_NPC_CLASS 1000
  95. // New NPC range
  96. #define MAX_NPC_CLASS2_START 10000
  97. #define MAX_NPC_CLASS2_END 10236
  98. //Checks if a given id is a valid npc id. [Skotlex]
  99. //Since new npcs are added all the time, the max valid value is the one before the first mob (Scorpion = 1001)
  100. #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 ) )
  101. #ifdef PCRE_SUPPORT
  102. void npc_chat_finalize(struct npc_data* nd);
  103. #endif
  104. //Script NPC events.
  105. enum npce_event {
  106. NPCE_LOGIN,
  107. NPCE_LOGOUT,
  108. NPCE_LOADMAP,
  109. NPCE_BASELVUP,
  110. NPCE_JOBLVUP,
  111. NPCE_DIE,
  112. NPCE_KILLPC,
  113. NPCE_KILLNPC,
  114. NPCE_STATCALC,
  115. NPCE_MAX
  116. };
  117. struct view_data* npc_get_viewdata(int class_);
  118. int npc_chat_sub(struct block_list* bl, va_list ap);
  119. int npc_event_dequeue(struct map_session_data* sd);
  120. int npc_event(struct map_session_data* sd, const char* eventname, int ontouch);
  121. int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y);
  122. int npc_touch_areanpc2(struct mob_data *md); // [Skotlex]
  123. int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range);
  124. int npc_touchnext_areanpc(struct map_session_data* sd,bool leavemap);
  125. int npc_click(struct map_session_data* sd, struct npc_data* nd);
  126. int npc_scriptcont(struct map_session_data* sd, int id, bool closing);
  127. struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* bl);
  128. int npc_buysellsel(struct map_session_data* sd, int id, int type);
  129. uint8 npc_buylist(struct map_session_data* sd, uint16 n, struct s_npc_buy_list *item_list);
  130. uint8 npc_selllist(struct map_session_data* sd, int n, unsigned short *item_list);
  131. void npc_parse_mob2(struct spawn_data* mob);
  132. bool npc_viewisid(const char * viewid);
  133. 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);
  134. int npc_globalmessage(const char* name,const char* mes);
  135. void npc_setcells(struct npc_data* nd);
  136. void npc_unsetcells(struct npc_data* nd);
  137. void npc_movenpc(struct npc_data* nd, int16 x, int16 y);
  138. int npc_enable(const char* name, int flag);
  139. void npc_setdisplayname(struct npc_data* nd, const char* newname);
  140. void npc_setclass(struct npc_data* nd, short class_);
  141. struct npc_data* npc_name2id(const char* name);
  142. int npc_isnear_sub(struct block_list* bl, va_list args);
  143. bool npc_isnear(struct block_list * bl);
  144. int npc_get_new_npc_id(void);
  145. int npc_addsrcfile(const char* name, bool loadscript);
  146. void npc_delsrcfile(const char* name);
  147. int npc_parsesrcfile(const char* filepath, bool runOnInit);
  148. void do_clear_npc(void);
  149. void do_final_npc(void);
  150. void do_init_npc(void);
  151. void npc_event_do_oninit(void);
  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. void npc_event_runall( const char* eventname );
  156. int npc_event_doall_id(const char* name, int rid);
  157. int npc_timerevent_start(struct npc_data* nd, int rid);
  158. int npc_timerevent_stop(struct npc_data* nd);
  159. void npc_timerevent_quit(struct map_session_data* sd);
  160. int npc_gettimerevent_tick(struct npc_data* nd);
  161. int npc_settimerevent_tick(struct npc_data* nd, int newtimer);
  162. int npc_remove_map(struct npc_data* nd);
  163. void npc_unload_duplicates (struct npc_data* nd);
  164. int npc_unload(struct npc_data* nd, bool single);
  165. int npc_reload(void);
  166. void npc_read_event_script(void);
  167. int npc_script_event(struct map_session_data* sd, enum npce_event type);
  168. int npc_duplicate4instance(struct npc_data *snd, int16 m);
  169. int npc_instanceinit(struct npc_data* nd);
  170. int npc_instancedestroy(struct npc_data* nd);
  171. int npc_cashshop_buy(struct map_session_data *sd, unsigned short nameid, int amount, int points);
  172. void npc_shop_currency_type(struct map_session_data *sd, struct npc_data *nd, int cost[2], bool display);
  173. extern struct npc_data* fake_nd;
  174. int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, unsigned short* item_list);
  175. bool npc_shop_discount(enum npc_subtype type, bool discount);
  176. #if PACKETVER >= 20131223
  177. void npc_market_tosql(const char *exname, struct npc_item_list *list);
  178. void npc_market_delfromsql_(const char *exname, unsigned short nameid, bool clear);
  179. #endif
  180. #ifdef SECURE_NPCTIMEOUT
  181. int npc_rr_secure_timeout_timer(int tid, unsigned int tick, int id, intptr_t data);
  182. #endif
  183. // @commands (script-based)
  184. int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const char* message, const char* eventname);
  185. bool npc_unloadfile( const char* path );
  186. #endif /* _NPC_H_ */