battleground.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef BATTLEGROUND_HPP
  4. #define BATTLEGROUND_HPP
  5. #include <memory>
  6. #include <string>
  7. #include <vector>
  8. #include "../common/cbasetypes.hpp"
  9. #include "../common/database.hpp"
  10. #include "../common/mmo.hpp" // struct party
  11. #define MAX_BG_MEMBERS 30
  12. struct s_battleground_member_data {
  13. unsigned short x, y;
  14. map_session_data *sd;
  15. unsigned afk : 1;
  16. struct point entry_point; ///< Battleground queue entry point
  17. };
  18. struct s_battleground_data {
  19. int id; ///< Battleground ID
  20. std::vector<s_battleground_member_data> members; ///< List of players in battleground
  21. struct point cemetery; ///< Respawn point for players who die
  22. std::string logout_event; ///< NPC Event to call on log out events
  23. std::string die_event; ///< NPC Event to call on death events
  24. std::string active_event; ///< NPC Event to call on players joining an active battleground
  25. };
  26. struct s_battleground_team {
  27. uint16 warp_x, warp_y; ///< Team respawn coordinates
  28. std::string quit_event, ///< Team NPC Event to call on log out events
  29. death_event, ///< Team NPC Event to call on death events
  30. active_event, ///< Team NPC Event to call on players joining an active battleground
  31. bg_id_var; ///< Team NPC variable name
  32. };
  33. struct s_battleground_map {
  34. int id; ///< Battleground ID
  35. uint16 mapindex; ///< Index of the map
  36. s_battleground_team team1, team2; ///< Team data
  37. std::string bgcallscript; ///< Script to be called when players join the battleground
  38. bool isReserved; ///< Reserve BG maps that are used so that the system won't create multiple BG instances on the same map
  39. };
  40. /// Enum for queue state tracking
  41. enum e_queue_state : uint16 {
  42. QUEUE_STATE_SETUP = 0, ///< The initial setup of a queue (a required amount of players hasn't been met)
  43. QUEUE_STATE_SETUP_DELAY, ///< The initial setup of a queue but a required amount of players have accepted and the delay timer is active
  44. QUEUE_STATE_ACTIVE, ///< The queue is active script side and more players can join (players may or may not be on the field)
  45. QUEUE_STATE_ENDED, ///< The queue is no longer joinable (players are getting prizes)
  46. };
  47. /// Battlegrounds client interface queue system [MasterOfMuppets]
  48. struct s_battleground_queue {
  49. int queue_id; ///< Battlegrounds Queue ID
  50. int id; ///< Battlegrounds database ID
  51. std::vector<map_session_data *> teama_members; ///< List of members on team A
  52. std::vector<map_session_data *> teamb_members; ///< List of members on team B
  53. int required_players; ///< Amount of players required on each side to start
  54. int max_players; ///< Maximum amount of players on each side
  55. int accepted_players; ///< Amount of players who accepted the offer to enter the battleground
  56. e_queue_state state; ///< See @e_queue_state
  57. int tid_expire; ///< Timer ID associated with the time out at the ready to enter window
  58. int tid_start; ///< Timer ID associated with the start delay
  59. int tid_requeue; ///< Timer ID associated with requeuing this group if all BG maps are reserved
  60. s_battleground_map *map; ///< Map this BG queue has been assigned to
  61. };
  62. struct s_battleground_type {
  63. int id; ///< Battlegrounds database ID
  64. std::string name; ///< Name of the battleground type
  65. int required_players; ///< Amount of players required on each side to start
  66. int max_players; ///< Maximum amount of players on each side
  67. int min_lvl; ///< Minimum level to participate in this battleground type
  68. int max_lvl; ///< Maximum level to participate in this battleground type
  69. std::vector<s_battleground_map> maps; ///< List of battleground locations
  70. uint32 deserter_time; ///< Amount of time a player is marked deserter (seconds)
  71. uint32 start_delay; ///< Amount of time before the start message is sent to players (seconds)
  72. bool solo; ///< Ability to join a queue as an individual.
  73. bool party; ///< Ability to join a queue as a party.
  74. bool guild; ///< Ability to join a queue as a guild.
  75. std::vector<int32> job_restrictions; ///< List of jobs that are unable to join.
  76. };
  77. /// Enum of responses when applying for a Battleground
  78. enum e_bg_queue_apply_ack : uint16 {
  79. BG_APPLY_NONE = 0,
  80. BG_APPLY_ACCEPT, ///< Accept
  81. BG_APPLY_QUEUE_FINISHED, ///< Queuing has finished
  82. BG_APPLY_INVALID_NAME, ///< Invalid name of Battleground
  83. BG_APPLY_INVALID_APP, ///< Invalid application
  84. BG_APPLY_PLAYER_COUNT, ///< Too many players in party/guild
  85. BG_APPLY_PLAYER_LEVEL, ///< Level too low/high
  86. BG_APPLY_DUPLICATE, ///< Duplicate application
  87. BG_APPLY_RECONNECT, ///< Reconnect then apply
  88. BG_APPLY_PARTYGUILD_LEADER, ///< Only party/guild leader can apply
  89. BG_APPLY_PLAYER_CLASS, ///< Your class can't apply
  90. };
  91. /// Enum of script command bg_info types
  92. enum e_bg_info : uint16 {
  93. BG_INFO_ID = 0,
  94. BG_INFO_REQUIRED_PLAYERS,
  95. BG_INFO_MAX_PLAYERS,
  96. BG_INFO_MIN_LEVEL,
  97. BG_INFO_MAX_LEVEL,
  98. BG_INFO_MAPS,
  99. BG_INFO_DESERTER_TIME,
  100. };
  101. class BattlegroundDatabase : public TypesafeYamlDatabase<uint32, s_battleground_type> {
  102. public:
  103. BattlegroundDatabase() : TypesafeYamlDatabase("BATTLEGROUND_DB", 1) {
  104. }
  105. const std::string getDefaultLocation() override;
  106. uint64 parseBodyNode(const ryml::NodeRef& node) override;
  107. };
  108. extern BattlegroundDatabase battleground_db;
  109. extern std::unordered_map<int, std::shared_ptr<s_battleground_data>> bg_team_db;
  110. extern std::vector<std::shared_ptr<s_battleground_queue>> bg_queues;
  111. std::shared_ptr<s_battleground_type> bg_search_name(const char *name);
  112. std::shared_ptr<s_battleground_queue> bg_search_queue(int queue_id);
  113. void bg_send_dot_remove(map_session_data *sd);
  114. int bg_team_get_id(struct block_list *bl);
  115. map_session_data *bg_getavailablesd(s_battleground_data *bg);
  116. bool bg_queue_reservation(const char *name, bool state, bool ended);
  117. #define bg_queue_reserve(name, end) (bg_queue_reservation(name, true, end))
  118. #define bg_queue_unbook(name) (bg_queue_reservation(name, false, false))
  119. int bg_create(uint16 mapindex, s_battleground_team* team);
  120. bool bg_team_join(int bg_id, map_session_data *sd, bool is_queue);
  121. bool bg_team_delete(int bg_id);
  122. int bg_team_leave(map_session_data *sd, bool quit, bool deserter);
  123. bool bg_team_warp(int bg_id, unsigned short mapindex, short x, short y);
  124. bool bg_player_is_in_bg_map(map_session_data *sd);
  125. bool bg_queue_check_joinable(std::shared_ptr<s_battleground_type> bg, map_session_data *sd, const char *name);
  126. void bg_queue_join_solo(const char *name, map_session_data *sd);
  127. void bg_queue_join_party(const char *name, map_session_data *sd);
  128. void bg_queue_join_guild(const char *name, map_session_data *sd);
  129. void bg_queue_join_multi(const char *name, map_session_data *sd, std::vector<map_session_data *> list);
  130. void bg_queue_clear(std::shared_ptr<s_battleground_queue> queue, bool ended);
  131. bool bg_queue_leave(map_session_data *sd, bool apply_sc = true);
  132. bool bg_queue_on_ready(const char *name, std::shared_ptr<s_battleground_queue> queue);
  133. void bg_queue_on_accept_invite(map_session_data *sd);
  134. void bg_queue_start_battleground(std::shared_ptr<s_battleground_queue> queue);
  135. bool bg_member_respawn(map_session_data *sd);
  136. void bg_send_message(map_session_data *sd, const char *mes, int len);
  137. void do_init_battleground(void);
  138. void do_final_battleground(void);
  139. #endif /* BATTLEGROUND_HPP */