From 8582aba75c0b2bbdd3f9a6d2611a785a18ccbbbf Mon Sep 17 00:00:00 2001 From: 964293341 Date: Sat, 18 May 2024 00:27:49 +0800 Subject: [PATCH 1/9] fix(CAPI): align data type --- CAPI/cpp/API/include/Communication.h | 4 +-- CAPI/cpp/API/include/structures.h | 41 ++++++++++++++-------------- CAPI/cpp/API/include/utils.hpp | 16 +++++------ CAPI/cpp/API/src/logic.cpp | 6 ++-- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index 8ab441f8..e44b5578 100755 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -52,8 +52,8 @@ class Communication protobuf::MessageToClient message2Client; std::mutex mtxMessage; std::mutex mtxLimit; - int32_t counter; - int32_t counterMove; + int32_t counter{}; + int32_t counterMove{}; static constexpr const int32_t limit = 50; static constexpr const int32_t moveLimit = 10; std::condition_variable cvMessage; diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 375c57e1..c0750419 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -197,8 +197,8 @@ namespace THUAI7 int32_t hp; // 血量 int32_t armor; // 装甲 int32_t shield; // 护盾 - int32_t playerID; // 船的id - int32_t teamID; + int64_t playerID; // 船的id + int64_t teamID; int64_t guid; // 全局唯一ID ShipState shipState; // 船所处状态 ShipType shipType; @@ -213,10 +213,10 @@ namespace THUAI7 struct Team { - int32_t playerID; - int32_t teamID; - int32_t score; - int32_t energy; + int64_t playerID; + int64_t teamID; + int64_t score; + int64_t energy; }; struct Home @@ -224,23 +224,22 @@ namespace THUAI7 int32_t x; int32_t y; int32_t hp; - int32_t teamID; + int64_t teamID; int64_t guid; }; struct Bullet { - int32_t x; // x坐标 - int32_t y; // y坐标 - double facingDirection; // 朝向 - int64_t guid; // - int32_t teamID; // 子弹所属队伍 - BulletType bulletType; // 子弹类型 - int32_t damage; // 伤害值 + int32_t x; // x坐标 + int32_t y; // y坐标 + double facingDirection; // 朝向 + int64_t guid; // + int64_t teamID; // 子弹所属队伍 + BulletType bulletType; // 子弹类型 + int32_t damage; // 伤害值 int32_t attackRange; - int32_t bombRange; - double explodeRange; // 炸弹爆炸范围 - int32_t speed; // 子弹速度 + double bombRange; // 炸弹爆炸范围 + int32_t speed; // 子弹速度 }; struct ConstructionState @@ -269,10 +268,10 @@ namespace THUAI7 struct GameMap { // x,y,id,hp - std::map, std::pair> factoryState; - std::map, std::pair> communityState; - std::map, std::pair> fortState; - std::map, std::pair> homeState; + std::map, std::pair> factoryState; + std::map, std::pair> communityState; + std::map, std::pair> fortState; + std::map, std::pair> homeState; std::map, int32_t> wormholeState; std::map, int32_t> resourceState; }; diff --git a/CAPI/cpp/API/include/utils.hpp b/CAPI/cpp/API/include/utils.hpp index 52ac4973..cce9bace 100755 --- a/CAPI/cpp/API/include/utils.hpp +++ b/CAPI/cpp/API/include/utils.hpp @@ -29,21 +29,21 @@ namespace AssistFunction [[nodiscard]] constexpr inline int32_t GridToCell(double grid) noexcept { - return int(grid) / numOfGridPerCell; + return int32_t(grid) / numOfGridPerCell; } inline bool HaveView(int32_t x, int32_t y, int32_t newX, int32_t newY, int32_t viewRange, std::vector>& map) { - int32_t deltaX = newX - x; - int32_t deltaY = newY - y; - double distance = double(deltaX * deltaX) + double(deltaY * deltaY); + double deltaX = newX - x; + double deltaY = newY - y; + double distance = std::pow(deltaX, 2) + std::pow(deltaY, 2); THUAI7::PlaceType myPlace = map[GridToCell(x)][GridToCell(y)]; THUAI7::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)]; if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI7::PlaceType::Shadow) return false; - if (distance > viewRange * viewRange) + if (distance > std::pow(viewRange, 2)) return false; - int32_t divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100; + int32_t divide = int32_t(std::max(std::abs(deltaX), std::abs(deltaY)) / 100); if (divide == 0) return true; double dx = deltaX / divide; @@ -546,8 +546,8 @@ namespace Time { inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp) { - std::chrono::system_clock::time_point tp = std::chrono::system_clock::now(); - std::chrono::duration time_span = std::chrono::duration_cast>(tp - sp); + auto tp = std::chrono::system_clock::now(); + auto time_span = std::chrono::duration_cast>(tp - sp); return time_span.count(); } } // namespace Time diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 9710b355..72a5807d 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -322,7 +322,7 @@ void Logic::ProcessMessage() if (Proto2THUAI7::messageOfObjDict[item.message_of_obj_case()] == THUAI7::MessageOfObj::MapMessage) { auto map = std::vector>(); - auto mapResult = item.map_message(); + auto& mapResult = item.map_message(); for (int32_t i = 0; i < item.map_message().rows_size(); i++) { std::vector row; @@ -608,7 +608,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) break; case THUAI7::MessageOfObj::NewsMessage: { - auto news = item.news_message(); + auto& news = item.news_message(); if (news.to_id() == playerID && news.team_id() == teamID) { if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) @@ -813,7 +813,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::NewsMessage: if (item.news_message().team_id() == teamID && item.news_message().to_id() == playerID) { - auto news = item.news_message(); + auto& news = item.news_message(); if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) { messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); From 2cbb5c3a8f548eff9e6d8299f9d6667c4e780680 Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Sat, 18 May 2024 20:05:26 +0800 Subject: [PATCH 2/9] fix: :bug: construction activate --- logic/GameClass/GameObj/Areas/Construction.cs | 1 + logic/Gaming/AttackManager.cs | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/logic/GameClass/GameObj/Areas/Construction.cs b/logic/GameClass/GameObj/Areas/Construction.cs index 1161c235..2c1c407d 100755 --- a/logic/GameClass/GameObj/Areas/Construction.cs +++ b/logic/GameClass/GameObj/Areas/Construction.cs @@ -72,6 +72,7 @@ public bool BeAttacked(Bullet bullet) { lock (lockOfConstructionType) constructionType = ConstructionType.Null; + IsActivated.Set(false); } return HP.IsBelowMaxTimes(0.5); } diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index b6b79d62..29f2dd21 100755 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -89,12 +89,20 @@ private void BombObj(Bullet bullet, GameObj objBeingShot) case GameObjType.Construction: var constructionType = ((Construction)objBeingShot).ConstructionType; var flag = ((Construction)objBeingShot).BeAttacked(bullet); - if (constructionType == ConstructionType.Community && flag) - game.RemoveBirthPoint( - ((Construction)objBeingShot).TeamID, - ((Construction)objBeingShot).Position); - else if (constructionType == ConstructionType.Factory && flag) - game.RemoveFactory(((Construction)objBeingShot).TeamID); + if (flag) + { + ((Construction)objBeingShot).IsActivated.SetROri(false); + if (constructionType == ConstructionType.Community) + { + game.RemoveBirthPoint( + ((Construction)objBeingShot).TeamID, + ((Construction)objBeingShot).Position); + } + else if (constructionType == ConstructionType.Factory) + { + game.RemoveFactory(((Construction)objBeingShot).TeamID); + } + } break; case GameObjType.Wormhole: ((WormholeCell)objBeingShot).Wormhole.BeAttacked(bullet); From eb0f78ecbbd4caa40350a7fdef93bbc9092c97c2 Mon Sep 17 00:00:00 2001 From: 964293341 Date: Sat, 18 May 2024 20:08:08 +0800 Subject: [PATCH 3/9] feat(CAPI): add `using cellxy_t = std::pair` --- CAPI/cpp/API/include/Communication.h | 4 +- CAPI/cpp/API/include/logic.h | 2 +- CAPI/cpp/API/include/structures.h | 19 ++-- CAPI/cpp/API/include/utils.hpp | 5 +- CAPI/cpp/API/src/logic.cpp | 148 +++++++++++++++++++-------- 5 files changed, 118 insertions(+), 60 deletions(-) diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index e44b5578..9b7a46f3 100755 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -24,9 +24,7 @@ class Communication { public: Communication(std::string sIP, std::string sPort); - ~Communication() - { - } + ~Communication() = default; bool TryConnection(int32_t playerID, int32_t teamID); protobuf::MessageToClient GetMessage2Client(); void AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType); diff --git a/CAPI/cpp/API/include/logic.h b/CAPI/cpp/API/include/logic.h index e03bad4e..3b41a065 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -63,7 +63,7 @@ class Logic : public ILogic std::condition_variable cvAI; // 信息队列 - ConcurrentQueue> messageQueue; + ConcurrentQueue> messageQueue; // 存储状态,分别是现在的状态和缓冲区的状态。 State state[2]; diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index c0750419..bdba5c59 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -14,7 +14,6 @@ namespace THUAI7 { - // 游戏状态 enum class GameState : unsigned char { @@ -244,10 +243,10 @@ namespace THUAI7 struct ConstructionState { - int32_t teamID; + int64_t teamID; int32_t hp; ConstructionType constructionType; - ConstructionState(std::pair teamHP, ConstructionType type) : + ConstructionState(std::pair teamHP, ConstructionType type) : teamID(teamHP.first), hp(teamHP.second), constructionType(type) @@ -265,15 +264,17 @@ namespace THUAI7 // double bombRange, // }; + using cellxy_t = std::pair; + struct GameMap { // x,y,id,hp - std::map, std::pair> factoryState; - std::map, std::pair> communityState; - std::map, std::pair> fortState; - std::map, std::pair> homeState; - std::map, int32_t> wormholeState; - std::map, int32_t> resourceState; + std::map> factoryState; + std::map> communityState; + std::map> fortState; + std::map> homeState; + std::map wormholeState; + std::map resourceState; }; struct GameInfo diff --git a/CAPI/cpp/API/include/utils.hpp b/CAPI/cpp/API/include/utils.hpp index cce9bace..5a38ea56 100755 --- a/CAPI/cpp/API/include/utils.hpp +++ b/CAPI/cpp/API/include/utils.hpp @@ -17,9 +17,9 @@ #undef SendMessage #undef PeekMessage +// 用于将THUAI7的类转换为Protobuf的类 namespace AssistFunction { - constexpr int32_t numOfGridPerCell = 1000; [[nodiscard]] constexpr inline int32_t GridToCell(int32_t grid) noexcept @@ -539,9 +539,8 @@ namespace THUAI72Proto playerMsg.set_ship_type(THUAI72Proto::shipTypeDict[ShipType]); return playerMsg; } - - // 用于将THUAI7的类转换为Protobuf的类 } // namespace THUAI72Proto + namespace Time { inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp) diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 72a5807d..56a18360 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -95,7 +95,7 @@ std::optional Logic::GetConstructionState(int32_t cel { std::unique_lock lock(mtxState); logger->debug("Called GetConstructionState"); - auto pos = std::make_pair(cellX, cellY); + auto pos = THUAI7::cellxy_t(cellX, cellY); auto it = currentState->mapInfo->factoryState.find(pos); auto it2 = currentState->mapInfo->communityState.find(pos); auto it3 = currentState->mapInfo->fortState.find(pos); @@ -118,7 +118,7 @@ int32_t Logic::GetWormholeHp(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetWormholeHp"); - auto pos = std::make_pair(cellX, cellY); + auto pos = THUAI7::cellxy_t(cellX, cellY); auto it = currentState->mapInfo->wormholeState.find(pos); if (it != currentState->mapInfo->wormholeState.end()) { @@ -144,7 +144,7 @@ int32_t Logic::GetResourceState(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetResourceState"); - auto pos = std::make_pair(cellX, cellY); + auto pos = THUAI7::cellxy_t(cellX, cellY); auto it = currentState->mapInfo->resourceState.find(pos); if (it != currentState->mapInfo->resourceState.end()) { @@ -220,7 +220,7 @@ std::pair Logic::GetMessage() else { logger->warn("No message"); - return std::make_pair(-1, ""); + return std::pair(-1, std::string("")); } } @@ -451,10 +451,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::HomeMessage: if (item.home_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -465,10 +468,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.home_message().x(), item.home_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -481,10 +487,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FactoryMessage: if (item.factory_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -496,10 +505,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.factory_message().x(), item.factory_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -513,10 +525,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::CommunityMessage: if (item.community_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -528,10 +543,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.community_message().x(), item.community_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -545,10 +563,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FortMessage: if (item.fort_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -560,10 +581,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.fort_message().x(), item.fort_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -577,7 +601,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::WormholeMessage: if (AssistFunction::HaveView(x, y, item.wormhole_message().x(), item.wormhole_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.wormhole_message().x()), + AssistFunction::GridToCell(item.wormhole_message().y()) + ); if (bufferState->mapInfo->wormholeState.count(pos) == 0) { bufferState->mapInfo->wormholeState.emplace(pos, item.wormhole_message().hp()); @@ -593,7 +620,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::ResourceMessage: if (AssistFunction::HaveView(x, y, item.resource_message().x(), item.resource_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.resource_message().x()), + AssistFunction::GridToCell(item.resource_message().y()) + ); if (bufferState->mapInfo->resourceState.count(pos) == 0) { bufferState->mapInfo->resourceState.emplace(pos, item.resource_message().progress()); @@ -613,12 +643,12 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) { if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); + messageQueue.emplace(std::pair(news.from_id(), news.text_message())); logger->debug("Load Text News!"); } else if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::BinaryMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.binary_message())); + messageQueue.emplace(std::pair(news.from_id(), news.binary_message())); logger->debug("Load Binary News!"); } else @@ -655,10 +685,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::HomeMessage: if (item.home_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -669,10 +702,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.home_message().x(), item.home_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -685,10 +721,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FactoryMessage: if (item.factory_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -700,10 +739,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.factory_message().x(), item.factory_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -717,10 +759,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::CommunityMessage: if (item.community_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -732,10 +777,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.community_message().x(), item.community_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -749,10 +797,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FortMessage: if (item.fort_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -764,10 +815,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.fort_message().x(), item.fort_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -781,7 +835,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::WormholeMessage: if (HaveOverView(item.wormhole_message().x(), item.wormhole_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.wormhole_message().x()), + AssistFunction::GridToCell(item.wormhole_message().y()) + ); if (bufferState->mapInfo->wormholeState.count(pos) == 0) { bufferState->mapInfo->wormholeState.emplace(pos, item.wormhole_message().hp()); @@ -797,7 +854,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::ResourceMessage: if (HaveOverView(item.resource_message().x(), item.resource_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.resource_message().x()), + AssistFunction::GridToCell(item.resource_message().y()) + ); if (bufferState->mapInfo->resourceState.count(pos) == 0) { bufferState->mapInfo->resourceState.emplace(pos, item.resource_message().progress()); @@ -816,12 +876,12 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) auto& news = item.news_message(); if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); + messageQueue.emplace(std::pair(news.from_id(), news.text_message())); logger->debug("Load Text News!"); } else if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::BinaryMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.binary_message())); + messageQueue.emplace(std::pair(news.from_id(), news.binary_message())); logger->debug("Load Binary News!"); } else From 0abf155fe821e7bd5cefd44c2cafee68a6b07186 Mon Sep 17 00:00:00 2001 From: 964293341 Date: Sat, 18 May 2024 20:14:00 +0800 Subject: [PATCH 4/9] format --- CAPI/cpp/API/include/structures.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index bdba5c59..2d784d85 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -229,16 +229,16 @@ namespace THUAI7 struct Bullet { - int32_t x; // x坐标 - int32_t y; // y坐标 - double facingDirection; // 朝向 - int64_t guid; // - int64_t teamID; // 子弹所属队伍 - BulletType bulletType; // 子弹类型 - int32_t damage; // 伤害值 + int32_t x; // x坐标 + int32_t y; // y坐标 + double facingDirection; // 朝向 + int64_t guid; // + int64_t teamID; // 子弹所属队伍 + BulletType bulletType; // 子弹类型 + int32_t damage; // 伤害值 int32_t attackRange; - double bombRange; // 炸弹爆炸范围 - int32_t speed; // 子弹速度 + double bombRange; // 炸弹爆炸范围 + int32_t speed; // 子弹速度 }; struct ConstructionState @@ -368,7 +368,8 @@ namespace THUAI7 {ModuleType::ModulePlasmaGun, "ModulePlasmaGun"}, {ModuleType::ModuleShellGun, "ModuleShellGun"}, {ModuleType::ModuleMissileGun, "ModuleMissileGun"}, - {ModuleType::ModuleArcGun, "ModuleArcGun"}}; + {ModuleType::ModuleArcGun, "ModuleArcGun"} + }; inline std::map messageOfObjDict{ {MessageOfObj::NullMessageOfObj, "NullMessageOfObj"}, From 6c51ed67184dfac2d5ffe06226d7dda1c7183a15 Mon Sep 17 00:00:00 2001 From: 964293341 Date: Sat, 18 May 2024 20:21:26 +0800 Subject: [PATCH 5/9] format --- CAPI/cpp/API/include/structures.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 2d784d85..719fb31a 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -368,7 +368,7 @@ namespace THUAI7 {ModuleType::ModulePlasmaGun, "ModulePlasmaGun"}, {ModuleType::ModuleShellGun, "ModuleShellGun"}, {ModuleType::ModuleMissileGun, "ModuleMissileGun"}, - {ModuleType::ModuleArcGun, "ModuleArcGun"} + {ModuleType::ModuleArcGun, "ModuleArcGun"}, }; inline std::map messageOfObjDict{ From e9e0b95a3c5a568bcc8a33b0b0bbd307fb4380ab Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Sat, 18 May 2024 20:43:27 +0800 Subject: [PATCH 6/9] feat: :sparkles: bullet can attack wormhole --- logic/GameClass/GameObj/Areas/Asteroid.cs | 2 +- logic/GameClass/GameObj/Areas/Construction.cs | 2 +- logic/GameClass/GameObj/Areas/Home.cs | 2 +- logic/GameClass/GameObj/Areas/NullArea.cs | 2 +- logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs | 2 +- logic/GameClass/GameObj/Areas/Resource.cs | 2 +- logic/GameClass/GameObj/Areas/Ruin.cs | 2 +- logic/GameClass/GameObj/Areas/Shadow.cs | 2 +- logic/GameClass/GameObj/Areas/WormholeCell.cs | 2 +- logic/GameClass/GameObj/BombedBullet.cs | 2 +- logic/GameClass/GameObj/Bullet.cs | 2 +- logic/GameClass/GameObj/GameObj.cs | 2 +- logic/GameClass/GameObj/Ship.cs | 2 +- logic/GameEngine/CollisionChecker.cs | 10 +++++----- logic/GameEngine/MoveEngine.cs | 6 ++++-- logic/Gaming/AttackManager.cs | 3 ++- logic/Preparation/Interface/IGameObj.cs | 2 +- logic/Preparation/Interface/IMovable.cs | 4 ++-- 18 files changed, 27 insertions(+), 24 deletions(-) diff --git a/logic/GameClass/GameObj/Areas/Asteroid.cs b/logic/GameClass/GameObj/Areas/Asteroid.cs index 8dca4053..8bbb622c 100755 --- a/logic/GameClass/GameObj/Areas/Asteroid.cs +++ b/logic/GameClass/GameObj/Areas/Asteroid.cs @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas; public class Asteroid(XY initPos) : Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Asteroid) { - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Square; } diff --git a/logic/GameClass/GameObj/Areas/Construction.cs b/logic/GameClass/GameObj/Areas/Construction.cs index 2c1c407d..8b82dfd6 100755 --- a/logic/GameClass/GameObj/Areas/Construction.cs +++ b/logic/GameClass/GameObj/Areas/Construction.cs @@ -10,7 +10,7 @@ public class Construction(XY initPos) { public AtomicLong TeamID { get; } = new(long.MaxValue); public InVariableRange HP { get; } = new(0, GameData.CommunityHP); - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Square; private readonly object lockOfConstructionType = new(); diff --git a/logic/GameClass/GameObj/Areas/Home.cs b/logic/GameClass/GameObj/Areas/Home.cs index 35de2baa..65752411 100755 --- a/logic/GameClass/GameObj/Areas/Home.cs +++ b/logic/GameClass/GameObj/Areas/Home.cs @@ -11,7 +11,7 @@ public class Home(XY initPos, long id) { public long TeamID { get; } = id; public InVariableRange HP { get; } = new(GameData.HomeHP); - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Square; public AtomicInt RepairNum { get; } = new AtomicInt(0); public bool Repair(int constructSpeed, Ship ship) diff --git a/logic/GameClass/GameObj/Areas/NullArea.cs b/logic/GameClass/GameObj/Areas/NullArea.cs index 3baeea51..bcfa3b4c 100755 --- a/logic/GameClass/GameObj/Areas/NullArea.cs +++ b/logic/GameClass/GameObj/Areas/NullArea.cs @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas; public class NullArea(XY initPos) : Immovable(initPos, int.MaxValue, GameObjType.Null) { - public override bool IsRigid => false; + public override bool IsRigid(bool args = false) => false; public override ShapeType Shape => ShapeType.Null; } diff --git a/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs b/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs index c5f600a4..7fd1df30 100755 --- a/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs +++ b/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs @@ -10,6 +10,6 @@ namespace GameClass.GameObj.Areas; public class OutOfBoundBlock(XY initPos) : Immovable(initPos, int.MaxValue, GameObjType.OutOfBoundBlock), IOutOfBound { - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Square; } diff --git a/logic/GameClass/GameObj/Areas/Resource.cs b/logic/GameClass/GameObj/Areas/Resource.cs index 9f8b151c..a7223575 100755 --- a/logic/GameClass/GameObj/Areas/Resource.cs +++ b/logic/GameClass/GameObj/Areas/Resource.cs @@ -9,7 +9,7 @@ public class Resource(XY initPos) : Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Resource) { public InVariableRange HP { get; } = new(GameData.ResourceHP); - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Square; public AtomicInt ProduceNum { get; } = new AtomicInt(0); public bool Produce(int produceSpeed, Ship ship) diff --git a/logic/GameClass/GameObj/Areas/Ruin.cs b/logic/GameClass/GameObj/Areas/Ruin.cs index c4a96790..04d4a24a 100755 --- a/logic/GameClass/GameObj/Areas/Ruin.cs +++ b/logic/GameClass/GameObj/Areas/Ruin.cs @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas; public class Ruin(XY initPos) : Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Ruin) { - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Square; } diff --git a/logic/GameClass/GameObj/Areas/Shadow.cs b/logic/GameClass/GameObj/Areas/Shadow.cs index 3d35a9b3..52071d47 100755 --- a/logic/GameClass/GameObj/Areas/Shadow.cs +++ b/logic/GameClass/GameObj/Areas/Shadow.cs @@ -6,6 +6,6 @@ namespace GameClass.GameObj.Areas; public class Shadow(XY initPos) : Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Shadow) { - public override bool IsRigid => false; + public override bool IsRigid(bool args = false) => false; public override ShapeType Shape => ShapeType.Square; } \ No newline at end of file diff --git a/logic/GameClass/GameObj/Areas/WormholeCell.cs b/logic/GameClass/GameObj/Areas/WormholeCell.cs index 0f1726ed..609773cd 100644 --- a/logic/GameClass/GameObj/Areas/WormholeCell.cs +++ b/logic/GameClass/GameObj/Areas/WormholeCell.cs @@ -6,7 +6,7 @@ namespace GameClass.GameObj.Areas; public class WormholeCell(XY initPos, Wormhole wormhole) : Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Wormhole) { - public override bool IsRigid => Wormhole.HP < GameData.WormholeHP / 2; + public override bool IsRigid(bool args = false) => args || Wormhole.HP < GameData.WormholeHP / 2; public override ShapeType Shape => ShapeType.Square; public readonly Wormhole Wormhole = wormhole; } diff --git a/logic/GameClass/GameObj/BombedBullet.cs b/logic/GameClass/GameObj/BombedBullet.cs index 0d89bc29..f5b3dcdf 100755 --- a/logic/GameClass/GameObj/BombedBullet.cs +++ b/logic/GameClass/GameObj/BombedBullet.cs @@ -8,7 +8,7 @@ public sealed class BombedBullet(Bullet bullet) : Immovable(bullet.Position, bullet.Radius, GameObjType.BombedBullet) { public override ShapeType Shape => ShapeType.Circle; - public override bool IsRigid => false; + public override bool IsRigid(bool args = false) => false; public long MappingID { get; } = bullet.ID; public readonly Bullet bulletHasBombed = bullet; public readonly XY facingDirection = bullet.FacingDirection; diff --git a/logic/GameClass/GameObj/Bullet.cs b/logic/GameClass/GameObj/Bullet.cs index b2d9bd60..b84eacec 100755 --- a/logic/GameClass/GameObj/Bullet.cs +++ b/logic/GameClass/GameObj/Bullet.cs @@ -15,7 +15,7 @@ public abstract class Bullet : ObjOfShip public abstract int SwingTime { get; } public abstract double ArmorModifier { get; } public abstract double ShieldModifier { get; } - public override bool IsRigid => true; // 默认为true + public override bool IsRigid(bool args = false) => true; // 默认为true public override ShapeType Shape => ShapeType.Circle; // 默认为圆形 public abstract BulletType TypeOfBullet { get; } public abstract bool CanAttack(GameObj target); diff --git a/logic/GameClass/GameObj/GameObj.cs b/logic/GameClass/GameObj/GameObj.cs index ca9aa34f..aabd09e1 100755 --- a/logic/GameClass/GameObj/GameObj.cs +++ b/logic/GameClass/GameObj/GameObj.cs @@ -25,7 +25,7 @@ public abstract class GameObj(XY initPos, int initRadius, GameObjType initType) protected XY position = initPos; public abstract XY Position { get; } - public abstract bool IsRigid { get; } + public abstract bool IsRigid(bool args = false); public abstract ShapeType Shape { get; } private readonly AtomicBool isRemoved = new(false); diff --git a/logic/GameClass/GameObj/Ship.cs b/logic/GameClass/GameObj/Ship.cs index c6073182..34ac4eeb 100755 --- a/logic/GameClass/GameObj/Ship.cs +++ b/logic/GameClass/GameObj/Ship.cs @@ -14,7 +14,7 @@ public class Ship : Movable, IShip { public AtomicLong TeamID { get; } = new(long.MaxValue); public AtomicLong PlayerID { get; } = new(long.MaxValue); - public override bool IsRigid => true; + public override bool IsRigid(bool args = false) => true; public override ShapeType Shape => ShapeType.Circle; public int ViewRange { get; } public override bool IgnoreCollideExecutor(IGameObj targetObj) diff --git a/logic/GameEngine/CollisionChecker.cs b/logic/GameEngine/CollisionChecker.cs index eb079554..9296d9eb 100755 --- a/logic/GameEngine/CollisionChecker.cs +++ b/logic/GameEngine/CollisionChecker.cs @@ -8,12 +8,12 @@ namespace GameEngine { internal class CollisionChecker(IMap gameMap) { - public IGameObj? CheckCollision(IMovable obj, XY Pos) + public IGameObj? CheckCollision(IMovable obj, XY Pos, bool collideWithWormhole = false) { // 在列表中检查碰撞 IGameObj? CheckCollisionInList(LockedClassList lst) { - return lst.Find(listObj => obj.WillCollideWith(listObj, Pos)); + return lst.Find(listObj => obj.WillCollideWith(listObj, Pos, collideWithWormhole)); } IGameObj? collisionObj; @@ -33,16 +33,16 @@ internal class CollisionChecker(IMap gameMap) /// 移动的物体 /// 移动的位移向量 /// 和它碰撞的物体 - public IGameObj? CheckCollisionWhenMoving(IMovable obj, XY moveVec) + public IGameObj? CheckCollisionWhenMoving(IMovable obj, XY moveVec, bool collideWithWormhole = false) { XY nextPos = obj.Position + moveVec; - if (!obj.IsRigid) + if (!obj.IsRigid()) { if (gameMap.IsOutOfBound(obj)) return gameMap.GetOutOfBound(nextPos); return null; } - return CheckCollision(obj, nextPos); + return CheckCollision(obj, nextPos, collideWithWormhole); } /// /// /// 可移动物体(圆)向矩形物体移动时,可移动且不会碰撞的最大距离。直接用double计算,防止误差 diff --git a/logic/GameEngine/MoveEngine.cs b/logic/GameEngine/MoveEngine.cs index 86e8b02c..76843fa6 100755 --- a/logic/GameEngine/MoveEngine.cs +++ b/logic/GameEngine/MoveEngine.cs @@ -23,7 +23,8 @@ namespace GameEngine public class MoveEngine( IMap gameMap, Func OnCollision, - Action EndMove + Action EndMove, + bool collideWithWormhole = false ) { /// @@ -46,6 +47,7 @@ public enum AfterCollision private readonly CollisionChecker collisionChecker = new(gameMap); private readonly Func OnCollision = OnCollision; + private bool collideWithWormhole = collideWithWormhole; /// /// 在无碰撞的前提下行走最远的距离 @@ -102,7 +104,7 @@ private bool LoopDo(IMovable obj, double direction, ref double deltaLen, long st do { flag = false; - IGameObj? collisionObj = collisionChecker.CheckCollisionWhenMoving(obj, res); + IGameObj? collisionObj = collisionChecker.CheckCollisionWhenMoving(obj, res, collideWithWormhole); if (collisionObj == null) break; diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index 29f2dd21..7e74fae5 100755 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -46,7 +46,8 @@ public AttackManager(Game game, Map gameMap, ShipManager shipManager) BulletBomb((Bullet)obj, null); } obj.CanMove.SetROri(false); - } + }, + collideWithWormhole: true ); this.game = game; } diff --git a/logic/Preparation/Interface/IGameObj.cs b/logic/Preparation/Interface/IGameObj.cs index 427dcc0f..c97d456d 100755 --- a/logic/Preparation/Interface/IGameObj.cs +++ b/logic/Preparation/Interface/IGameObj.cs @@ -9,7 +9,7 @@ public interface IGameObj public GameObjType Type { get; } public long ID { get; } public XY Position { get; } // if Square, Pos equals the center - public bool IsRigid { get; } + public bool IsRigid(bool args = false); public AtomicBool IsRemoved { get; } public ShapeType Shape { get; } public int Radius { get; } // if Square, Radius equals half length of one side diff --git a/logic/Preparation/Interface/IMovable.cs b/logic/Preparation/Interface/IMovable.cs index 0392235d..cf97dd9d 100755 --- a/logic/Preparation/Interface/IMovable.cs +++ b/logic/Preparation/Interface/IMovable.cs @@ -17,12 +17,12 @@ public interface IMovable : IGameObj public long StateNum { get; } public Semaphore ThreadNum { get; } public long MovingSetPos(XY moveVec, long stateNum); - public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞 + public bool WillCollideWith(IGameObj? targetObj, XY nextPos, bool collideWithWormhole = false) // 检查下一位置是否会和目标物碰撞 { if (targetObj == null) return false; // 会移动的只有子弹和人物,都是Circle - if (!targetObj.IsRigid || targetObj.ID == ID) + if (!targetObj.IsRigid(collideWithWormhole) || targetObj.ID == ID) return false; if (IgnoreCollideExecutor(targetObj) || targetObj.IgnoreCollideExecutor(this)) From 6025f16fe9cd3c216df3c99990406558a8b6d782 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 18 May 2024 13:10:04 +0000 Subject: [PATCH 7/9] chore(deps): update dependency tencent.qcloud.cos.sdk to v5.4.37 --- dependency/deploy/deploy.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependency/deploy/deploy.csproj b/dependency/deploy/deploy.csproj index 6dbb2996..56c26e02 100644 --- a/dependency/deploy/deploy.csproj +++ b/dependency/deploy/deploy.csproj @@ -25,7 +25,7 @@ - + From 8d0afa955e5809a028e36ceff389ef68d7b9f4c3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 19 May 2024 18:43:23 +0000 Subject: [PATCH 8/9] chore(deps): update dotnet monorepo --- dependency/Dockerfile/Dockerfile_run_client | 2 +- dependency/Dockerfile/Dockerfile_run_server | 4 ++-- installer/installer.csproj | 2 +- logic/Client/Client.csproj | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dependency/Dockerfile/Dockerfile_run_client b/dependency/Dockerfile/Dockerfile_run_client index 28e9cea2..947ee16b 100644 --- a/dependency/Dockerfile/Dockerfile_run_client +++ b/dependency/Dockerfile/Dockerfile_run_client @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0.204-jammy-amd64 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0.300-jammy-amd64 AS build LABEL maintainer="eesast" WORKDIR /usr/local COPY . . diff --git a/dependency/Dockerfile/Dockerfile_run_server b/dependency/Dockerfile/Dockerfile_run_server index 62249679..4a2f1c5d 100644 --- a/dependency/Dockerfile/Dockerfile_run_server +++ b/dependency/Dockerfile/Dockerfile_run_server @@ -1,10 +1,10 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0.204-jammy-amd64 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0.300-jammy-amd64 AS build LABEL maintainer="eesast" WORKDIR /usr/local COPY . . RUN dotnet publish logic/Server/Server.csproj -c Release -o /usr/local/Server --self-contained true -r linux-x64 -FROM mcr.microsoft.com/dotnet/sdk:8.0.204-jammy-amd64 +FROM mcr.microsoft.com/dotnet/sdk:8.0.300-jammy-amd64 LABEL maintainer="eesast" WORKDIR /usr/local COPY --from=build /usr/local/Server . diff --git a/installer/installer.csproj b/installer/installer.csproj index e82f1be8..f545a591 100755 --- a/installer/installer.csproj +++ b/installer/installer.csproj @@ -100,7 +100,7 @@ - + diff --git a/logic/Client/Client.csproj b/logic/Client/Client.csproj index 0d7c909a..20beb817 100755 --- a/logic/Client/Client.csproj +++ b/logic/Client/Client.csproj @@ -79,7 +79,7 @@ - + From af3506e7d87b2c85773ff6e424149a2f6e88d1b4 Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Mon, 20 May 2024 19:10:44 +0800 Subject: [PATCH 9/9] feat: :sparkles: modify data --- logic/Gaming/ActionManager.cs | 15 +++++++- logic/Gaming/Game.cs | 2 +- logic/Preparation/Utility/GameData.cs | 52 +++++++++++++-------------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index af7b6cb1..9812b56a 100755 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -350,8 +350,9 @@ public bool RepairWormhole(Ship ship) { IsBackground = true }.Start(); return false; } - public bool AddMoneyNaturally(Base team) + public bool TeamTask(Base team) { + Home home = team.Home; new Thread ( () => @@ -366,6 +367,18 @@ public bool AddMoneyNaturally(Base team) loopToDo: () => { team.AddMoney(team.MoneyAddPerSecond / GameData.NumOfStepPerSecond); + if (!home.HP.IsBelowMaxTimes(0.4)) + { + var ships = gameMap.ShipInTheRangeNotTeamID( + home.Position, GameData.FortRange, home.TeamID); + if (ships == null || ships.Count == 0) + { + return true; + } + var ship = ships[random.Next(ships.Count)]; + shipManager.BeAttacked(ship, + GameData.FortDamage / GameData.NumOfStepPerSecond, home.TeamID); + } return true; }, timeInterval: GameData.CheckInterval, diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index 5ae9c04c..10a14aa4 100755 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -114,7 +114,7 @@ public bool StartGame(int milliSeconds) // 开始游戏 foreach (var team in TeamList) { - actionManager.AddMoneyNaturally(team); + actionManager.TeamTask(team); ActivateShip(team.TeamID, ShipType.CivilShip); } gameMap.Timer.Start(() => { }, () => EndGame(), milliSeconds); diff --git a/logic/Preparation/Utility/GameData.cs b/logic/Preparation/Utility/GameData.cs index b031f553..c124ab57 100755 --- a/logic/Preparation/Utility/GameData.cs +++ b/logic/Preparation/Utility/GameData.cs @@ -74,41 +74,41 @@ public static bool IsInTheRange(XY pos1, XY pos2, int range) public const int BulletRadius = 200; // 子弹半径 public const int LaserRange = 4000; // 激光射程 - public const int LaserDamage = 1200; // 激光伤害 + public const int LaserDamage = 800; // 激光伤害 public const double LaserArmorModifier = 1.5; // 激光装甲修正 public const double LaserShieldModifier = 0.6; // 激光护盾修正 public const int LaserSpeed = 20000; // 激光速度 - public const int LaserCastTime = 300; // 激光前摇时间 - public const int LaserSwingTime = 300; // 激光后摇时间 + public const int LaserCastTime = 500; // 激光前摇时间 + public const int LaserSwingTime = 1000; // 激光后摇时间 public const int PlasmaRange = 4000; // 等离子射程 - public const int PlasmaDamage = 1300; // 等离子伤害 + public const int PlasmaDamage = 1000; // 等离子伤害 public const double PlasmaArmorModifier = 2.0; // 等离子装甲修正 public const double PlasmaShieldModifier = 0.4; // 等离子护盾修正 public const int PlasmaSpeed = 10000; // 等离子速度 - public const int PlasmaCastTime = 400; // 等离子前摇时间 - public const int PlasmaSwingTime = 400; // 等离子后摇时间 + public const int PlasmaCastTime = 800; // 等离子前摇时间 + public const int PlasmaSwingTime = 1600; // 等离子后摇时间 public const int ShellRange = 4000; // 炮弹射程 - public const int ShellDamage = 1800; // 炮弹伤害 + public const int ShellDamage = 1200; // 炮弹伤害 public const double ShellArmorModifier = 0.4; // 炮弹装甲修正 public const double ShellShieldModifier = 1.5; // 炮弹护盾修正 public const int ShellSpeed = 8000; // 炮弹速度 - public const int ShellCastTime = 200; // 炮弹前摇时间 - public const int ShellSwingTime = 200; // 炮弹后摇时间 - public const int MissileRange = 8000; // 导弹射程 + public const int ShellCastTime = 500; // 炮弹前摇时间 + public const int ShellSwingTime = 1000; // 炮弹后摇时间 + public const int MissileRange = 6000; // 导弹射程 public const int MissileBombRange = 1600; // 导弹爆炸范围 - public const int MissileDamage = 1600; // 导弹伤害 + public const int MissileDamage = 1100; // 导弹伤害 public const double MissileArmorModifier = 1.0; // 导弹装甲修正 public const int MissileSpeed = 6000; // 导弹速度 - public const int MissileCastTime = 600; // 导弹前摇时间 - public const int MissileSwingTime = 600; // 导弹后摇时间 - public const int ArcRange = 8000; // 电弧射程 - public const int ArcDamageMin = 100; // 电弧伤害 - public const int ArcDamageMax = 3200; // 电弧伤害 + public const int MissileCastTime = 1200; // 导弹前摇时间 + public const int MissileSwingTime = 1800; // 导弹后摇时间 + public const int ArcRange = 6000; // 电弧射程 + public const int ArcDamageMin = 800; // 电弧伤害 + public const int ArcDamageMax = 1600; // 电弧伤害 public const double ArcArmorModifier = 2.0; // 电弧装甲修正 public const double ArcShieldModifier = 2.0; // 电弧护盾修正 public const int ArcSpeed = 8000; // 电弧速度 - public const int ArcCastTime = 600; // 电弧前摇时间 - public const int ArcSwingTime = 600; // 电弧后摇时间 + public const int ArcCastTime = 1200; // 电弧前摇时间 + public const int ArcSwingTime = 1800; // 电弧后摇时间 public const int CivilShipCost = 4000; public const int CivilShipMaxHP = 3000; @@ -165,7 +165,7 @@ public static bool IsInTheRange(XY pos1, XY pos2, int range) public const int FlagShipArcGunCost = 24000; public const int ScoreHomePerSecond = 100; - public const int ScoreFactoryPerSecond = 300; + public const int ScoreFactoryPerSecond = 200; public const int ScoreProducer1PerSecond = 100; public const int ScoreProducer2PerSecond = 200; public const int ScoreProducer3PerSecond = 300; @@ -184,14 +184,14 @@ public static bool IsInTheRange(XY pos1, XY pos2, int range) public const int Shield2 = 3000; public const int Shield3 = 4000; - public const int ResourceHP = 16000; - public const int FactoryHP = 8000; - public const int CommunityHP = 6000; - public const int FortHP = 12000; - public const int WormholeHP = 18000; - public const int HomeHP = 24000; + public const int ResourceHP = 32000; + public const int FactoryHP = 12000; + public const int CommunityHP = 10000; + public const int FortHP = 16000; + public const int WormholeHP = 24000; + public const int HomeHP = 48000; public const int FortRange = 6000; - public const int FortDamage = 500; + public const int FortDamage = 300; } }