You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.hpp 24 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. // 杂项函数
  2. #pragma once
  3. #ifndef UTILS_HPP
  4. #define UTILS_HPP
  5. #include <cstdint>
  6. #include "Message2Clients.pb.h"
  7. #include "Message2Server.pb.h"
  8. #include "MessageType.pb.h"
  9. #include "structures.h"
  10. namespace AssistFunction
  11. {
  12. constexpr int numOfGridPerCell = 100;
  13. [[nodiscard]] constexpr inline int GridToCell(int grid) noexcept
  14. {
  15. return grid / numOfGridPerCell;
  16. }
  17. inline bool HaveView(int viewRange, int x, int y, int newX, int newY, std::vector<std::vector<THUAI6::PlaceType>>& map)
  18. {
  19. int deltaX = newX - x;
  20. int deltaY = newY - y;
  21. double distance = deltaX * deltaX + deltaY * deltaY;
  22. THUAI6::PlaceType myPlace = map[GridToCell(x)][GridToCell(y)];
  23. THUAI6::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)];
  24. if (newPlace == THUAI6::PlaceType::Grass && myPlace != THUAI6::PlaceType::Grass) // 草丛外必不可能看到草丛内
  25. return false;
  26. if (distance < viewRange * viewRange)
  27. {
  28. int divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100;
  29. if (divide == 0)
  30. return true;
  31. double dx = deltaX / divide;
  32. double dy = deltaY / divide;
  33. double myX = double(x);
  34. double myY = double(y);
  35. if (newPlace == THUAI6::PlaceType::Grass && myPlace == THUAI6::PlaceType::Grass) // 都在草丛内,要另作判断
  36. for (int i = 0; i < divide; i++)
  37. {
  38. myX += dx;
  39. myY += dy;
  40. if (map[GridToCell(myX)][GridToCell(myY)] != THUAI6::PlaceType::Grass)
  41. return false;
  42. }
  43. else // 不在草丛内,只需要没有墙即可
  44. for (int i = 0; i < divide; i++)
  45. {
  46. myX += dx;
  47. myY += dy;
  48. if (map[GridToCell(myX)][GridToCell(myY)] == THUAI6::PlaceType::Wall)
  49. return false;
  50. }
  51. return true;
  52. }
  53. else
  54. return false;
  55. }
  56. } // namespace AssistFunction
  57. // 辅助函数,用于将proto信息转换为THUAI6信息
  58. namespace Proto2THUAI6
  59. {
  60. // 用于将Protobuf中的枚举转换为THUAI6的枚举
  61. inline std::map<protobuf::PlaceType, THUAI6::PlaceType> placeTypeDict{
  62. {protobuf::PlaceType::NULL_PLACE_TYPE, THUAI6::PlaceType::NullPlaceType},
  63. {protobuf::PlaceType::LAND, THUAI6::PlaceType::Land},
  64. {protobuf::PlaceType::WALL, THUAI6::PlaceType::Wall},
  65. {protobuf::PlaceType::GRASS, THUAI6::PlaceType::Grass},
  66. {protobuf::PlaceType::CLASSROOM, THUAI6::PlaceType::ClassRoom},
  67. {protobuf::PlaceType::GATE, THUAI6::PlaceType::Gate},
  68. {protobuf::PlaceType::HIDDEN_GATE, THUAI6::PlaceType::HiddenGate},
  69. {protobuf::PlaceType::WINDOW, THUAI6::PlaceType::Window},
  70. {protobuf::PlaceType::DOOR3, THUAI6::PlaceType::Door3},
  71. {protobuf::PlaceType::DOOR5, THUAI6::PlaceType::Door5},
  72. {protobuf::PlaceType::DOOR6, THUAI6::PlaceType::Door6},
  73. {protobuf::PlaceType::CHEST, THUAI6::PlaceType::Chest},
  74. };
  75. inline std::map<protobuf::ShapeType, THUAI6::ShapeType> shapeTypeDict{
  76. {protobuf::ShapeType::NULL_SHAPE_TYPE, THUAI6::ShapeType::NullShapeType},
  77. {protobuf::ShapeType::CIRCLE, THUAI6::ShapeType::Circle},
  78. {protobuf::ShapeType::SQUARE, THUAI6::ShapeType::Square},
  79. };
  80. inline std::map<protobuf::PropType, THUAI6::PropType> propTypeDict{
  81. {protobuf::PropType::NULL_PROP_TYPE, THUAI6::PropType::NullPropType},
  82. {protobuf::PropType::KEY3, THUAI6::PropType::Key3},
  83. {protobuf::PropType::KEY5, THUAI6::PropType::Key5},
  84. {protobuf::PropType::KEY6, THUAI6::PropType::Key6},
  85. {protobuf::PropType::ADD_SPEED, THUAI6::PropType::AddSpeed},
  86. {protobuf::PropType::ADD_HP_OR_AP, THUAI6::PropType::AddHpOrAp},
  87. {protobuf::PropType::ADD_LIFE_OR_AP, THUAI6::PropType::AddLifeOrAp},
  88. {protobuf::PropType::SHIELD_OR_SPEAR, THUAI6::PropType::ShieldOrSpear},
  89. };
  90. inline std::map<protobuf::PlayerType, THUAI6::PlayerType> playerTypeDict{
  91. {protobuf::PlayerType::NULL_PLAYER_TYPE, THUAI6::PlayerType::NullPlayerType},
  92. {protobuf::PlayerType::STUDENT_PLAYER, THUAI6::PlayerType::StudentPlayer},
  93. {protobuf::PlayerType::TRICKER_PLAYER, THUAI6::PlayerType::TrickerPlayer},
  94. };
  95. inline std::map<protobuf::StudentType, THUAI6::StudentType> studentTypeDict{
  96. {protobuf::StudentType::NULL_STUDENT_TYPE, THUAI6::StudentType::NullStudentType},
  97. {protobuf::StudentType::ATHLETE, THUAI6::StudentType::Athlete},
  98. {protobuf::StudentType::STUDENTTYPE2, THUAI6::StudentType::StudentType2},
  99. {protobuf::StudentType::STUDENTTYPE3, THUAI6::StudentType::StudentType3},
  100. {protobuf::StudentType::STUDENTTYPE4, THUAI6::StudentType::StudentType4},
  101. };
  102. inline std::map<protobuf::TrickerType, THUAI6::TrickerType> trickerTypeDict{
  103. {protobuf::TrickerType::NULL_TRICKER_TYPE, THUAI6::TrickerType::NullTrickerType},
  104. {protobuf::TrickerType::ASSASSIN, THUAI6::TrickerType::Assassin},
  105. {protobuf::TrickerType::TRICKERTYPE2, THUAI6::TrickerType::TrickerType2},
  106. {protobuf::TrickerType::TRICKERTYPE3, THUAI6::TrickerType::TrickerType3},
  107. {protobuf::TrickerType::TRICKERTYPE4, THUAI6::TrickerType::TrickerType4},
  108. };
  109. inline std::map<protobuf::StudentBuffType, THUAI6::StudentBuffType> studentBuffTypeDict{
  110. {protobuf::StudentBuffType::NULL_SBUFF_TYPE, THUAI6::StudentBuffType::NullStudentBuffType},
  111. {protobuf::StudentBuffType::SBUFFTYPE1, THUAI6::StudentBuffType::StudentBuffType1},
  112. {protobuf::StudentBuffType::SBUFFTYPE2, THUAI6::StudentBuffType::StudentBuffType2},
  113. {protobuf::StudentBuffType::SBUFFTYPE3, THUAI6::StudentBuffType::StudentBuffType3},
  114. {protobuf::StudentBuffType::SBUFFTYPE4, THUAI6::StudentBuffType::StudentBuffType4},
  115. };
  116. inline std::map<protobuf::TrickerBuffType, THUAI6::TrickerBuffType> trickerBuffTypeDict{
  117. {protobuf::TrickerBuffType::NULL_TBUFF_TYPE, THUAI6::TrickerBuffType::NullTrickerBuffType},
  118. {protobuf::TrickerBuffType::TBUFFTYPE1, THUAI6::TrickerBuffType::TrickerBuffType1},
  119. {protobuf::TrickerBuffType::TBUFFTYPE2, THUAI6::TrickerBuffType::TrickerBuffType2},
  120. {protobuf::TrickerBuffType::TBUFFTYPE3, THUAI6::TrickerBuffType::TrickerBuffType3},
  121. {protobuf::TrickerBuffType::TBUFFTYPE4, THUAI6::TrickerBuffType::TrickerBuffType4},
  122. };
  123. inline std::map<protobuf::PlayerState, THUAI6::PlayerState> playerStateDict{
  124. {protobuf::PlayerState::NULL_STATUS, THUAI6::PlayerState::NullState},
  125. {protobuf::PlayerState::IDLE, THUAI6::PlayerState::Idle},
  126. {protobuf::PlayerState::LEARNING, THUAI6::PlayerState::Learning},
  127. {protobuf::PlayerState::ADDICTED, THUAI6::PlayerState::Addicted},
  128. {protobuf::PlayerState::QUIT, THUAI6::PlayerState::Quit},
  129. {protobuf::PlayerState::GRADUATED, THUAI6::PlayerState::Graduated},
  130. {protobuf::PlayerState::RESCUED, THUAI6::PlayerState::Rescued},
  131. {protobuf::PlayerState::TREATED, THUAI6::PlayerState::Treated},
  132. {protobuf::PlayerState::STUNNED, THUAI6::PlayerState::Stunned},
  133. {protobuf::PlayerState::RESCUING, THUAI6::PlayerState::Rescuing},
  134. {protobuf::PlayerState::TREATING, THUAI6::PlayerState::Treating},
  135. {protobuf::PlayerState::SWINGING, THUAI6::PlayerState::Swinging},
  136. {protobuf::PlayerState::ATTACKING, THUAI6::PlayerState::Attacking},
  137. {protobuf::PlayerState::LOCKING, THUAI6::PlayerState::Locking},
  138. {protobuf::PlayerState::RUMMAGING, THUAI6::PlayerState::Rummaging},
  139. {protobuf::PlayerState::CLIMBING, THUAI6::PlayerState::Climbing},
  140. {protobuf::PlayerState::OPENING_A_CHEST, THUAI6::PlayerState::OpeningAChest},
  141. {protobuf::PlayerState::USING_SPECIAL_SKILL, THUAI6::PlayerState::UsingSpecialSkill},
  142. {protobuf::PlayerState::OPENING_A_GATE, THUAI6::PlayerState::OpeningAGate},
  143. };
  144. inline std::map<protobuf::GameState, THUAI6::GameState> gameStateDict{
  145. {protobuf::GameState::NULL_GAME_STATE, THUAI6::GameState::NullGameState},
  146. {protobuf::GameState::GAME_START, THUAI6::GameState::GameStart},
  147. {protobuf::GameState::GAME_RUNNING, THUAI6::GameState::GameRunning},
  148. {protobuf::GameState::GAME_END, THUAI6::GameState::GameEnd},
  149. };
  150. inline std::map<protobuf::BulletType, THUAI6::BulletType> bulletTypeDict{
  151. {protobuf::BulletType::NULL_BULLET_TYPE, THUAI6::BulletType::NullBulletType},
  152. {protobuf::BulletType::FLYING_KNIFE, THUAI6::BulletType::FlyingKnife},
  153. {protobuf::BulletType::COMMON_ATTACK_OF_TRICKER, THUAI6::BulletType::CommonAttackOfTricker},
  154. {protobuf::BulletType::FAST_BULLET, THUAI6::BulletType::FastBullet},
  155. {protobuf::BulletType::ORDINARY_BULLET, THUAI6::BulletType::OrdinaryBullet},
  156. {protobuf::BulletType::ATOM_BOMB, THUAI6::BulletType::AtomBomb},
  157. };
  158. inline std::map<protobuf::MessageOfObj::MessageOfObjCase, THUAI6::MessageOfObj> messageOfObjDict{
  159. {protobuf::MessageOfObj::MessageOfObjCase::kStudentMessage, THUAI6::MessageOfObj::StudentMessage},
  160. {protobuf::MessageOfObj::MessageOfObjCase::kTrickerMessage, THUAI6::MessageOfObj::TrickerMessage},
  161. {protobuf::MessageOfObj::MessageOfObjCase::kPropMessage, THUAI6::MessageOfObj::PropMessage},
  162. {protobuf::MessageOfObj::MessageOfObjCase::kBulletMessage, THUAI6::MessageOfObj::BulletMessage},
  163. {protobuf::MessageOfObj::MessageOfObjCase::kBombedBulletMessage, THUAI6::MessageOfObj::BombedBulletMessage},
  164. {protobuf::MessageOfObj::MessageOfObjCase::kClassroomMessage, THUAI6::MessageOfObj::ClassroomMessage},
  165. {protobuf::MessageOfObj::MessageOfObjCase::kDoorMessage, THUAI6::MessageOfObj::DoorMessage},
  166. {protobuf::MessageOfObj::MessageOfObjCase::kGateMessage, THUAI6::MessageOfObj::GateMessage},
  167. {protobuf::MessageOfObj::MessageOfObjCase::kChestMessage, THUAI6::MessageOfObj::ChestMessage},
  168. {protobuf::MessageOfObj::MessageOfObjCase::MESSAGE_OF_OBJ_NOT_SET, THUAI6::MessageOfObj::NullMessageOfObj},
  169. {protobuf::MessageOfObj::MessageOfObjCase::kMapMessage, THUAI6::MessageOfObj::MapMessage},
  170. {protobuf::MessageOfObj::MessageOfObjCase::kNewsMessage, THUAI6::MessageOfObj::NewsMessage},
  171. {protobuf::MessageOfObj::MessageOfObjCase::kHiddenGateMessage, THUAI6::MessageOfObj::HiddenGateMessage},
  172. };
  173. // 用于将Protobuf中的类转换为THUAI6的类
  174. inline std::shared_ptr<THUAI6::Tricker> Protobuf2THUAI6Tricker(const protobuf::MessageOfTricker& trickerMsg)
  175. {
  176. auto tricker = std::make_shared<THUAI6::Tricker>();
  177. tricker->x = trickerMsg.x();
  178. tricker->y = trickerMsg.y();
  179. tricker->speed = trickerMsg.speed();
  180. tricker->score = trickerMsg.score();
  181. tricker->facingDirection = trickerMsg.facing_direction();
  182. tricker->bulletType = bulletTypeDict[trickerMsg.bullet_type()];
  183. tricker->trickDesire = trickerMsg.trick_desire();
  184. tricker->classVolume = trickerMsg.class_volume();
  185. for (int i = 0; i < trickerMsg.time_until_skill_available().size(); i++)
  186. tricker->timeUntilSkillAvailable.push_back(trickerMsg.time_until_skill_available(i));
  187. tricker->place = placeTypeDict[trickerMsg.place()];
  188. tricker->playerState = playerStateDict[trickerMsg.player_state()];
  189. for (int i = 0; i < trickerMsg.prop().size(); i++)
  190. tricker->props.push_back(propTypeDict[trickerMsg.prop(i)]);
  191. tricker->trickerType = trickerTypeDict[trickerMsg.tricker_type()];
  192. tricker->guid = trickerMsg.guid();
  193. tricker->playerID = trickerMsg.player_id();
  194. tricker->viewRange = trickerMsg.view_range();
  195. tricker->radius = trickerMsg.radius();
  196. tricker->playerType = THUAI6::PlayerType::TrickerPlayer;
  197. tricker->buff.clear();
  198. for (int i = 0; i < trickerMsg.buff().size(); i++)
  199. tricker->buff.push_back(trickerBuffTypeDict[trickerMsg.buff(i)]);
  200. return tricker;
  201. }
  202. inline std::shared_ptr<THUAI6::Student> Protobuf2THUAI6Student(const protobuf::MessageOfStudent& studentMsg)
  203. {
  204. auto student = std::make_shared<THUAI6::Student>();
  205. student->x = studentMsg.x();
  206. student->y = studentMsg.y();
  207. student->speed = studentMsg.speed();
  208. student->viewRange = studentMsg.view_range();
  209. student->playerID = studentMsg.player_id();
  210. student->guid = studentMsg.guid();
  211. student->radius = studentMsg.radius();
  212. student->score = studentMsg.score();
  213. student->facingDirection = studentMsg.facing_direction();
  214. student->bulletType = bulletTypeDict[studentMsg.bullet_type()];
  215. student->learningSpeed = studentMsg.learning_speed();
  216. student->treatSpeed = studentMsg.treat_speed();
  217. student->treatProgress = studentMsg.treat_progress();
  218. student->rescueProgress = studentMsg.rescue_progress();
  219. student->dangerAlert = studentMsg.danger_alert();
  220. for (int i = 0; i < studentMsg.time_until_skill_available().size(); i++)
  221. student->timeUntilSkillAvailable.push_back(studentMsg.time_until_skill_available(i));
  222. student->playerType = THUAI6::PlayerType::StudentPlayer;
  223. for (int i = 0; i < studentMsg.prop().size(); i++)
  224. student->props.push_back(propTypeDict[studentMsg.prop(i)]);
  225. student->place = placeTypeDict[studentMsg.place()];
  226. student->playerState = playerStateDict[studentMsg.player_state()];
  227. student->determination = studentMsg.determination();
  228. student->addiction = studentMsg.addiction();
  229. student->studentType = studentTypeDict[studentMsg.student_type()];
  230. student->buff.clear();
  231. for (int i = 0; i < studentMsg.buff_size(); i++)
  232. student->buff.push_back(studentBuffTypeDict[studentMsg.buff(i)]);
  233. return student;
  234. }
  235. inline std::shared_ptr<THUAI6::Prop> Protobuf2THUAI6Prop(const protobuf::MessageOfProp& propMsg)
  236. {
  237. auto prop = std::make_shared<THUAI6::Prop>();
  238. prop->x = propMsg.x();
  239. prop->y = propMsg.y();
  240. prop->type = propTypeDict[propMsg.type()];
  241. prop->place = placeTypeDict[propMsg.place()];
  242. prop->guid = propMsg.guid();
  243. prop->facingDirection = propMsg.facing_direction();
  244. return prop;
  245. }
  246. inline std::shared_ptr<THUAI6::GameInfo> Protobuf2THUAI6GameInfo(const protobuf::MessageOfAll& allMsg)
  247. {
  248. auto gameInfo = std::make_shared<THUAI6::GameInfo>();
  249. gameInfo->gameTime = allMsg.game_time();
  250. gameInfo->subjectLeft = allMsg.subject_left();
  251. gameInfo->studentGraduated = allMsg.student_graduated();
  252. gameInfo->studentQuited = allMsg.student_quited();
  253. gameInfo->studentScore = allMsg.student_score();
  254. gameInfo->trickerScore = allMsg.tricker_score();
  255. return gameInfo;
  256. }
  257. inline std::shared_ptr<THUAI6::Bullet> Protobuf2THUAI6Bullet(const protobuf::MessageOfBullet& bulletMsg)
  258. {
  259. auto bullet = std::make_shared<THUAI6::Bullet>();
  260. bullet->bulletType = bulletTypeDict[bulletMsg.type()];
  261. bullet->x = bulletMsg.x();
  262. bullet->y = bulletMsg.y();
  263. bullet->facingDirection = bulletMsg.facing_direction();
  264. bullet->guid = bulletMsg.guid();
  265. bullet->team = playerTypeDict[bulletMsg.team()];
  266. bullet->place = placeTypeDict[bulletMsg.place()];
  267. bullet->bombRange = bulletMsg.bomb_range();
  268. bullet->speed = bulletMsg.speed();
  269. return bullet;
  270. }
  271. inline std::shared_ptr<THUAI6::BombedBullet> Protobuf2THUAI6BombedBullet(const protobuf::MessageOfBombedBullet& bombedBulletMsg)
  272. {
  273. auto bombedBullet = std::make_shared<THUAI6::BombedBullet>();
  274. bombedBullet->bulletType = bulletTypeDict[bombedBulletMsg.type()];
  275. bombedBullet->x = bombedBulletMsg.x();
  276. bombedBullet->y = bombedBulletMsg.y();
  277. bombedBullet->facingDirection = bombedBulletMsg.facing_direction();
  278. bombedBullet->mappingID = bombedBulletMsg.mapping_id();
  279. bombedBullet->bombRange = bombedBulletMsg.bomb_range();
  280. return bombedBullet;
  281. }
  282. inline THUAI6::HiddenGateState Bool2HiddenGateState(bool gateMsg)
  283. {
  284. if (gateMsg)
  285. return THUAI6::HiddenGateState::Opened;
  286. else
  287. return THUAI6::HiddenGateState::Refreshed;
  288. }
  289. } // namespace Proto2THUAI6
  290. namespace THUAI62Proto
  291. {
  292. // 用于将THUAI6的枚举转换为Protobuf的枚举
  293. inline std::map<THUAI6::PlaceType, protobuf::PlaceType> placeTypeDict{
  294. {THUAI6::PlaceType::NullPlaceType, protobuf::PlaceType::NULL_PLACE_TYPE},
  295. {THUAI6::PlaceType::Land, protobuf::PlaceType::LAND},
  296. {THUAI6::PlaceType::Wall, protobuf::PlaceType::WALL},
  297. {THUAI6::PlaceType::Grass, protobuf::PlaceType::GRASS},
  298. {THUAI6::PlaceType::ClassRoom, protobuf::PlaceType::CLASSROOM},
  299. {THUAI6::PlaceType::Gate, protobuf::PlaceType::GATE},
  300. {THUAI6::PlaceType::HiddenGate, protobuf::PlaceType::HIDDEN_GATE},
  301. {THUAI6::PlaceType::Door3, protobuf::PlaceType::DOOR3},
  302. {THUAI6::PlaceType::Door5, protobuf::PlaceType::DOOR5},
  303. {THUAI6::PlaceType::Door6, protobuf::PlaceType::DOOR6},
  304. {THUAI6::PlaceType::Window, protobuf::PlaceType::WINDOW},
  305. };
  306. inline std::map<THUAI6::ShapeType, protobuf::ShapeType> shapeTypeDict{
  307. {THUAI6::ShapeType::NullShapeType, protobuf::ShapeType::NULL_SHAPE_TYPE},
  308. {THUAI6::ShapeType::Circle, protobuf::ShapeType::CIRCLE},
  309. {THUAI6::ShapeType::Square, protobuf::ShapeType::SQUARE},
  310. };
  311. inline std::map<THUAI6::PropType, protobuf::PropType> propTypeDict{
  312. {THUAI6::PropType::NullPropType, protobuf::PropType::NULL_PROP_TYPE},
  313. {THUAI6::PropType::Key3, protobuf::PropType::KEY3},
  314. {THUAI6::PropType::Key5, protobuf::PropType::KEY5},
  315. {THUAI6::PropType::Key6, protobuf::PropType::KEY6},
  316. {THUAI6::PropType::AddHpOrAp, protobuf::PropType::ADD_HP_OR_AP},
  317. {THUAI6::PropType::AddLifeOrAp, protobuf::PropType::ADD_LIFE_OR_AP},
  318. {THUAI6::PropType::AddSpeed, protobuf::PropType::ADD_SPEED},
  319. {THUAI6::PropType::ShieldOrSpear, protobuf::PropType::SHIELD_OR_SPEAR},
  320. };
  321. inline std::map<THUAI6::PlayerType, protobuf::PlayerType> playerTypeDict{
  322. {THUAI6::PlayerType::NullPlayerType, protobuf::PlayerType::NULL_PLAYER_TYPE},
  323. {THUAI6::PlayerType::StudentPlayer, protobuf::PlayerType::STUDENT_PLAYER},
  324. {THUAI6::PlayerType::TrickerPlayer, protobuf::PlayerType::TRICKER_PLAYER},
  325. };
  326. inline std::map<THUAI6::StudentType, protobuf::StudentType> studentTypeDict{
  327. {THUAI6::StudentType::NullStudentType, protobuf::StudentType::NULL_STUDENT_TYPE},
  328. {THUAI6::StudentType::Athlete, protobuf::StudentType::ATHLETE},
  329. {THUAI6::StudentType::StudentType2, protobuf::StudentType::STUDENTTYPE2},
  330. {THUAI6::StudentType::StudentType3, protobuf::StudentType::STUDENTTYPE3},
  331. {THUAI6::StudentType::StudentType4, protobuf::StudentType::STUDENTTYPE4},
  332. };
  333. // inline std::map<THUAI6::StudentBuffType, protobuf::StudentBuffType> studentBuffTypeDict{
  334. // {THUAI6::StudentBuffType::NullStudentBuffType, protobuf::StudentBuffType::NULL_SBUFF_TYPE},
  335. // {THUAI6::StudentBuffType::StudentBuffType1, protobuf::StudentBuffType::SBUFFTYPE1},
  336. // {THUAI6::StudentBuffType::StudentBuffType2, protobuf::StudentBuffType::SBUFFTYPE2},
  337. // {THUAI6::StudentBuffType::StudentBuffType3, protobuf::StudentBuffType::SBUFFTYPE3},
  338. // {THUAI6::StudentBuffType::StudentBuffType4, protobuf::StudentBuffType::SBUFFTYPE4},
  339. // };
  340. inline std::map<THUAI6::TrickerType, protobuf::TrickerType> trickerTypeDict{
  341. {THUAI6::TrickerType::NullTrickerType, protobuf::TrickerType::NULL_TRICKER_TYPE},
  342. {THUAI6::TrickerType::Assassin, protobuf::TrickerType::ASSASSIN},
  343. {THUAI6::TrickerType::TrickerType2, protobuf::TrickerType::TRICKERTYPE2},
  344. {THUAI6::TrickerType::TrickerType3, protobuf::TrickerType::TRICKERTYPE3},
  345. {THUAI6::TrickerType::TrickerType4, protobuf::TrickerType::TRICKERTYPE4},
  346. };
  347. // inline std::map<THUAI6::TrickerBuffType, protobuf::TrickerBuffType> trickerBuffTypeDict{
  348. // {THUAI6::TrickerBuffType::NullTrickerBuffType, protobuf::TrickerBuffType::NULL_TBUFF_TYPE},
  349. // {THUAI6::TrickerBuffType::TrickerBuffType1, protobuf::TrickerBuffType::TBUFFTYPE1},
  350. // {THUAI6::TrickerBuffType::TrickerBuffType2, protobuf::TrickerBuffType::TBUFFTYPE2},
  351. // {THUAI6::TrickerBuffType::TrickerBuffType3, protobuf::TrickerBuffType::TBUFFTYPE3},
  352. // {THUAI6::TrickerBuffType::TrickerBuffType4, protobuf::TrickerBuffType::TBUFFTYPE4},
  353. // };
  354. // 用于将THUAI6的类转换为Protobuf的消息
  355. inline protobuf::PlayerMsg THUAI62ProtobufPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::StudentType studentType, THUAI6::TrickerType trickerType)
  356. {
  357. protobuf::PlayerMsg playerMsg;
  358. playerMsg.set_player_id(playerID);
  359. playerMsg.set_player_type(playerTypeDict[playerType]);
  360. if (playerType == THUAI6::PlayerType::StudentPlayer)
  361. {
  362. playerMsg.set_player_type(protobuf::PlayerType::STUDENT_PLAYER);
  363. playerMsg.set_student_type(studentTypeDict[studentType]);
  364. }
  365. else if (playerType == THUAI6::PlayerType::TrickerPlayer)
  366. {
  367. playerMsg.set_player_type(protobuf::PlayerType::TRICKER_PLAYER);
  368. playerMsg.set_tricker_type(trickerTypeDict[trickerType]);
  369. }
  370. return playerMsg;
  371. }
  372. inline protobuf::IDMsg THUAI62ProtobufID(int playerID)
  373. {
  374. protobuf::IDMsg idMsg;
  375. idMsg.set_player_id(playerID);
  376. return idMsg;
  377. }
  378. inline protobuf::TreatAndRescueMsg THUAI62ProtobufTreatAndRescue(int64_t playerID, int64_t mateID)
  379. {
  380. protobuf::TreatAndRescueMsg treatAndRescueMsg;
  381. treatAndRescueMsg.set_player_id(playerID);
  382. treatAndRescueMsg.set_to_player_id(mateID);
  383. return treatAndRescueMsg;
  384. }
  385. inline protobuf::MoveMsg THUAI62ProtobufMove(int64_t time, double angle, int64_t id)
  386. {
  387. protobuf::MoveMsg moveMsg;
  388. moveMsg.set_time_in_milliseconds(time);
  389. moveMsg.set_angle(angle);
  390. moveMsg.set_player_id(id);
  391. return moveMsg;
  392. }
  393. inline protobuf::PropMsg THUAI62ProtobufProp(THUAI6::PropType prop, int64_t id)
  394. {
  395. protobuf::PropMsg pickMsg;
  396. pickMsg.set_prop_type(propTypeDict[prop]);
  397. pickMsg.set_player_id(id);
  398. return pickMsg;
  399. }
  400. inline protobuf::SendMsg THUAI62ProtobufSend(std::string msg, int64_t toID, int64_t id)
  401. {
  402. protobuf::SendMsg sendMsg;
  403. sendMsg.set_message(msg);
  404. sendMsg.set_to_player_id(toID);
  405. sendMsg.set_player_id(id);
  406. return sendMsg;
  407. }
  408. inline protobuf::AttackMsg THUAI62ProtobufAttack(double angle, int64_t id)
  409. {
  410. protobuf::AttackMsg attackMsg;
  411. attackMsg.set_angle(angle);
  412. attackMsg.set_player_id(id);
  413. return attackMsg;
  414. }
  415. inline protobuf::SkillMsg THUAI62ProtobufSkill(int32_t skillID, int64_t id)
  416. {
  417. protobuf::SkillMsg skillMsg;
  418. skillMsg.set_skill_id(skillID);
  419. skillMsg.set_player_id(id);
  420. return skillMsg;
  421. }
  422. } // namespace THUAI62Proto
  423. namespace Time
  424. {
  425. inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp)
  426. {
  427. std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
  428. std::chrono::duration<double, std::milli> time_span = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(tp - sp);
  429. return time_span.count();
  430. }
  431. } // namespace Time
  432. #endif