| @@ -34,6 +34,7 @@ public: | |||||
| virtual std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const = 0; | virtual std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const = 0; | ||||
| virtual std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const = 0; | virtual std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const = 0; | ||||
| virtual THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const = 0; | |||||
| // 供IAPI使用的操作相关的部分 | // 供IAPI使用的操作相关的部分 | ||||
| virtual bool Move(int64_t time, double angle) = 0; | virtual bool Move(int64_t time, double angle) = 0; | ||||
| @@ -42,17 +43,17 @@ public: | |||||
| virtual bool UseSkill() = 0; | virtual bool UseSkill() = 0; | ||||
| virtual bool SendMessage(int64_t toID, std::string message) = 0; | virtual bool SendMessage(int64_t toID, std::string message) = 0; | ||||
| virtual bool HaveMessage() = 0; | virtual bool HaveMessage() = 0; | ||||
| virtual std::pair<std::string, int64_t> GetMessage() = 0; | |||||
| virtual std::pair<int64_t, std::string> GetMessage() = 0; | |||||
| virtual bool Escape() = 0; | virtual bool Escape() = 0; | ||||
| // 说明:双向stream由三个函数共同实现,两个记录开始和结束,结果由Logic里的私有的成员变量记录,获得返回值则另调函数 | // 说明:双向stream由三个函数共同实现,两个记录开始和结束,结果由Logic里的私有的成员变量记录,获得返回值则另调函数 | ||||
| virtual bool StartFixMachine() = 0; | |||||
| virtual bool EndFixMachine() = 0; | |||||
| virtual void StartFixMachine() = 0; | |||||
| virtual void EndFixMachine() = 0; | |||||
| virtual bool GetFixStatus() = 0; | virtual bool GetFixStatus() = 0; | ||||
| virtual bool StartSaveHuman() = 0; | |||||
| virtual bool EndSaveHuman() = 0; | |||||
| virtual void StartSaveHuman() = 0; | |||||
| virtual void EndSaveHuman() = 0; | |||||
| virtual bool GetSaveStatus() = 0; | virtual bool GetSaveStatus() = 0; | ||||
| virtual bool Attack(double angle) = 0; | virtual bool Attack(double angle) = 0; | ||||
| @@ -128,11 +129,11 @@ class IHumanAPI : public IAPI | |||||
| public: | public: | ||||
| /*****人类阵营的特定函数*****/ | /*****人类阵营的特定函数*****/ | ||||
| virtual std::future<bool> StartFixMachine() = 0; | |||||
| virtual std::future<bool> EndFixMachine() = 0; | |||||
| virtual void StartFixMachine() = 0; | |||||
| virtual void EndFixMachine() = 0; | |||||
| virtual std::future<bool> GetFixStatus() = 0; | virtual std::future<bool> GetFixStatus() = 0; | ||||
| virtual std::future<bool> StartSaveHuman() = 0; | |||||
| virtual std::future<bool> EndSaveHuman() = 0; | |||||
| virtual void StartSaveHuman() = 0; | |||||
| virtual void EndSaveHuman() = 0; | |||||
| virtual std::future<bool> GetSaveStatus() = 0; | virtual std::future<bool> GetSaveStatus() = 0; | ||||
| virtual std::future<bool> Escape() = 0; | virtual std::future<bool> Escape() = 0; | ||||
| [[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const = 0; | [[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const = 0; | ||||
| @@ -189,12 +190,8 @@ public: | |||||
| std::future<bool> UseSkill() override; | std::future<bool> UseSkill() override; | ||||
| std::future<bool> SendMessage(int64_t, std::string) override; | std::future<bool> SendMessage(int64_t, std::string) override; | ||||
| [[nodiscard]] std::future<bool> HaveMessage() override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::future<bool> HaveMessage() override; | |||||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override; | |||||
| std::future<bool> Wait() override | std::future<bool> Wait() override | ||||
| { | { | ||||
| @@ -206,38 +203,20 @@ public: | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override; | [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override; | ||||
| [[nodiscard]] std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | [[nodiscard]] std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | ||||
| [[nodiscard]] THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override; | |||||
| [[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override | [[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override | ||||
| { | { | ||||
| } | } | ||||
| std::future<bool> StartFixMachine() override | |||||
| { | |||||
| } | |||||
| std::future<bool> EndFixMachine() override | |||||
| { | |||||
| } | |||||
| std::future<bool> GetFixStatus() override | |||||
| { | |||||
| } | |||||
| std::future<bool> StartSaveHuman() override | |||||
| { | |||||
| } | |||||
| std::future<bool> EndSaveHuman() override | |||||
| { | |||||
| } | |||||
| std::future<bool> GetSaveStatus() override | |||||
| { | |||||
| } | |||||
| std::future<bool> Escape() override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const override | |||||
| { | |||||
| } | |||||
| void StartFixMachine() override; | |||||
| void EndFixMachine() override; | |||||
| std::future<bool> GetFixStatus() override; | |||||
| void StartSaveHuman() override; | |||||
| void EndSaveHuman() override; | |||||
| std::future<bool> GetSaveStatus() override; | |||||
| std::future<bool> Escape() override; | |||||
| [[nodiscard]] std::shared_ptr<const THUAI6::Human> GetSelfInfo() const override; | |||||
| private: | private: | ||||
| ILogic& logic; | ILogic& logic; | ||||
| @@ -273,54 +252,30 @@ public: | |||||
| std::future<bool> UseSkill() override; | std::future<bool> UseSkill() override; | ||||
| std::future<bool> SendMessage(int64_t, std::string) override; | std::future<bool> SendMessage(int64_t, std::string) override; | ||||
| [[nodiscard]] std::future<bool> HaveMessage() override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::future<bool> HaveMessage() override; | |||||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override; | |||||
| std::future<bool> Wait() override | std::future<bool> Wait() override | ||||
| { | { | ||||
| } | } | ||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override; | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override; | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override; | |||||
| [[nodiscard]] std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | |||||
| [[nodiscard]] THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override; | |||||
| [[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override | [[nodiscard]] const std::vector<int64_t> GetPlayerGUIDs() const override | ||||
| { | { | ||||
| } | } | ||||
| std::future<bool> Attack(double angleInRadian) override | |||||
| { | |||||
| } | |||||
| std::future<bool> CarryHuman() override | |||||
| { | |||||
| } | |||||
| std::future<bool> ReleaseHuman() override | |||||
| { | |||||
| } | |||||
| std::future<bool> HangHuman() override | |||||
| { | |||||
| } | |||||
| [[nodiscard]] std::shared_ptr<const THUAI6::Butcher> GetSelfInfo() const override | |||||
| { | |||||
| } | |||||
| std::future<bool> Attack(double angleInRadian) override; | |||||
| std::future<bool> CarryHuman() override; | |||||
| std::future<bool> ReleaseHuman() override; | |||||
| std::future<bool> HangHuman() override; | |||||
| [[nodiscard]] std::shared_ptr<const THUAI6::Butcher> GetSelfInfo() const override; | |||||
| private: | private: | ||||
| ILogic& logic; | ILogic& logic; | ||||
| @@ -408,19 +363,19 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> StartFixMachine() override | |||||
| void StartFixMachine() override | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> EndFixMachine() override | |||||
| void EndFixMachine() override | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> GetFixStatus() override | std::future<bool> GetFixStatus() override | ||||
| { | { | ||||
| } | } | ||||
| std::future<bool> StartSaveHuman() override | |||||
| void StartSaveHuman() override | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> EndSaveHuman() override | |||||
| void EndSaveHuman() override | |||||
| { | { | ||||
| } | } | ||||
| std::future<bool> GetSaveStatus() override | std::future<bool> GetSaveStatus() override | ||||
| @@ -8,6 +8,7 @@ | |||||
| #include "Services.pb.h" | #include "Services.pb.h" | ||||
| #include <grpcpp/grpcpp.h> | #include <grpcpp/grpcpp.h> | ||||
| #include "structures.h" | #include "structures.h" | ||||
| #include <thread> | |||||
| class Logic; | class Logic; | ||||
| @@ -24,17 +25,35 @@ public: | |||||
| bool UseSkill(int64_t playerID); | bool UseSkill(int64_t playerID); | ||||
| bool SendMessage(int64_t toID, std::string message, int64_t playerID); | bool SendMessage(int64_t toID, std::string message, int64_t playerID); | ||||
| bool HaveMessage(int64_t playerID); | bool HaveMessage(int64_t playerID); | ||||
| std::pair<std::string, int64_t> GetMessage(int64_t playerID); | |||||
| std::pair<int64_t, std::string> GetMessage(int64_t playerID); | |||||
| bool Escape(int64_t playerID); | bool Escape(int64_t playerID); | ||||
| void StartFixMachine(int64_t playerID); | |||||
| void EndFixMachine(); | |||||
| bool GetFixStatus(); | |||||
| void StartSaveHuman(int64_t playerID); | |||||
| void EndSaveHuman(); | |||||
| bool GetSaveStatus(); | |||||
| bool Attack(double angle, int64_t playerID); | |||||
| bool CarryHuman(int64_t playerID); | |||||
| bool ReleaseHuman(int64_t playerID); | |||||
| bool HangHuman(int64_t playerID); | |||||
| bool TryConnection(int64_t playerID); | bool TryConnection(int64_t playerID); | ||||
| protobuf::MessageToClient GetMessage2Client(); | protobuf::MessageToClient GetMessage2Client(); | ||||
| bool HaveMessage2Client(); | bool HaveMessage2Client(); | ||||
| void AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::HumanType humanType, THUAI6::ButcherType butcherType); | void AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::HumanType humanType, THUAI6::ButcherType butcherType); | ||||
| private: | private: | ||||
| void FixMachine(int64_t playerID); | |||||
| void SaveHuman(int64_t playerID); | |||||
| std::unique_ptr<protobuf::AvailableService::Stub> THUAI6Stub; | std::unique_ptr<protobuf::AvailableService::Stub> THUAI6Stub; | ||||
| bool haveNewMessage = false; | bool haveNewMessage = false; | ||||
| protobuf::MessageToClient message2Client; | protobuf::MessageToClient message2Client; | ||||
| bool isFixing = false; | |||||
| bool isSaving = false; | |||||
| }; | }; | ||||
| #endif | #endif | ||||
| @@ -90,6 +90,7 @@ private: | |||||
| std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const override; | std::shared_ptr<const THUAI6::Butcher> ButcherGetSelfInfo() const override; | ||||
| std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | std::vector<std::vector<THUAI6::PlaceType>> GetFullMap() const override; | ||||
| THUAI6::PlaceType GetPlaceType(int32_t CellX, int32_t CellY) const override; | |||||
| // 供IAPI使用的操作相关的部分 | // 供IAPI使用的操作相关的部分 | ||||
| bool Move(int64_t time, double angle) override; | bool Move(int64_t time, double angle) override; | ||||
| @@ -98,43 +99,23 @@ private: | |||||
| bool UseSkill() override; | bool UseSkill() override; | ||||
| bool SendMessage(int64_t toID, std::string message) override; | bool SendMessage(int64_t toID, std::string message) override; | ||||
| bool HaveMessage() override; | bool HaveMessage() override; | ||||
| std::pair<std::string, int64_t> GetMessage() override; | |||||
| std::pair<int64_t, std::string> GetMessage() override; | |||||
| bool Escape() override; | bool Escape() override; | ||||
| // 说明:双向stream由三个函数共同实现,两个记录开始和结束,结果由Logic里的私有的成员变量记录,获得返回值则另调函数 | // 说明:双向stream由三个函数共同实现,两个记录开始和结束,结果由Logic里的私有的成员变量记录,获得返回值则另调函数 | ||||
| bool StartFixMachine() override | |||||
| { | |||||
| } | |||||
| bool EndFixMachine() override | |||||
| { | |||||
| } | |||||
| bool GetFixStatus() override | |||||
| { | |||||
| } | |||||
| bool StartSaveHuman() override | |||||
| { | |||||
| } | |||||
| bool EndSaveHuman() override | |||||
| { | |||||
| } | |||||
| bool GetSaveStatus() override | |||||
| { | |||||
| } | |||||
| bool Attack(double angle) override | |||||
| { | |||||
| } | |||||
| bool CarryHuman() override | |||||
| { | |||||
| } | |||||
| bool ReleaseHuman() override | |||||
| { | |||||
| } | |||||
| bool HangHuman() override | |||||
| { | |||||
| } | |||||
| void StartFixMachine() override; | |||||
| void EndFixMachine() override; | |||||
| bool GetFixStatus() override; | |||||
| void StartSaveHuman() override; | |||||
| void EndSaveHuman() override; | |||||
| bool GetSaveStatus() override; | |||||
| bool Attack(double angle) override; | |||||
| bool CarryHuman() override; | |||||
| bool ReleaseHuman() override; | |||||
| bool HangHuman() override; | |||||
| bool WaitThread() override | bool WaitThread() override | ||||
| { | { | ||||
| @@ -272,6 +272,14 @@ namespace THUAI62Proto | |||||
| sendMsg.set_player_id(id); | sendMsg.set_player_id(id); | ||||
| return sendMsg; | return sendMsg; | ||||
| } | } | ||||
| inline protobuf::AttackMsg THUAI62ProtobufAttack(double angle, int64_t id) | |||||
| { | |||||
| protobuf::AttackMsg attackMsg; | |||||
| attackMsg.set_angle(angle); | |||||
| attackMsg.set_player_id(id); | |||||
| return attackMsg; | |||||
| } | |||||
| } // namespace THUAI62Proto | } // namespace THUAI62Proto | ||||
| #endif | #endif | ||||
| @@ -10,26 +10,22 @@ std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadia | |||||
| std::future<bool> HumanAPI::MoveDown(int64_t timeInMilliseconds) | std::future<bool> HumanAPI::MoveDown(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, 0); }); | |||||
| return Move(timeInMilliseconds, 0); | |||||
| } | } | ||||
| std::future<bool> HumanAPI::MoveRight(int64_t timeInMilliseconds) | std::future<bool> HumanAPI::MoveRight(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 0.5); }); | |||||
| return Move(timeInMilliseconds, PI * 0.5); | |||||
| } | } | ||||
| std::future<bool> HumanAPI::MoveUp(int64_t timeInMilliseconds) | std::future<bool> HumanAPI::MoveUp(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI); }); | |||||
| return Move(timeInMilliseconds, PI); | |||||
| } | } | ||||
| std::future<bool> HumanAPI::MoveLeft(int64_t timeInMilliseconds) | std::future<bool> HumanAPI::MoveLeft(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 1.5); }); | |||||
| return Move(timeInMilliseconds, PI * 1.5); | |||||
| } | } | ||||
| std::future<bool> ButcherAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | std::future<bool> ButcherAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | ||||
| @@ -40,26 +36,22 @@ std::future<bool> ButcherAPI::Move(int64_t timeInMilliseconds, double angleInRad | |||||
| std::future<bool> ButcherAPI::MoveDown(int64_t timeInMilliseconds) | std::future<bool> ButcherAPI::MoveDown(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, 0); }); | |||||
| return Move(timeInMilliseconds, 0); | |||||
| } | } | ||||
| std::future<bool> ButcherAPI::MoveRight(int64_t timeInMilliseconds) | std::future<bool> ButcherAPI::MoveRight(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 0.5); }); | |||||
| return Move(timeInMilliseconds, PI * 0.5); | |||||
| } | } | ||||
| std::future<bool> ButcherAPI::MoveUp(int64_t timeInMilliseconds) | std::future<bool> ButcherAPI::MoveUp(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI); }); | |||||
| return Move(timeInMilliseconds, PI); | |||||
| } | } | ||||
| std::future<bool> ButcherAPI::MoveLeft(int64_t timeInMilliseconds) | std::future<bool> ButcherAPI::MoveLeft(int64_t timeInMilliseconds) | ||||
| { | { | ||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Move(timeInMilliseconds, PI * 1.5); }); | |||||
| return Move(timeInMilliseconds, PI * 1.5); | |||||
| } | } | ||||
| std::future<bool> HumanAPI::PickProp(THUAI6::PropType prop) | std::future<bool> HumanAPI::PickProp(THUAI6::PropType prop) | ||||
| @@ -110,6 +102,30 @@ std::future<bool> ButcherAPI::SendMessage(int64_t toID, std::string message) | |||||
| { return logic.SendMessage(toID, message); }); | { return logic.SendMessage(toID, message); }); | ||||
| } | } | ||||
| std::future<bool> HumanAPI::HaveMessage() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.HaveMessage(); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::HaveMessage() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.HaveMessage(); }); | |||||
| } | |||||
| std::future<std::pair<int64_t, std::string>> HumanAPI::GetMessage() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.GetMessage(); }); | |||||
| } | |||||
| std::future<std::pair<int64_t, std::string>> ButcherAPI::GetMessage() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.GetMessage(); }); | |||||
| } | |||||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanAPI::GetButcher() const | std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanAPI::GetButcher() const | ||||
| { | { | ||||
| return logic.GetButchers(); | return logic.GetButchers(); | ||||
| @@ -120,16 +136,126 @@ std::vector<std::shared_ptr<const THUAI6::Human>> HumanAPI::GetHuman() const | |||||
| return logic.GetHumans(); | return logic.GetHumans(); | ||||
| } | } | ||||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> ButcherAPI::GetButcher() const | |||||
| { | |||||
| return logic.GetButchers(); | |||||
| } | |||||
| std::vector<std::shared_ptr<const THUAI6::Human>> ButcherAPI::GetHuman() const | |||||
| { | |||||
| return logic.GetHumans(); | |||||
| } | |||||
| std::vector<std::shared_ptr<const THUAI6::Prop>> HumanAPI::GetProps() const | std::vector<std::shared_ptr<const THUAI6::Prop>> HumanAPI::GetProps() const | ||||
| { | { | ||||
| return logic.GetProps(); | return logic.GetProps(); | ||||
| } | } | ||||
| std::vector<std::shared_ptr<const THUAI6::Prop>> ButcherAPI::GetProps() const | |||||
| { | |||||
| return logic.GetProps(); | |||||
| } | |||||
| std::vector<std::vector<THUAI6::PlaceType>> HumanAPI::GetFullMap() const | std::vector<std::vector<THUAI6::PlaceType>> HumanAPI::GetFullMap() const | ||||
| { | { | ||||
| return logic.GetFullMap(); | return logic.GetFullMap(); | ||||
| } | } | ||||
| THUAI6::PlaceType HumanAPI::GetPlaceType(int32_t CellX, int32_t CellY) const | |||||
| { | |||||
| return logic.GetPlaceType(CellX, CellY); | |||||
| } | |||||
| THUAI6::PlaceType ButcherAPI::GetPlaceType(int32_t CellX, int32_t CellY) const | |||||
| { | |||||
| return logic.GetPlaceType(CellX, CellY); | |||||
| } | |||||
| std::vector<std::vector<THUAI6::PlaceType>> ButcherAPI::GetFullMap() const | |||||
| { | |||||
| return logic.GetFullMap(); | |||||
| } | |||||
| void HumanAPI::StartFixMachine() | |||||
| { | |||||
| std::thread([&]() | |||||
| { logic.StartFixMachine(); }) | |||||
| .detach(); | |||||
| } | |||||
| void HumanAPI::EndFixMachine() | |||||
| { | |||||
| std::thread([&]() | |||||
| { logic.EndFixMachine(); }) | |||||
| .detach(); | |||||
| } | |||||
| std::future<bool> HumanAPI::GetFixStatus() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.GetFixStatus(); }); | |||||
| } | |||||
| void HumanAPI::StartSaveHuman() | |||||
| { | |||||
| std::thread([&]() | |||||
| { logic.StartSaveHuman(); }) | |||||
| .detach(); | |||||
| } | |||||
| void HumanAPI::EndSaveHuman() | |||||
| { | |||||
| std::thread([&]() | |||||
| { logic.EndSaveHuman(); }) | |||||
| .detach(); | |||||
| } | |||||
| std::future<bool> HumanAPI::GetSaveStatus() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.GetSaveStatus(); }); | |||||
| } | |||||
| std::future<bool> HumanAPI::Escape() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Escape(); }); | |||||
| } | |||||
| std::shared_ptr<const THUAI6::Human> HumanAPI::GetSelfInfo() const | |||||
| { | |||||
| return logic.HumanGetSelfInfo(); | |||||
| } | |||||
| std::future<bool> ButcherAPI::Attack(double angleInRadian) | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.Attack(angleInRadian); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::CarryHuman() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.CarryHuman(); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::ReleaseHuman() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.ReleaseHuman(); }); | |||||
| } | |||||
| std::future<bool> ButcherAPI::HangHuman() | |||||
| { | |||||
| return std::async(std::launch::async, [&]() | |||||
| { return logic.HangHuman(); }); | |||||
| } | |||||
| std::shared_ptr<const THUAI6::Butcher> ButcherAPI::GetSelfInfo() const | |||||
| { | |||||
| return logic.ButcherGetSelfInfo(); | |||||
| } | |||||
| void HumanAPI::Play(IAI& ai) | void HumanAPI::Play(IAI& ai) | ||||
| { | { | ||||
| ai.play(*this); | ai.play(*this); | ||||
| @@ -85,7 +85,7 @@ bool Communication::HaveMessage(int64_t playerID) | |||||
| return false; | return false; | ||||
| } | } | ||||
| std::pair<std::string, int64_t> Communication::GetMessage(int64_t playerID) | |||||
| std::pair<int64_t, std::string> Communication::GetMessage(int64_t playerID) | |||||
| { | { | ||||
| protobuf::MsgRes getMessageResult; | protobuf::MsgRes getMessageResult; | ||||
| ClientContext context; | ClientContext context; | ||||
| @@ -94,12 +94,12 @@ std::pair<std::string, int64_t> Communication::GetMessage(int64_t playerID) | |||||
| if (status.ok()) | if (status.ok()) | ||||
| { | { | ||||
| if (getMessageResult.have_message()) | if (getMessageResult.have_message()) | ||||
| return std::make_pair(getMessageResult.message_received(), getMessageResult.from_player_id()); | |||||
| return std::make_pair(getMessageResult.from_player_id(), getMessageResult.message_received()); | |||||
| else | else | ||||
| return std::make_pair("", -1); | |||||
| return std::make_pair(-1, ""); | |||||
| } | } | ||||
| else | else | ||||
| return std::make_pair("", -1); | |||||
| return std::make_pair(-1, ""); | |||||
| } | } | ||||
| bool Communication::Escape(int64_t playerID) | bool Communication::Escape(int64_t playerID) | ||||
| @@ -114,6 +114,124 @@ bool Communication::Escape(int64_t playerID) | |||||
| return false; | return false; | ||||
| } | } | ||||
| void Communication::FixMachine(int64_t playerID) | |||||
| { | |||||
| protobuf::BoolRes fixMachineResult; | |||||
| auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| ClientContext context; | |||||
| while (isFixing) | |||||
| { | |||||
| auto fixStream = THUAI6Stub->FixMachine(&context); | |||||
| fixStream->Write(request); | |||||
| fixStream->Read(&fixMachineResult); | |||||
| if (!fixMachineResult.act_success()) | |||||
| { | |||||
| isFixing = false; | |||||
| break; | |||||
| } | |||||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); // 防止巨量发信 | |||||
| } | |||||
| } | |||||
| void Communication::StartFixMachine(int64_t playerID) | |||||
| { | |||||
| isFixing = true; | |||||
| FixMachine(playerID); | |||||
| } | |||||
| void Communication::EndFixMachine() | |||||
| { | |||||
| isFixing = false; | |||||
| } | |||||
| bool Communication::GetFixStatus() | |||||
| { | |||||
| return isFixing; | |||||
| } | |||||
| void Communication::SaveHuman(int64_t playerID) | |||||
| { | |||||
| protobuf::BoolRes saveHumanResult; | |||||
| auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| ClientContext context; | |||||
| while (isSaving) | |||||
| { | |||||
| auto saveStream = THUAI6Stub->SaveHuman(&context); | |||||
| saveStream->Write(request); | |||||
| saveStream->Read(&saveHumanResult); | |||||
| if (!saveHumanResult.act_success()) | |||||
| { | |||||
| isSaving = false; | |||||
| break; | |||||
| } | |||||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); // 防止巨量发信 | |||||
| } | |||||
| } | |||||
| void Communication::StartSaveHuman(int64_t playerID) | |||||
| { | |||||
| isSaving = true; | |||||
| SaveHuman(playerID); | |||||
| } | |||||
| void Communication::EndSaveHuman() | |||||
| { | |||||
| isSaving = false; | |||||
| } | |||||
| bool Communication::GetSaveStatus() | |||||
| { | |||||
| return isSaving; | |||||
| } | |||||
| bool Communication::Attack(double angle, int64_t playerID) | |||||
| { | |||||
| protobuf::BoolRes attackResult; | |||||
| ClientContext context; | |||||
| auto request = THUAI62Proto::THUAI62ProtobufAttack(angle, playerID); | |||||
| auto status = THUAI6Stub->Attack(&context, request, &attackResult); | |||||
| if (status.ok()) | |||||
| return attackResult.act_success(); | |||||
| else | |||||
| return false; | |||||
| } | |||||
| bool Communication::CarryHuman(int64_t playerID) | |||||
| { | |||||
| protobuf::BoolRes carryHumanResult; | |||||
| ClientContext context; | |||||
| auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| auto status = THUAI6Stub->CarryHuman(&context, request, &carryHumanResult); | |||||
| if (status.ok()) | |||||
| return carryHumanResult.act_success(); | |||||
| else | |||||
| return false; | |||||
| } | |||||
| bool Communication::ReleaseHuman(int64_t playerID) | |||||
| { | |||||
| protobuf::BoolRes releaseHumanResult; | |||||
| ClientContext context; | |||||
| auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| auto status = THUAI6Stub->ReleaseHuman(&context, request, &releaseHumanResult); | |||||
| if (status.ok()) | |||||
| return releaseHumanResult.act_success(); | |||||
| else | |||||
| return false; | |||||
| } | |||||
| bool Communication::HangHuman(int64_t playerID) | |||||
| { | |||||
| protobuf::BoolRes hangHumanResult; | |||||
| ClientContext context; | |||||
| auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| auto status = THUAI6Stub->HangHuman(&context, request, &hangHumanResult); | |||||
| if (status.ok()) | |||||
| return hangHumanResult.act_success(); | |||||
| else | |||||
| return false; | |||||
| } | |||||
| bool Communication::TryConnection(int64_t playerID) | bool Communication::TryConnection(int64_t playerID) | ||||
| { | { | ||||
| protobuf::BoolRes reply; | protobuf::BoolRes reply; | ||||
| @@ -62,121 +62,102 @@ std::vector<std::vector<THUAI6::PlaceType>> Logic::GetFullMap() const | |||||
| return currentState->gamemap; | return currentState->gamemap; | ||||
| } | } | ||||
| THUAI6::PlaceType Logic::GetPlaceType(int32_t CellX, int32_t CellY) const | |||||
| { | |||||
| std::lock_guard<std::mutex> lock(mtxState); | |||||
| return currentState->gamemap[CellX][CellY]; | |||||
| } | |||||
| bool Logic::Move(int64_t time, double angle) | bool Logic::Move(int64_t time, double angle) | ||||
| { | { | ||||
| // protobuf::MoveRes moveResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufMove(time, angle, playerID); | |||||
| // auto status = THUAI6Stub->Move(&context, request, &moveResult); | |||||
| // if (status.ok()) | |||||
| // return moveResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->Move(time, angle, playerID); | return pComm->Move(time, angle, playerID); | ||||
| } | } | ||||
| bool Logic::PickProp(THUAI6::PropType prop) | bool Logic::PickProp(THUAI6::PropType prop) | ||||
| { | { | ||||
| // protobuf::BoolRes pickPropResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufPick(prop, playerID); | |||||
| // auto status = THUAI6Stub->PickProp(&context, request, &pickPropResult); | |||||
| // if (status.ok()) | |||||
| // return pickPropResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->PickProp(prop, playerID); | return pComm->PickProp(prop, playerID); | ||||
| } | } | ||||
| bool Logic::UseProp() | bool Logic::UseProp() | ||||
| { | { | ||||
| // protobuf::BoolRes usePropResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| // auto status = THUAI6Stub->UseProp(&context, request, &usePropResult); | |||||
| // if (status.ok()) | |||||
| // return usePropResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->UseProp(playerID); | return pComm->UseProp(playerID); | ||||
| } | } | ||||
| bool Logic::UseSkill() | bool Logic::UseSkill() | ||||
| { | { | ||||
| // protobuf::BoolRes useSkillResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| // auto status = THUAI6Stub->UseSkill(&context, request, &useSkillResult); | |||||
| // if (status.ok()) | |||||
| // return useSkillResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->UseSkill(playerID); | return pComm->UseSkill(playerID); | ||||
| } | } | ||||
| bool Logic::SendMessage(int64_t toID, std::string message) | bool Logic::SendMessage(int64_t toID, std::string message) | ||||
| { | { | ||||
| // protobuf::BoolRes sendMessageResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufSend(message, toID, playerID); | |||||
| // auto status = THUAI6Stub->SendMessage(&context, request, &sendMessageResult); | |||||
| // if (status.ok()) | |||||
| // return sendMessageResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->SendMessage(toID, message, playerID); | return pComm->SendMessage(toID, message, playerID); | ||||
| } | } | ||||
| bool Logic::HaveMessage() | bool Logic::HaveMessage() | ||||
| { | { | ||||
| // protobuf::BoolRes haveMessageResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| // auto status = THUAI6Stub->HaveMessage(&context, request, &haveMessageResult); | |||||
| // if (status.ok()) | |||||
| // return haveMessageResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->HaveMessage(playerID); | return pComm->HaveMessage(playerID); | ||||
| } | } | ||||
| std::pair<std::string, int64_t> Logic::GetMessage() | |||||
| std::pair<int64_t, std::string> Logic::GetMessage() | |||||
| { | { | ||||
| // protobuf::MsgRes getMessageResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| // auto status = THUAI6Stub->GetMessage(&context, request, &getMessageResult); | |||||
| // if (status.ok()) | |||||
| // { | |||||
| // if (getMessageResult.have_message()) | |||||
| // return std::make_pair(getMessageResult.message_received(), getMessageResult.from_player_id()); | |||||
| // else | |||||
| // return std::make_pair("", -1); | |||||
| // } | |||||
| // else | |||||
| // return std::make_pair("", -1); | |||||
| return pComm->GetMessage(playerID); | return pComm->GetMessage(playerID); | ||||
| } | } | ||||
| bool Logic::Escape() | bool Logic::Escape() | ||||
| { | { | ||||
| // protobuf::BoolRes escapeResult; | |||||
| // ClientContext context; | |||||
| // auto request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| // auto status = THUAI6Stub->Escape(&context, request, &escapeResult); | |||||
| // if (status.ok()) | |||||
| // return escapeResult.act_success(); | |||||
| // else | |||||
| // return false; | |||||
| return pComm->Escape(playerID); | return pComm->Escape(playerID); | ||||
| } | } | ||||
| void Logic::StartFixMachine() | |||||
| { | |||||
| pComm->StartFixMachine(playerID); | |||||
| } | |||||
| void Logic::EndFixMachine() | |||||
| { | |||||
| pComm->EndFixMachine(); | |||||
| } | |||||
| bool Logic::GetFixStatus() | |||||
| { | |||||
| return pComm->GetFixStatus(); | |||||
| } | |||||
| void Logic::StartSaveHuman() | |||||
| { | |||||
| pComm->StartSaveHuman(playerID); | |||||
| } | |||||
| void Logic::EndSaveHuman() | |||||
| { | |||||
| pComm->EndSaveHuman(); | |||||
| } | |||||
| bool Logic::GetSaveStatus() | |||||
| { | |||||
| return pComm->GetSaveStatus(); | |||||
| } | |||||
| bool Logic::Attack(double angle) | |||||
| { | |||||
| return pComm->Attack(angle, playerID); | |||||
| } | |||||
| bool Logic::CarryHuman() | |||||
| { | |||||
| return pComm->CarryHuman(playerID); | |||||
| } | |||||
| bool Logic::ReleaseHuman() | |||||
| { | |||||
| return pComm->ReleaseHuman(playerID); | |||||
| } | |||||
| bool Logic::HangHuman() | |||||
| { | |||||
| return pComm->HangHuman(playerID); | |||||
| } | |||||
| void Logic::ProcessMessage() | void Logic::ProcessMessage() | ||||
| { | { | ||||
| auto messageThread = [&]() | auto messageThread = [&]() | ||||
| @@ -268,14 +249,6 @@ void Logic::PlayerWrapper(std::function<void()> player) | |||||
| bool Logic::TryConnection() | bool Logic::TryConnection() | ||||
| { | { | ||||
| // IDMsg request = THUAI62Proto::THUAI62ProtobufID(playerID); | |||||
| // BoolRes reply; | |||||
| // ClientContext context; | |||||
| // auto status = THUAI6Stub->TryConnection(&context, request, &reply); | |||||
| // if (status.ok()) | |||||
| // return true; | |||||
| // else | |||||
| // return false; | |||||
| return pComm->TryConnection(playerID); | return pComm->TryConnection(playerID); | ||||
| } | } | ||||