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

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