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 25 kB

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