Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Grange007 authored May 11, 2024
2 parents 4f69c8e + b90b408 commit fa3b3a1
Show file tree
Hide file tree
Showing 50 changed files with 1,060 additions and 464 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/debug.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: deploy
on:
push:
branches: [dev, main, master]
pull_request:
branches: [dev, main, master]

env:
version: 1.1.0.0

jobs:
deploy-to-tencent-cos:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup dotnet-script
run: dotnet tool install --global dotnet-script
- name: Pre-Process
run: dotnet script .github/preProcess/MauiEnvConfig.csx
- name: Install Workloads
run: dotnet workload install maui-windows
- name: Create Folders need
run: |
mkdir D:\a\installer
mkdir D:\a\publish
- name: Copy THUAI7
run: Copy-Item -recurse D:\a\THUAI7\THUAI7\ D:\a\mirror\
- name: Test
run: tree D:\a\mirror
- name: Remove directories not needed
run: |
Remove-Item -recurse -force D:\a\mirror\.git
Remove-Item -recurse D:\a\mirror\.github
Remove-Item -recurse D:\a\mirror\installer
Remove-Item -recurse D:\a\mirror\interface
Remove-Item -recurse D:\a\mirror\logic
- name: Build Server
run: |
mkdir D:\a\mirror\logic
dotnet build "./logic/Server/Server.csproj" -o "D:\a\mirror\logic\Server" -p:WindowsAppSDKSelfContained=true -c Release
- name: Build Client
run: dotnet publish "./logic/Client/Client.csproj" -o "D:\a\mirror\logic\Client" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
- name: Deploy to bucket
run: dotnet run --project "./dependency/deploy/deploy.csproj" ${{ secrets.INSTALLER_COS_SECRET_ID }} ${{ secrets.INSTALLER_COS_SECRET_KEY }}
- name: Get installer package(No Key contained for safety)
run: |
$version=Get-ChildItem -Path D:\a\publish | ForEach-Object { $_.name }
[Environment]::SetEnvironmentVariable("version", $version, "Machine")
dotnet publish "./installer/installer.csproj" -o "D:\a\installer" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
./dependency/7z/7za.exe a -r D:\a\publish\Installer_v${version}.zip D:\a\installer\*
- name: Upload installer package
uses: actions/upload-artifact@v4
with:
name: Installer_v${{ env.version }}.zip
path: D:\a\publish\Installer_v${{ env.version }}.zip
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v5
Expand Down
12 changes: 6 additions & 6 deletions CAPI/cpp/API/include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ILogic
[[nodiscard]] virtual std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const = 0;
[[nodiscard]] virtual std::vector<int64_t> GetPlayerGUIDs() const = 0;
[[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetHomeHp() const = 0;
Expand Down Expand Up @@ -97,7 +97,7 @@ class IAPI
[[nodiscard]] virtual std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const = 0;
[[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetHomeHp() const = 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ class ShipAPI : public IShipAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const override;
Expand Down Expand Up @@ -259,7 +259,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down Expand Up @@ -320,7 +320,7 @@ class ShipDebugAPI : public IShipAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down Expand Up @@ -366,7 +366,7 @@ class TeamDebugAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down
2 changes: 1 addition & 1 deletion CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Logic : public ILogic
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const;
[[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetHomeHp() const;
Expand Down
2 changes: 2 additions & 0 deletions CAPI/cpp/API/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace AssistFunction
THUAI7::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)];
if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI7::PlaceType::Shadow)
return false;
if (distance > viewRange * viewRange)
return false;
int32_t divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100;
if (divide == 0)
return true;
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ THUAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
return logic.GetPlaceType(cellX, cellY);
}

int32_t ShipAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t TeamAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t ShipAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const
Expand Down
18 changes: 7 additions & 11 deletions CAPI/cpp/API/src/Communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,14 @@ bool Communication::Recycle(int32_t playerID, int32_t teamID)

bool Communication::TryConnection(int32_t playerID, int32_t teamID)
{
constexpr int maxRetryNum = 10;
protobuf::BoolRes reply;
ClientContext context;
auto request = THUAI72Proto::THUAI72ProtobufIDMsg(playerID, teamID);
for (int retryNum = 0; retryNum < maxRetryNum; retryNum++)
{
protobuf::BoolRes reply;
ClientContext context;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
auto status = THUAI7Stub->TryConnection(&context, request, &reply);
if (status.ok())
return true;
}
return false;
auto status = THUAI7Stub->TryConnection(&context, request, &reply);
if (status.ok())
return true;
else
return false;
}

void Communication::AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType)
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/src/DebugAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ THUAI7::PlaceType ShipDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
return logic.GetPlaceType(cellX, cellY);
}

int32_t ShipDebugAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t ShipDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const
Expand Down Expand Up @@ -395,9 +395,9 @@ THUAI7::PlaceType TeamDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
return logic.GetPlaceType(cellX, cellY);
}

int32_t TeamDebugAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t TeamDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const
Expand Down
24 changes: 18 additions & 6 deletions CAPI/cpp/API/src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,26 @@ THUAI7::PlaceType Logic::GetPlaceType(int32_t cellX, int32_t cellY) const
return currentState->gameMap[cellX][cellY];
}

int32_t Logic::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> Logic::GetConstructionState(int32_t cellX, int32_t cellY) const
{
std::unique_lock<std::mutex> lock(mtxState);
logger->debug("Called GetConstructionHp");
logger->debug("Called GetConstructionState");
auto pos = std::make_pair(cellX, cellY);
auto it = currentState->mapInfo->factoryState.find(pos);
auto it2 = currentState->mapInfo->communityState.find(pos);
auto it3 = currentState->mapInfo->fortState.find(pos);
if (it != currentState->mapInfo->factoryState.end())
{
return currentState->mapInfo->factoryState[pos].first;
return currentState->mapInfo->factoryState[pos];
}
else if (it2 != currentState->mapInfo->communityState.end())
return currentState->mapInfo->communityState[pos].first;
return currentState->mapInfo->communityState[pos];
else if (it3 != currentState->mapInfo->fortState.end())
return currentState->mapInfo->fortState[pos].first;
return currentState->mapInfo->fortState[pos];
else
{
logger->warn("Construction not found");
return -1;
return std::make_pair(-1, -1);
}
}

Expand Down Expand Up @@ -477,6 +477,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -491,6 +492,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -507,6 +509,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -521,6 +524,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -537,6 +541,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand All @@ -551,6 +556,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand Down Expand Up @@ -675,6 +681,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -689,6 +696,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -705,6 +713,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -719,6 +728,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -735,6 +745,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand All @@ -749,6 +760,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand Down
12 changes: 8 additions & 4 deletions CAPI/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pthread")

if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()

aux_source_directory(./API/src CPP_LIST)
aux_source_directory(./proto PROTO_CPP_LIST)

Expand All @@ -21,8 +25,8 @@ add_executable(capi ${CPP_LIST} ${PROTO_CPP_LIST})
target_include_directories(capi PUBLIC ${PROJECT_SOURCE_DIR}/proto ${PROJECT_SOURCE_DIR}/API/include ${PROJECT_SOURCE_DIR}/tclap/include ${PROJECT_SOURCE_DIR}/spdlog/include)

target_link_libraries(capi
protobuf::libprotobuf
gRPC::grpc
gRPC::grpc++_reflection
gRPC::grpc++
protobuf::libprotobuf
gRPC::grpc
gRPC::grpc++_reflection
gRPC::grpc++
)
8 changes: 4 additions & 4 deletions CAPI/python/PyAPI/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
return self.__logic.GetPlaceType(cellX, cellY)

def GetConstructionHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetConstructionHp(cellX, cellY)
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
return self.__logic.GetConstructionState(cellX, cellY)

def GetWormholeHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormholeHp(cellX, cellY)
Expand Down Expand Up @@ -184,8 +184,8 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
return self.__logic.GetPlaceType(cellX, cellY)

def GetConstructionHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetConstructionHp(cellX, cellY)
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
return self.__logic.GetConstructionState(cellX, cellY)

def GetWormholeHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormholeHp(cellX, cellY)
Expand Down
Loading

0 comments on commit fa3b3a1

Please sign in to comment.