Compare commits

...

7 Commits

Author SHA1 Message Date
王一涵 1c8fc9e5cc
Merge pull request #162 from SERENCH/dev
feat:  py文件的增改
2025-04-07 22:55:27 +08:00
SERENCH c3da762d43 fix: 🐛 2025-04-07 22:35:45 +08:00
Chen 0de8386eb4
Merge branch 'eesast:dev' into dev 2025-04-07 22:30:11 +08:00
SERENCH 5d7ca8c354 feat: py增改 2025-04-07 22:29:11 +08:00
Chen 9a25c205b5
Update CAPI/python/structures.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-04-07 20:15:26 +08:00
SERENCH cef37bbd4f fix: 🐛 berserk换bool类型 2025-04-07 15:33:18 +08:00
SERENCH ab064bb64b feat: py文件的增改 2025-04-07 13:19:57 +08:00
12 changed files with 1458 additions and 299 deletions

View File

@ -71,12 +71,12 @@ namespace THUAI8
Camp1Character5 = 5,
Camp1Character6 = 6,
CampCharacter1 = 7,
CampCharacter2 = 8,
CampCharacter3 = 9,
CampCharacter4 = 10,
CampCharacter5 = 11,
CampCharacter6 = 12,
Camp2Character1 = 7,
Camp2Character2 = 8,
Camp2Character3 = 9,
Camp2Character4 = 10,
Camp2Character5 = 11,
Camp2Character6 = 12,
};
enum class EquipmentType : unsigned char
@ -218,23 +218,16 @@ namespace THUAI8
CharacterState characterActiveState;
CharacterState blindState;
bool isBlind;
long blindTime;
// CharacterState knockbackState;
// double knockbackTime;
CharacterState stunnedState;
bool isStunned;
long stunnedTime;
CharacterState invisibleState;
bool isInvisible;
long invisibleTime;
// CharacterState healingState;
// double healingTime;
// CharacterState berserkState;
// double berserkTime;
CharacterState burnedState;
bool isBurned;
long burnedTime;
double harmCut;
long harmCutTime;
CharacterState deceasedState;
CharacterState characterPassiveState;
@ -246,10 +239,10 @@ namespace THUAI8
int32_t viewRange;
int32_t commonAttack;
long commonAttackCD;
int64_t commonAttackCD;
int32_t commonAttackRange;
long skillAttackCD;
int64_t skillAttackCD;
int32_t economyDepletion;
int32_t killScore;
@ -259,17 +252,16 @@ namespace THUAI8
int32_t shieldEquipment;
// int32_t shild;
int32_t shoesEquipment;
long shoesEquipmentTime;
long purificationEquipmentTime;
int64_t shoesTime;
bool isPurified;
int64_t purifiedTime;
bool isBerserk;
int64_t berserkTime;
// CharacterBuffType attackBuff;
long attackBuffTime;
// CharacterBuffType defenseBuff;
// long defenseBuffTime;
// CharacterBuffType speedBuff;
long speedBuffTime;
// CharacterBuffType visionBuff;
long visionBuffTime;
int32_t attackBuffNum;
int64_t attackBuffTime;
int64_t speedBuffTime;
int64_t visionBuffTime;
};
struct Team

View File

@ -210,15 +210,45 @@ namespace Proto2THUAI8
inline std::shared_ptr<THUAI8::Character> Protobuf2THUAI8Character(const protobuf::MessageOfCharacter& CharacterMsg)
{
auto character = std::make_shared<THUAI8::Character>();
character->characterType = characterTypeDict.at(CharacterMsg.character().characterType());
character->hp = CharacterMsg.character().hp();
character->guid = CharacterMsg.character().guid();
character->teamID = CharacterMsg.character().teamid();
character->playerID = CharacterMsg.character().playerid();
character->characterType = characterTypeDict.at(CharacterMsg.character().charactertype());
character->characterActiveState = characterStateDict.at(CharacterMsg.character().characteractivestate());
character->isBlind = CharacterMsg.character().isblind();
character->blindTime = CharacterMsg.character().blindtime();
character->isStunned = CharacterMsg.character().isstunned();
character->stunnedTime = CharacterMsg.character().stunnedtime();
character->isInvisible = CharacterMsg.character().isinvisible();
character->invisibleTime = CharacterMsg.character().invisibletime();
character->isBurned = CharacterMsg.character().isburned();
character->burnedTime = CharacterMsg.character().burnedtime();
character->harmCut = CharacterMsg.character().harmcut();
character->harmCutTime = CharacterMsg.character().harmcuttime();
character->characterPassiveState = characterStateDict.at(CharacterMsg.character().characterpassivestate());
character->x = CharacterMsg.character().x();
character->y = CharacterMsg.character().y();
character->state = characterStateDict.at(CharacterMsg.character().state());
character->equipmentType = equipmentTypeDict.at(CharacterMsg.character().equipmenttype());
return character;
character->facingDirection = CharacterMsg.character().facingdirection();
character->speed = CharacterMsg.character().speed();
character->viewRange = CharacterMsg.character().viewrange();
character->commonAttack = CharacterMsg.character().commonattack();
character->commonAttackCD = CharacterMsg.character().commonattackcd();
character->commonAttackRange = CharacterMsg.character().commonattackrange();
character->skillAttackCD = CharacterMsg.character().skillattackcd();
character->economyDepletion = CharacterMsg.character().economydepletion();
character->killScore = CharacterMsg.character().killscore();
character->hp = CharacterMsg.character().hp();
character->shieldEquipment = CharacterMsg.character().shieldequipment();
character->shoesEquipment = CharacterMsg.character().shoesequipment();
character->shoesTime = CharacterMsg.character().shoestime();
character->isPurified = CharacterMsg.character().ispurified();
character->purifiedTime = CharacterMsg.character().purifiedtime();
character->isBerserk = CharacterMsg.character().isberserk();
character->berserkTime = CharacterMsg.character().berserktime();
character->attackBuffNum = CharacterMsg.character().attackbuffnum();
character->attackBuffTime = CharacterMsg.character().attackbufftime();
character->speedBuffTime = CharacterMsg.character().speedbufftime();
character->visionBuffTime = CharacterMsg.character().visionbufftime();
}
inline std::shared_ptr<THUAI8::Team> Protobuf2THUAI8Team(const protobuf::MessageOfTeam& TeamMsg)
@ -280,35 +310,36 @@ namespace Proto2THUAI8
return constructionState;
}
inline std::shared_ptr<THUAI8::GameMap> Protobuf2THUAI8GameMap(const protobuf::MessageOfGameMap& GameMapMsg)
{
auto gameMap = std::make_shared<THUAI8::GameMap>();
for (const auto& barracks : GameMapMsg.gamemap().barracksstate())
{
gameMap->barracksState[{barracks.first.x(), barracks.first.y()}] = {barracks.second.teamid(), barracks.second.hp()};
}
for (const auto& spring : GameMapMsg.gamemap().springstate())
{
gameMap->springState[{spring.first.x(), spring.first.y()}] = {spring.second.teamid(), spring.second.hp()};
}
for (const auto& farm : GameMapMsg.gamemap().farmstate())
{
gameMap->farmState[{farm.first.x(), farm.first.y()}] = {farm.second.teamid(), farm.second.hp()};
}
for (const auto& trap : GameMapMsg.gamemap().trapstate())
{
gameMap->trapState[{trap.first.x(), trap.first.y()}] = {trap.second.teamid(), trap.second.hp()};
}
for (const auto& economyResource : GameMapMsg.gamemap().economyresource())
{
gameMap->economyResource[{economyResource.first.x(), economyResource.first.y()}] = economyResource.second;
}
for (const auto& additionResource : GameMapMsg.gamemap().additionresource())
{
gameMap->additionResource[{additionResource.first.x(), additionResource.first.y()}] = additionResource.second;
}
return gameMap;
}
// ?
// inline std::shared_ptr<THUAI8::GameMap> Protobuf2THUAI8GameMap(const protobuf::MessageOfGameMap& GameMapMsg)
// {
// auto gameMap = std::make_shared<THUAI8::GameMap>();
// for (const auto& barracks : GameMapMsg.gamemap().barracksstate())
// {
// gameMap->barracksState[{barracks.first.x(), barracks.first.y()}] = {barracks.second.teamid(), barracks.second.hp()};
// }
// for (const auto& spring : GameMapMsg.gamemap().springstate())
// {
// gameMap->springState[{spring.first.x(), spring.first.y()}] = {spring.second.teamid(), spring.second.hp()};
// }
// for (const auto& farm : GameMapMsg.gamemap().farmstate())
// {
// gameMap->farmState[{farm.first.x(), farm.first.y()}] = {farm.second.teamid(), farm.second.hp()};
// }
// for (const auto& trap : GameMapMsg.gamemap().trapstate())
// {
// gameMap->trapState[{trap.first.x(), trap.first.y()}] = {trap.second.teamid(), trap.second.hp()};
// }
// for (const auto& economyResource : GameMapMsg.gamemap().economyresource())
// {
// gameMap->economyResource[{economyResource.first.x(), economyResource.first.y()}] = economyResource.second;
// }
// for (const auto& additionResource : GameMapMsg.gamemap().additionresource())
// {
// gameMap->additionResource[{additionResource.first.x(), additionResource.first.y()}] = additionResource.second;
// }
// return gameMap;
// }
} // namespace Proto2THUAI8
// 辅助函数用于将proto信息转换为THUAI8的信息
namespace THUAI8Proto
@ -485,7 +516,7 @@ namespace THUAI8Proto
return equipMsg;
}
inline protobuf::CreatCharacterMsg(int64_t team_id, THUAI8::CharacterType character_type, int32_t birthpoint_index)
inline protobuf::CreatCharacterMsg THUAI82ProtobufCreatCharacterMsg(int64_t team_id, THUAI8::CharacterType character_type, int32_t birthpoint_index)
{
protobuf::CreatCharacterMsg creatCharacterMsg;
creatCharacterMsg.set_team_id(team_id);
@ -494,7 +525,7 @@ namespace THUAI8Proto
return creatCharacterMsg;
}
inline protobuf::ConstructMsg(int64_t character_id, int64_t team_id, THUAI8::ConstructionType construction_type, int32_t x, int32_t y)
inline protobuf::ConstructMsg THUAI82ProtobufConstructMsg(int64_t character_id, int64_t team_id, THUAI8::ConstructionType construction_type)
{
protobuf::ConstructMsg constructMsg;
constructMsg.set_character_id(character_id);
@ -503,7 +534,7 @@ namespace THUAI8Proto
return constructMsg;
}
inline protobuf::CharacterMsg(int64_t character_id, int64_t team_id, THUAI8::CharacterType character_type)
inline protobuf::CharacterMsg THUAI82ProtobufCharacterMsg(int64_t character_id, int64_t team_id, THUAI8::CharacterType character_type)
{
protobuf::CharacterMsg characterMsg;
characterMsg.set_character_id(character_id);
@ -512,7 +543,7 @@ namespace THUAI8Proto
return characterMsg;
}
inline protobuf::CastMsg(int64_t character_id, int64_t skill_id, int64_t team_id, int32_t attack_range, int32_t x, int32_t y, double angle)
inline protobuf::CastMsg THUAI82ProtobufCastMsg(int64_t character_id, int64_t skill_id, int64_t team_id, int32_t attack_range, int32_t x, int32_t y, double angle)
{
protobuf::CastMsg castMsg;
castMsg.set_character_id(character_id);
@ -525,7 +556,7 @@ namespace THUAI8Proto
return castMsg;
}
inline protobuf::AttackMsg(int64_t character_id, int64_t team_id, int64_t attacked_character_id, int32_t attack_range)
inline protobuf::AttackMsg THUAI82ProtobufAttackMsg(int64_t character_id, int64_t team_id, int64_t attacked_character_id, int32_t attack_range)
{
protobuf::AttackMsg attackMsg;
attackMsg.set_character_id(character_id);

View File

@ -561,7 +561,7 @@ void TeamDebugAPI::PrintSelfInfo() const
logger->info("*********************\n");
}
void ShipDebugAPI::Play(IAI& ai)
void CharacterDebugAPI::Play(IAI& ai)
{
ai.play(*this);
}

View File

@ -57,12 +57,12 @@ std::shared_ptr<const THUAI8::Character> Logic::GetSelfInfo() const
return currentState->characterSelf;
}
// std::shared_ptr<const THUAI8::Team> Logic::TeamGetSelfInfo() const
// {
//     std::unique_lock<std::mutex> lock(mtxState);
//     logger->debug("Called TeamGetSelfInfo");
//     return currentState->teamSelf;
// }
std::shared_ptr<const THUAI8::Team> Logic::TeamGetSelfInfo() const
{
    std::unique_lock<std::mutex> lock(mtxState);
    logger->debug("Called TeamGetSelfInfo");
    return currentState->teamSelf;
}
std::vector<std::vector<THUAI8::PlaceType>> Logic::GetFullMap() const
{
@ -611,12 +611,23 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
switch (Proto2THUAI8::messageOfObjDict[item.message_of_obj_case()])
{
case THUAI8::MessageOfObj::CharacterMessage:
if (item.character_message().team_id() != teamID && HaveOverView(item.character_message().x(), item.character_message().y()))
if (item.character_message().team_id() != teamID && HaveOverView(item.character_message().x(), item.character_message().y()) && !item.character_message().is_invisible())
{
std::shared_ptr<THUAI8::Character> Character = Proto2THUAI8::Protobuf2THUAI8Character(item.character_message());
bufferState->enemyCharacters.push_back(Character);
logger->debug("Load EnemyCharacter!");
}
else if (item.character_message().team_id() == teamID && playerID != item.character_message().player_id())
{
std::shared_ptr<THUAI8::Character> Character = Proto2THUAI8::Protobuf2THUAI8Character(item.character_message());
bufferState->characters.push_back(Character);
logger->debug("Load Character!");
}
else if (item.character_message().team_id() == teamID && playerID == item.character_message().player_id())
{
bufferState->characterSelf = Proto2THUAI8::Protobuf2THUAI8Character(item.character_message());
logger->debug("Load Self Character!");
}
break;
case THUAI8::MessageOfObj::BarracksMessage:
if (item.barracks_message().team_id() == teamID || HaveOverView(item.barracks_message().x(), item.barracks_message().y()))

View File

@ -15,7 +15,6 @@ class Setting:
return False
@staticmethod
<<<<<<< HEAD
def BuddhistsCharacterTypes() -> List[THUAI8.CharacterType]:
return [
THUAI8.CharacterType.Monk,
@ -30,40 +29,20 @@ class Setting:
return [
THUAI8.CharacterType.JiuTouYuanSheng,
THUAI8.CharacterType.HongHaier,
=======
def ShipTypes() -> List[THUAI8.CharacterType]:
return [
THUAI8.CharacterType.Monk,
THUAI8.CharacterType.MonkeyKing,
THUAI8.CharacterType.Pigsy,
THUAI8.CharacterType.ShaWujing,
THUAI8.CharacterType.Whitedragonhorse,
THUAI8.CharacterType.JiuTouYuanSheng,
THUAI8.CharacterType.Honghaier,
>>>>>>> 5a1751dc64f09ba19aaa818e5dc99172d15f4c69
THUAI8.CharacterType.Gyuumao,
THUAI8.CharacterType.Princess_Iron_Fan,
THUAI8.CharacterType.Spider,
]
<<<<<<< HEAD
numOfGridPerCell: Final[int] = 1000
=======
numOfGridPerCell: Final[int] = 1000
>>>>>>> 5a1751dc64f09ba19aaa818e5dc99172d15f4c69
class AI(IAI):
def __init__(self, pID: int):
self.__playerID = pID
<<<<<<< HEAD
def CharacterPlay(self, api: ICharacterAPI) -> None:
=======
def ShipPlay(self, api: IShipAPI) -> None:
>>>>>>> 5a1751dc64f09ba19aaa818e5dc99172d15f4c69
# 公共操作
if self.__playerID == 1:
# player1的操作
@ -77,13 +56,7 @@ class AI(IAI):
elif self.__playerID == 4:
# player4的操作
return
<<<<<<< HEAD
return
=======
elif self.__playerID == 5:
# player4的操作
return
>>>>>>> 5a1751dc64f09ba19aaa818e5dc99172d15f4c69
def TeamPlay(self, api: ITeamAPI) -> None:
# player0的操作

31
CAPI/python/State.py Normal file
View File

@ -0,0 +1,31 @@
from typing import List, Union
import PyAPI.structures as THUAI8
class State:
def __init__(self) -> None:
self.teamScore = 0
self.self = None
self.characters = []
self.enemyCharacters = []
self.gameMap = []
self.mapInfo = THUAI8.GameMap()
self.gameInfo = THUAI8.GameInfo()
self.guids = []
self.allGuids = []
teamScore: int
self: Union[THUAI8.Character, THUAI8.Team]
characters: List[THUAI8.Character]
enemyCharacters: List[THUAI8.Character]
gameMap: List[List[THUAI8.PlaceType]]
mapInfo: THUAI8.GameMap
gameInfo: THUAI8.GameInfo
guids: List[int]
allGuids: List[int]

View File

@ -1,21 +1,23 @@
import os
from typing import List, Union, Callable, Tuple
import threading
import logging
import copy
import logging
import os
import platform
import proto.MessageType_pb2 as MessageType
import proto.Message2Server_pb2 as Message2Server
import proto.Message2Clients_pb2 as Message2Clients
import threading
from queue import Queue
from typing import Callable, List, Tuple, Union
import proto.Message2Clients_pb2 as Message2Clients
import proto.Message2Server_pb2 as Message2Server
import proto.MessageType_pb2 as MessageType
import PyAPI.structures as THUAI8
from PyAPI.utils import Proto2THUAI8, AssistFunction
from PyAPI.API import CharacterAPI, TeamAPI
from PyAPI.DebugAPI import CharacterDebugAPI, TeamDebugAPI
from PyAPI.AI import Setting
from PyAPI.API import CharacterAPI, TeamAPI
from PyAPI.Communication import Communication
from PyAPI.DebugAPI import CharacterDebugAPI, TeamDebugAPI
from PyAPI.Interface import IGameTimer, ILogic
from PyAPI.State import State
from PyAPI.Interface import ILogic, IGameTimer
from PyAPI.utils import AssistFunction, Proto2THUAI8
class Logic(ILogic):
def __init__(
@ -65,13 +67,12 @@ class Logic(ILogic):
with self.__mtxState:
self.__logger.debug("Called GetCharacters")
return copy.deepcopy(self.__currentState.characters)
def GetEnemyCharacters(self) -> List[THUAI8.Character]:
with self.__mtxState:
self.__logger.debug("Called GetEnemyCharacters")
return copy.deepcopy(self.__currentState.enemyCharacters)
return copy.deepcopy(self.__currentState.enemyCharacters)
def GetSelfInfo(self) -> Union[THUAI8.Character, THUAI8.Team]:
with self.__mtxState:
self.__logger.debug("Called GetSelfInfo")
@ -106,7 +107,9 @@ class Logic(ILogic):
def SendMessage(self, toID: int, message: Union[str, bytes]) -> bool:
self.__logger.debug("Called SendMessage")
return self.__comm.SendMessage(toID, message, self.__playerID, self.__teamID)
return self.__comm.SendMessage(
toID, message, self.__playerID, self.__teamID
)
def HaveMessage(self) -> bool:
self.__logger.debug("Called HaveMessage")
@ -132,8 +135,10 @@ class Logic(ILogic):
def GetPlayerGUIDs(self) -> List[int]:
with self.__mtxState:
return copy.deepcopy(self.__currentState.guids)
def GetConstructionState(self, cellX: int, cellY: int) -> THUAI8.ConstructionState | None:
def GetConstructionState(
self, cellX: int, cellY: int
) -> THUAI8.ConstructionState | None:
with self.__mtxState:
self.__logger.debug("Called GetConstructionState")
if (cellX, cellY) in self.__currentState.mapInfo.barracksState:
@ -154,26 +159,37 @@ class Logic(ILogic):
else:
self.__logger.warning("GetConstructionState: Out of range")
return None
def GetEconomyResourceState(self, cellX: int, cellY: int) -> int:
with self.__mtxState:
self.__logger.debug("Called GetEconomyResourceState")
if (cellX, cellY) not in self.__currentState.mapInfo.economyResourceState:
if (
cellX,
cellY,
) not in self.__currentState.mapInfo.economyResourceState:
self.__logger.warning("GetEconomyResourceState: Out of range")
return -1
else:
return copy.deepcopy(
self.__currentState.mapInfo.economyResourceState[(cellX, cellY)]
)
def GetAdditionResourceState(self, cellX: int, cellY: int) -> int:
with self.__mtxState:
self.__logger.debug("Called GetAdditionResourceState")
if (cellX, cellY) not in self.__currentState.mapInfo.additionResourceState:
if (
cellX,
cellY,
) not in self.__currentState.mapInfo.additionResourceState:
self.__logger.warning("GetAdditionResourceState: Out of range")
return -1
else:
return copy.deepcopy(
self.__currentState.mapInfo.additionResourceState[(cellX, cellY)]
self.__currentState.mapInfo.additionResourceState[
(cellX, cellY)
]
)
def GetEconomy(self) -> int:
with self.__mtxState:
self.__logger.debug("Called GetEconomy")
@ -182,6 +198,7 @@ class Logic(ILogic):
if self.__teamID == 0
else self.__currentState.gameInfo.monstersTeamEconomy
)
def GetScore(self) -> int:
with self.__mtxState:
self.__logger.debug("Called GetScore")
@ -190,23 +207,30 @@ class Logic(ILogic):
if self.__teamID == 0
else self.__currentState.gameInfo.monstersTeamEconomy
)
def CommonAttack(self, playerID: int, teamID: int, ATKplayerID: int, ATKteamID: int) -> bool:
def CommonAttack(
self, playerID: int, teamID: int, ATKplayerID: int, ATKteamID: int
) -> bool:
self.__logger.debug("Called CommonAttack")
return self.__comm.Attack(playerID, teamID, ATKplayerID, ATKteamID)
def SkillAttack(self, playerID: int, teamID: int, angle: float) -> bool:
self.__logger.debug("Called CommonAttack")
return self.__comm.Attack(playerID, teamID, ATKplayerID, ATKteamID)
def Recover(self, recover: int) -> bool:
self.__logger.debug("Called Recover")
return self.__comm.Recover(self.__playerID, self.__teamID, recover)
def Construct(self, constructionType: THUAI8.ConstructionType) -> bool:
self.__logger.debug("Called Construct")
return self.__comm.Construct(constructionType, self.__playerID, self.__teamID)
return self.__comm.Construct(
constructionType, self.__playerID, self.__teamID
)
def BuildCharacter(self, CharacterType: THUAI8.CharacterType, birthIndex: int) -> bool:
def BuildCharacter(
self, CharacterType: THUAI8.CharacterType, birthIndex: int
) -> bool:
self.__logger.debug("Called BuildCharacter")
return self.__comm.BuildCharacter(self.__teamID, characterType, birthIndex)
@ -214,18 +238,20 @@ class Logic(ILogic):
self.__logger.debug("Called Rebuild")
return self.__comm.Rebuild(constructionType, self.__playerID, self.__teamID)
def InstallEquipment(self, playerID: int, equipmentType: THUAI8.EquipmentType) -> bool:
def InstallEquipment(
self, playerID: int, equipmentType: THUAI8.EquipmentType
) -> bool:
self.__logger.debug("Called InstallEquipment")
return self.__comm.InstallEquipment(equipmentType, playerID, self.__teamID)
def Recycle(self, playerID: int) -> bool:
self.__logger.debug("Called Recycle")
return self.__comm.Recycle(playerID, self.__teamID)
def EndAllAction(self) -> bool:
self.__logger.debug("Called EndAllAction")
return self.__comm.EndAllAction(self.__playerID, self.__teamID)
def HaveView(
self, gridX: int, gridY: int, selfX: int, selfY: int, viewRange: int
) -> bool:
@ -237,7 +263,7 @@ class Logic(ILogic):
def TryConnection(self) -> bool:
self.__logger.info("Called TryConnection")
return self.__comm.TryConnection(self.__playerID, self.__teamID)
return self.__comm.TryConnection(self.__playerID, self.__teamID)
def __TryConnection(self) -> bool:
self.__logger.info("Try to connect to the server.")
@ -246,7 +272,9 @@ class Logic(ILogic):
def __ProcessMessage(self) -> None:
def messageThread():
self.__logger.info("Message thread started")
self.__comm.AddPlayer(self.__playerID, self.__teamID, self.__CharacterType)
self.__comm.AddPlayer(
self.__playerID, self.__teamID, self.__CharacterType
)
self.__logger.info("Player added")
while self.__gameState != THUAI8.GameState.GameEnd:
@ -296,8 +324,8 @@ class Logic(ILogic):
with self.__cvBuffer:
self.__bufferState.characters.clear()
self.__bufferState.enemyCharacters.clear()
# self.__bufferState.bullets.clear()
# self.__bufferState.bombedBullets.clear()
# self.__bufferState.bullets.clear()
# self.__bufferState.bombedBullets.clear()
self.__bufferState.guids.clear()
self.__bufferState.allGuids.clear()
self.__logger.debug("Buffer cleared")
@ -343,8 +371,10 @@ class Logic(ILogic):
item.character_message.player_id == self.__playerID
and item.character_message.team_id == self.__teamID
):
self.__bufferState.self = Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
self.__bufferState.self = (
Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
)
)
# self.__bufferState.ships.append(self.__bufferState.self)
self.__logger.debug("Load self character")
@ -361,7 +391,9 @@ class Logic(ILogic):
if item.WhichOneof("message_of_obj") == "character_message":
if item.character_message.team_id == self.__teamID:
self.__bufferState.characters.append(
Proto2THUAI8.Protobuf2THUAI8Character(item.character_message)
Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
)
)
self.__logger.debug("Load Character")
@ -378,31 +410,39 @@ class Logic(ILogic):
self.__bufferState.gameMap,
):
self.__bufferState.enemyCharacters.append(
Proto2THUAI8.Protobuf2THUAI8Character(item.character_message)
Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
)
)
self.__logger.debug("Load enemy character")
else:
self.__bufferState.characters.append(
Proto2THUAI8.Protobuf2THUAI8Character(item.character_message)
Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
)
)
self.__logger.debug("Load character")
elif item.WhichOneof("message_of_obj") == "barracks_message":
barracks_message = item.barracks_message
if barracks_message.team_id == self.__teamID or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
barracks_message.x,
barracks_message.y,
self.__bufferState.gameMap,
if (
barracks_message.team_id == self.__teamID
or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
barracks_message.x,
barracks_message.y,
self.__bufferState.gameMap,
)
):
pos = (
AssistFunction.GridToCell(barracks_message.x),
AssistFunction.GridToCell(barracks_message.y)
AssistFunction.GridToCell(barracks_message.y),
)
if pos not in self.__bufferState.mapInfo.barracksState:
self.__bufferState.mapInfo.barracksState[pos] = (
barracks_message.team_id, barracks_message.hp
barracks_message.team_id,
barracks_message.hp,
)
if barracks_message.team_id == self.__teamID:
self.__logger.debug("Load Barracks!")
@ -410,30 +450,35 @@ class Logic(ILogic):
self.__logger.debug("Load EnemyBarracks!")
else:
self.__bufferState.mapInfo.barracksState[pos] = (
barracks_message.team_id, barracks_message.hp
barracks_message.team_id,
barracks_message.hp,
)
if barracks_message.team_id == self.__teamID:
self.__logger.debug("Update Barracks!")
else:
self.__logger.debug("Update EnemyBarracks!")
elif item.WhichOneof("message_of_obj") == "spring_message":
spring_message = item.spring_message
if spring_message.team_id == self.__teamID or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
spring_message.x,
spring_message.y,
self.__bufferState.gameMap,
if (
spring_message.team_id == self.__teamID
or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
spring_message.x,
spring_message.y,
self.__bufferState.gameMap,
)
):
pos = (
AssistFunction.GridToCell(spring_message.x),
AssistFunction.GridToCell(spring_message.y)
AssistFunction.GridToCell(spring_message.y),
)
if pos not in self.__bufferState.mapInfo.springState:
self.__bufferState.mapInfo.springState[pos] = (
spring_message.team_id, spring_message.hp
spring_message.team_id,
spring_message.hp,
)
if spring_message.team_id == self.__teamID:
self.__logger.debug("Load Spring!")
@ -441,13 +486,14 @@ class Logic(ILogic):
self.__logger.debug("Load EnemySpring!")
else:
self.__bufferState.mapInfo.springState[pos] = (
spring_message.team_id, spring_message.hp
spring_message.team_id,
spring_message.hp,
)
if spring_message.team_id == self.__teamID:
self.__logger.debug("Update Spring!")
else:
self.__logger.debug("Update EnemySpring!")
elif item.WhichOneof("message_of_obj") == "farm_message":
farm_message = item.farm_message
if farm_message.team_id == self.__teamID or AssistFunction.HaveView(
@ -460,11 +506,12 @@ class Logic(ILogic):
):
pos = (
AssistFunction.GridToCell(farm_message.x),
AssistFunction.GridToCell(farm_message.y)
AssistFunction.GridToCell(farm_message.y),
)
if pos not in self.__bufferState.mapInfo.farmState:
self.__bufferState.mapInfo.farmState[pos] = (
farm_message.team_id, farm_message.hp
farm_message.team_id,
farm_message.hp,
)
if farm_message.team_id == self.__teamID:
self.__logger.debug("Load Farm!")
@ -472,7 +519,8 @@ class Logic(ILogic):
self.__logger.debug("Load EnemyFarm!")
else:
self.__bufferState.mapInfo.farmState[pos] = (
farm_message.team_id, farm_message.hp
farm_message.team_id,
farm_message.hp,
)
if farm_message.team_id == self.__teamID:
self.__logger.debug("Update Farm!")
@ -491,7 +539,7 @@ class Logic(ILogic):
):
pos = (
AssistFunction.GridToCell(trap_message.x),
AssistFunction.GridToCell(trap_message.y)
AssistFunction.GridToCell(trap_message.y),
)
if pos not in self.__bufferState.mapInfo.trapState:
self.__bufferState.mapInfo.trapState[pos] = (
@ -514,43 +562,55 @@ class Logic(ILogic):
economy_message = item.economy_resource_message
pos = (
AssistFunction.GridToCell(economy_message.x),
AssistFunction.GridToCell(economy_message.y)
AssistFunction.GridToCell(economy_message.y),
)
if pos not in self.__bufferState.mapInfo.economyResourceState:
self.__bufferState.mapInfo.economyResourceState[pos] = economy_message.hp
self.__bufferState.mapInfo.economyResourceState[pos] = (
economy_message.hp
)
self.__logger.debug("Load EconomyResource!")
else:
self.__bufferState.mapInfo.economyResourceState[pos] = economy_message.hp
self.__bufferState.mapInfo.economyResourceState[pos] = (
economy_message.hp
)
self.__logger.debug("Update EconomyResource!")
elif item.WhichOneof("message_of_obj") == "addition_resource_message":
addition_message = item.addition_resource_message
pos = (
AssistFunction.GridToCell(addition_message.x),
AssistFunction.GridToCell(addition_message.y)
AssistFunction.GridToCell(addition_message.y),
)
if pos not in self.__bufferState.mapInfo.additionResourceState:
self.__bufferState.mapInfo.additionResourceState[pos] = addition_message.hp
self.__bufferState.mapInfo.additionResourceState[pos] = (
addition_message.hp
)
self.__logger.debug("Load AdditionResource!")
else:
self.__bufferState.mapInfo.additionResourceState[pos] = addition_message.hp
self.__bufferState.mapInfo.additionResourceState[pos] = (
addition_message.hp
)
self.__logger.debug("Update AdditionResource!")
elif item.WhichOneof("message_of_obj") == "news_message":
news = item.news_message
if news.to_id == self.__playerID and news.team_id == self.__teamID:
news_type = Proto2THUAI8.newsTypeDict.get(news.news_case())
if news_type == THUAI8.NewsType.TextMessage:
self.__messageQueue.append((news.from_id, news.text_message))
self.__messageQueue.append(
(news.from_id, news.text_message)
)
self.__logger.debug("Load Text News!")
elif news_type == THUAI8.NewsType.BinaryMessage:
self.__messageQueue.append((news.from_id, news.binary_message))
self.__messageQueue.append(
(news.from_id, news.binary_message)
)
self.__logger.debug("Load Binary News!")
else:
self.__logger.error("Unknown NewsType!")
# NullMessageOfObj和其他默认情况不需要处理
elif self.__playerType == THUAI8.PlayerType.Team:
# 定义视野检查函数
def HaveOverView(targetX: int, targetY: int) -> bool:
@ -561,24 +621,27 @@ class Logic(ILogic):
targetX,
targetY,
character.viewRange,
self.__bufferState.gameMap
self.__bufferState.gameMap,
):
return True
return False
def HaveOverTrapView(targetX: int, targetY: int) -> bool:
for character in self.__bufferState.characters:
if AssistFunction.HaveView(
character.x,
character.y,
targetX,
targetY,
character.viewRange,
self.__bufferState.gameMap
) and character.visionBuffTime > 0:
if (
AssistFunction.HaveView(
character.x,
character.y,
targetX,
targetY,
character.viewRange,
self.__bufferState.gameMap,
)
and character.visionBuffTime > 0
):
return True
return False
if item.WhichOneof("message_of_obj") == "character_message":
if item.character_message.team_id != self.__teamID:
if AssistFunction.HaveView(
@ -590,31 +653,39 @@ class Logic(ILogic):
self.__bufferState.gameMap,
):
self.__bufferState.enemyCharacters.append(
Proto2THUAI8.Protobuf2THUAI8Character(item.character_message)
Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
)
)
self.__logger.debug("Load enemy character")
else:
self.__bufferState.characters.append(
Proto2THUAI8.Protobuf2THUAI8Character(item.character_message)
Proto2THUAI8.Protobuf2THUAI8Character(
item.character_message
)
)
self.__logger.debug("Load character")
elif item.WhichOneof("message_of_obj") == "barracks_message":
barracks_message = item.barracks_message
if barracks_message.team_id == self.__teamID or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
barracks_message.x,
barracks_message.y,
self.__bufferState.gameMap,
if (
barracks_message.team_id == self.__teamID
or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
barracks_message.x,
barracks_message.y,
self.__bufferState.gameMap,
)
):
pos = (
AssistFunction.GridToCell(barracks_message.x),
AssistFunction.GridToCell(barracks_message.y)
AssistFunction.GridToCell(barracks_message.y),
)
if pos not in self.__bufferState.mapInfo.barracksState:
self.__bufferState.mapInfo.barracksState[pos] = (
barracks_message.team_id, barracks_message.hp
barracks_message.team_id,
barracks_message.hp,
)
if barracks_message.team_id == self.__teamID:
self.__logger.debug("Load Barracks!")
@ -622,30 +693,35 @@ class Logic(ILogic):
self.__logger.debug("Load EnemyBarracks!")
else:
self.__bufferState.mapInfo.barracksState[pos] = (
barracks_message.team_id, barracks_message.hp
barracks_message.team_id,
barracks_message.hp,
)
if barracks_message.team_id == self.__teamID:
self.__logger.debug("Update Barracks!")
else:
self.__logger.debug("Update EnemyBarracks!")
elif item.WhichOneof("message_of_obj") == "spring_message":
spring_message = item.spring_message
if spring_message.team_id == self.__teamID or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
spring_message.x,
spring_message.y,
self.__bufferState.gameMap,
if (
spring_message.team_id == self.__teamID
or AssistFunction.HaveView(
self.__bufferState.self.view_range,
self.__bufferState.self.x,
self.__bufferState.self.y,
spring_message.x,
spring_message.y,
self.__bufferState.gameMap,
)
):
pos = (
AssistFunction.GridToCell(spring_message.x),
AssistFunction.GridToCell(spring_message.y)
AssistFunction.GridToCell(spring_message.y),
)
if pos not in self.__bufferState.mapInfo.springState:
self.__bufferState.mapInfo.springState[pos] = (
spring_message.team_id, spring_message.hp
spring_message.team_id,
spring_message.hp,
)
if spring_message.team_id == self.__teamID:
self.__logger.debug("Load Spring!")
@ -653,13 +729,14 @@ class Logic(ILogic):
self.__logger.debug("Load EnemySpring!")
else:
self.__bufferState.mapInfo.springState[pos] = (
spring_message.team_id, spring_message.hp
spring_message.team_id,
spring_message.hp,
)
if spring_message.team_id == self.__teamID:
self.__logger.debug("Update Spring!")
else:
self.__logger.debug("Update EnemySpring!")
elif item.WhichOneof("message_of_obj") == "farm_message":
farm_message = item.farm_message
if farm_message.team_id == self.__teamID or AssistFunction.HaveView(
@ -672,11 +749,12 @@ class Logic(ILogic):
):
pos = (
AssistFunction.GridToCell(farm_message.x),
AssistFunction.GridToCell(farm_message.y)
AssistFunction.GridToCell(farm_message.y),
)
if pos not in self.__bufferState.mapInfo.farmState:
self.__bufferState.mapInfo.farmState[pos] = (
farm_message.team_id, farm_message.hp
farm_message.team_id,
farm_message.hp,
)
if farm_message.team_id == self.__teamID:
self.__logger.debug("Load Farm!")
@ -684,7 +762,8 @@ class Logic(ILogic):
self.__logger.debug("Load EnemyFarm!")
else:
self.__bufferState.mapInfo.farmState[pos] = (
farm_message.team_id, farm_message.hp
farm_message.team_id,
farm_message.hp,
)
if farm_message.team_id == self.__teamID:
self.__logger.debug("Update Farm!")
@ -703,7 +782,7 @@ class Logic(ILogic):
):
pos = (
AssistFunction.GridToCell(trap_message.x),
AssistFunction.GridToCell(trap_message.y)
AssistFunction.GridToCell(trap_message.y),
)
if pos not in self.__bufferState.mapInfo.trapState:
self.__bufferState.mapInfo.trapState[pos] = (
@ -721,45 +800,56 @@ class Logic(ILogic):
self.__logger.debug("Update Trap!")
else:
self.__logger.debug("Update EnemyTrap!")
elif item.WhichOneof("message_of_obj") == "economy_resource_message":
economy_message = item.economy_resource_message
pos = (
AssistFunction.GridToCell(economy_message.x),
AssistFunction.GridToCell(economy_message.y)
AssistFunction.GridToCell(economy_message.y),
)
if pos not in self.__bufferState.mapInfo.economyResourceState:
self.__bufferState.mapInfo.economyResourceState[pos] = economy_message.hp
self.__bufferState.mapInfo.economyResourceState[pos] = (
economy_message.hp
)
self.__logger.debug("Load EconomyResource!")
else:
self.__bufferState.mapInfo.economyResourceState[pos] = economy_message.hp
self.__bufferState.mapInfo.economyResourceState[pos] = (
economy_message.hp
)
self.__logger.debug("Update EconomyResource!")
elif item.WhichOneof("message_of_obj") == "addition_resource_message":
addition_message = item.addition_resource_message
pos = (
AssistFunction.GridToCell(addition_message.x),
AssistFunction.GridToCell(addition_message.y)
AssistFunction.GridToCell(addition_message.y),
)
if pos not in self.__bufferState.mapInfo.additionResourceState:
self.__bufferState.mapInfo.additionResourceState[pos] = addition_message.hp
self.__bufferState.mapInfo.additionResourceState[pos] = (
addition_message.hp
)
self.__logger.debug("Load AdditionResource!")
else:
self.__bufferState.mapInfo.additionResourceState[pos] = addition_message.hp
self.__bufferState.mapInfo.additionResourceState[pos] = (
addition_message.hp
)
self.__logger.debug("Update AdditionResource!")
elif item.WhichOneof("message_of_obj") == "news_message":
news = item.news_message
if news.to_id == self.__playerID and news.team_id == self.__teamID:
news_type = Proto2THUAI8.newsTypeDict.get(news.news_case())
if news_type == THUAI8.NewsType.TextMessage:
self.__messageQueue.append((news.from_id, news.text_message))
self.__messageQueue.append(
(news.from_id, news.text_message)
)
self.__logger.debug("Load Text News!")
elif news_type == THUAI8.NewsType.BinaryMessage:
self.__messageQueue.append((news.from_id, news.binary_message))
self.__messageQueue.append(
(news.from_id, news.binary_message)
)
self.__logger.debug("Load Binary News!")
else:
self.__logger.error("Unknown NewsType!")
# NullMessageOfObj和其他默认情况不需要处理
# NullMessageOfObj和其他默认情况不需要处理

125
CAPI/python/main.py Normal file
View File

@ -0,0 +1,125 @@
import argparse
import os
import platform
import sys
from typing import Callable, List
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + "/proto")
import PyAPI.structures as THUAI8 # NOQA: E402
from PyAPI.AI import AI, Setting # NOQA: E402
from PyAPI.Interface import IAI # NOQA: E402
from PyAPI.logic import Logic # NOQA: E402
def PrintWelcomeString() -> None:
# Generated by http://www.network-science.de/ascii/ with font "standard"
welcomeString = r"""
______________ ___ ____ ___ _____ .____________
\__ ___/ | \| | \/ _ \ | \______ \
| | / ~ \ | / /_\ \| | / /
| | \ Y / | / | \ | / /
|____| \___|_ /|______/\____|__ /___| /____/
\/ \/
_________ __ __ __
/ _____// |______ _______ / \ / \_____ _______
\_____ \\ __\__ \\_ __ \ \ \/\/ /\__ \\_ __ \
/ \| | / __ \| | \/ \ / / __ \| | \/
/_______ /|__| (____ /__| \__/\ / (____ /__|
\/ \/ \/ \/
"""
print(welcomeString)
def THUAI8Main(argv: List[str], AIBuilder: Callable) -> None:
pID: int = 0
sIP: str = "127.0.0.1"
sPort: str = "8888"
file: bool = True
screen: bool = True
warnOnly: bool = False
parser = argparse.ArgumentParser(
description="THUAI8 Python Interface Commandline Parameter Introduction"
)
parser.add_argument(
"-I",
type=str,
required=True,
help="Server`s IP 127.0.0.1 in default",
dest="sIP",
default="127.0.0.1",
)
parser.add_argument(
"-P",
type=str,
required=True,
help="Server`s Port 8888 in default",
dest="sPort",
default="8888",
)
parser.add_argument(
"-t",
type=int,
required=True,
help="Team`s ID",
dest="tID",
choices=[0, 1],
)
parser.add_argument(
"-p",
type=int,
required=True,
help="Player`s ID",
dest="pID",
choices=[0, 1, 2, 3, 4],
)
parser.add_argument(
"-d",
action="store_true",
help="Set this flag to save the debug log to ./logs folder",
dest="file",
)
parser.add_argument(
"-o",
action="store_true",
help="Set this flag to print the debug log to the screen",
dest="screen",
)
parser.add_argument(
"-w",
action="store_true",
help="Set this flag to only print warning on the screen",
dest="warnOnly",
)
args = parser.parse_args()
tID = args.tID
pID = args.pID
sIP = args.sIP
sPort = args.sPort
file = args.file
screen = args.screen
warnOnly = args.warnOnly
playerType = THUAI8.PlayerType.NullPlayerType
characterType = THUAI8.CharacterType.NullCharacterType
if pID == 0:
playerType = THUAI8.PlayerType.Team
else:
playerType = THUAI8.PlayerType.Character
characterType = Setting.CharacterTypes()[
pID - 1
] # 减去1 是因为字典从0计数而我们的角色是从1计数
if platform.system().lower() == "windows":
PrintWelcomeString()
logic = Logic(pID, tID, playerType, characterType)
logic.Main(AIBuilder, sIP, sPort, file, screen, warnOnly)
def CreateAI(pID: int) -> IAI:
return AI(pID)
if __name__ == "__main__":
THUAI8Main(sys.argv, CreateAI)

371
CAPI/python/structures.py Normal file
View File

@ -0,0 +1,371 @@
import sys
from enum import Enum
from typing import Dict, List
if sys.version_info < (3, 9):
from typing import Tuple
else:
Tuple = tuple
class GameState(Enum):
NullGameState = 0
GameStart = 1
GameRunning = 2
GameEnd = 3
class PlaceType(Enum):
NullPlaceType = 0
Home = 1
Space = 2
Barrier = 3
Bush = 4
EconomyResource = 5
AdditionResource = 6
Construction = 7
Trap = 8
class ShapeType(Enum):
NullShapeType = 0
Circle = 1
Square = 2
class PlayerTeam(Enum):
NullTeam = 0
BuddhistsTeam = 1
MonstersTeam = 2
class PlayerType(Enum):
NullPlayerType = 0
Character = 1
Team = 2
class CharacterType(Enum):
NullCharacterType = 0
Camp1Character1 = 1
Camp1Character2 = 2
Camp1Character3 = 3
Camp1Character4 = 4
Camp1Character5 = 5
Camp1Character6 = 6
Camp2Character1 = 7
Camp2Character2 = 8
Camp2Character3 = 9
Camp2Character4 = 10
Camp2Character5 = 11
Camp2Character6 = 12
class EquipmentType(Enum):
NullEquipmentType = 0
SmallHealthPotion = 1
MediumHealthPotion = 2
LargeHealthPotion = 3
SmallShield = 4
MediumShield = 5
LargeShield = 6
Speedboots = 7
PurificationPotion = 8
InvisibilityPotion = 9
BerserkPotion = 10
class CharacterState(Enum):
NullCharacterState = 0
Idle = 1
Harvesting = 2
Attacking = 3
SkillCasting = 4
Constructing = 5
Moving = 6
Blind = 7
KnockedBack = 8
Stunned = 9
Invisible = 10
Healing = 11
Berserk = 12
Burned = 13
class CharacterBuffType(Enum):
NullCharacterBuffType = 0
AttackBuff1 = 1
AttackBuff2 = 2
AttackBuff3 = 3
DefenseBuff = 4
SpeedBuff = 5
VisionBuff = 6
class EconomyResourceType(Enum):
NullEconomyResourceType = 0
SmallEconomyResource = 1
MediumEconomyResource = 2
LargeEconomyResource = 3
class AdditionResourceType(Enum):
NullAdditionReourceType = 0
SmallAdditionResource1 = 1
MediumAdditionResource1 = 2
LargeAdditionResource1 = 3
SmallAdditionResource2 = 4
MediumAdditionResource2 = 5
LargeAdditionResource2 = 6
AdditionResource3 = 7
AdditionResource4 = 8
class EconomyResourceState(Enum):
NullEconomyResourceState = 0
Harvestable = 1
BeingHarvested = 2
Harvested = 3
class AdditionResourceState(Enum):
NullAdditionResourceState = 0
Beatable = 1
BeingBeaten = 2
Beaten = 3
class ConstructionType(Enum):
NullConstructionType = 0
Barracks = 1
Spring = 2
Farm = 3
class TrapType(Enum):
NullTrapType = 0
Hole = 1
Cage = 2
class MessageOfObj(Enum):
NullMessageOfObj = 0
CharacterMessage = 1
BarracksMessage = 2
SpringMessage = 3
FarmMessage = 4
TrapMessage = 5
EconomyResourceMessage = 6
AdditionResourceMessage = 7
MapMessage = 8
NewsMessage = 9
TeamMessage = 10
class NewsType(Enum):
NullNewsType = 0
TextMessage = 1
BinaryMessage = 2
class Character:
"""
:attr guid: 玩家唯一标识符
:attr teamID: 玩家所在队伍ID
:attr playerID: 玩家ID
:attr characterType: 玩家角色类型
:attr characterActiveState: 玩家主动状态
:attr isBlind: 是否失明
:attr blindTime: 失明时间
:attr isStunned: 是否眩晕
:attr stunnedTime: 眩晕时间
:attr isInvisible: 是否隐身
:attr invisibleTime: 隐身时间
:attr isBurned: 是否烧伤
:attr burnedTime: 烧伤时间
:attr harmCut: 伤害减免比例
:attr harmCutTime: 伤害减免时间
:attr characterPassiveState: 玩家最新被动状态
:attr x: 玩家坐标x
:attr y: 玩家坐标y
:attr facingDirection: 玩家朝向
:attr speed: 玩家速度
:attr viewRange: 玩家视野范围
:attr commonAttack: 普通攻击力
:attr commonAttackCD: 普通攻击冷却时间
:attr commonAttackRange: 普通攻击范围
:attr skillAttackCD: 技能攻击冷却时间
:attr economyDepletion: 经济消耗
:attr killScore: 击杀得分
:attr hp: 玩家血量
:attr shieldEquipment: 装备护盾剩余值
:attr shoesEquipment: 装备鞋子加成值
:attr shoesTime: 鞋子加成时间
:attr isPurified: 是否被净化
:attr purifiedTime: 净化时间
:attr isBerserk: 是否狂暴
:attr berserkTime: 狂暴时间
:attr attackBuffNum: 加成资源attackBuff等级
:attr attackBuffTime: 加成资源attackBuff时间
:attr speedBuffTime: 加成资源speedBuff时间
:attr visionBuffTime: 加成资源visionBuff时间
"""
def __init__(self):
self.guid: int = 0
self.teamID: int = 0
self.playerID: int = 0
self.characterType: CharacterType = CharacterType.NullCharacterType
# 主动状态
self.characterActiveState: CharacterState = CharacterState.NullCharacterState
# 被动状态
self.isBlind: bool = False
self.blindTime: int = 0
self.isStunned: bool = False
self.stunnedTime: int = 0
self.isInvisible: bool = False
self.invisibleTime: int = 0
self.isBurned: bool = False
self.burnedTime: int = 0
self.harmCut: float = 1.0
self.harmCutTime: int = 0
# 最新被动状态状态
self.characterPassiveState: CharacterState = CharacterState.NullCharacterState
# 坐标位置和朝向
self.x: int = 0
self.y: int = 0
# 朝向和速度
self.facingDirection: float = 0.0
self.speed: int = 0
self.viewRange: int = 0
# 普通攻击相关属性
self.commonAttack: int = 0
self.commonAttackCD: int = 0
self.commonAttackRange: int = 0
# 技能攻击相关属性
self.skillAttackCD: int = 0
# 消耗资源相关属性
self.economyDepletion: int = 0
# 击杀得分相关属性
self.killScore: int = 0
# 血量相关属性
self.hp: int = 0
# 装备相关属性,装备护盾剩余值?
self.shieldEquipment: int = 0
self.shoesEquipment: int = 0
self.shoesTime: int = 0
self.isPurified: bool = False
self.purifiedTime: int = 0
self.isBerserk: bool = False
self.berserkTime: int = 0
# 加成资源的Buff
self.attackBuffNum: int = 0
self.attackBuffTime: int = 0
self.speedBuffTime: int = 0
self.visionBuffTime: int = 0
class Team:
def __init__(self):
self.playerID: int = 0
self.teamID: int = 0
self.score: int = 0
self.energy: int = 0
class Trap:
def __init__(self):
self.trapType: TrapType = TrapType.NullTrapType
self.x: int = 0
self.y: int = 0
self.teamID: int = 0
self.id: int = 0
class EconomyResource:
def __init__(self):
self.economyResourceType: EconomyResourceType = (
EconomyResourceType.NullEconomyResourceType
)
self.economyResourceState: EconomyResourceState = (
EconomyResourceState.NullEconomyResourceState
)
self.x: int = 0
self.y: int = 0
self.process: int = 0
self.id: int = 0
class AdditionResource:
def __init__(self):
self.additionResourceType: AdditionResourceType = (
AdditionResourceType.NullAdditionReourceType
)
self.additionResourceState: AdditionResourceState = (
AdditionResourceState.NullAdditionResourceState
)
self.x: int = 0
self.y: int = 0
self.hp: int = 0
self.id: int = 0
class ConstructionState:
def __init__(self, teamID, HP, type: ConstructionType):
self.teamID = teamID
self.hp = HP
self.constructionType: ConstructionType = ConstructionType.NullConstructionType
class GameMap:
"""
:attr barracksState: 兵营状态
:attr springState: 泉水状态
:attr farmState: 农场状态
:attr trapState: 陷阱状态
:attr economyResource: 经济资源状态
:attr additionResource: 加成资源状态
"""
def __init__(self):
self.barracksState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.springState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.farmState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.trapState: Dict[Tuple[int, int], Tuple[int, int]] = {}
self.economyResource: Dict[Tuple[int, int], int] = {}
self.additionResource: Dict[Tuple[int, int], int] = {}
class GameInfo:
def __init__(self):
self.gameTime: int = 0
self.buddhistsTeamScore: int = 0
self.buddhistsTeamEconomy: int = 0
self.buddhistsTeamHeroHp: int = 0
self.monstersScore: int = 0
self.monstersEconomy: int = 0
self.monstersHeroHp: int = 0

565
CAPI/python/utils.py Normal file
View File

@ -0,0 +1,565 @@
from typing import Final, List
import proto.Message2Clients_pb2 as Message2Clients
import proto.Message2Server_pb2 as Message2Server
import proto.MessageType_pb2 as MessageType
import PyAPI.structures as THUAI8
numOfGridPerCell: Final[int] = 1000
class AssistFunction:
@staticmethod
def CellToGrid(cell: int) -> int:
return cell * numOfGridPerCell + numOfGridPerCell // 2
@staticmethod
def GridToCell(grid: int) -> int:
return grid // numOfGridPerCell
@staticmethod
def HaveView(
viewRange: int,
x: int,
y: int,
newX: int,
newY: int,
map: List[List[THUAI8.PlaceType]],
) -> bool:
deltaX = newX - x
deltaY = newY - y
distance = deltaX**2 + deltaY**2
myPlace = map[AssistFunction.GridToCell(x)][AssistFunction.GridToCell(y)]
newPlace = map[AssistFunction.GridToCell(newX)][AssistFunction.GridToCell(newY)]
if myPlace != THUAI8.PlaceType.Bush and newPlace == THUAI8.PlaceType.Bush:
return False
if distance > viewRange * viewRange:
return False
divide = max(abs(deltaX), abs(deltaY)) // 100
if divide == 0:
return True
dx = deltaX / divide
dy = deltaY / divide
selfX = float(x)
selfY = float(y)
if newPlace == THUAI8.PlaceType.Bush and myPlace == THUAI8.PlaceType.Bush:
for _ in range(divide):
selfX += dx
selfY += dy
if (
map[AssistFunction.GridToCell(int(selfX))][
AssistFunction.GridToCell(int(selfY))
]
!= THUAI8.PlaceType.Bush
):
return False
else:
return True
else:
for _ in range(divide):
selfX += dx
selfY += dy
if (
map[AssistFunction.GridToCell(int(selfX))][
AssistFunction.GridToCell(int(selfY))
]
== THUAI8.PlaceType.Barrier
):
return False
else:
return True
class Proto2THUAI8:
gameStateDict: Final[dict] = {
MessageType.NULL_GAME_STATE: THUAI8.GameState.NullGameState,
MessageType.GAME_START: THUAI8.GameState.GameStart,
MessageType.GAME_RUNNING: THUAI8.GameState.GameRunning,
MessageType.GAME_END: THUAI8.GameState.GameEnd,
}
placeTypeDict: Final[dict] = {
MessageType.NULL_PLACE_TYPE: THUAI8.PlaceType.NullPlaceType,
MessageType.HOME: THUAI8.PlaceType.Home,
MessageType.SPACE: THUAI8.PlaceType.Space,
MessageType.BARRIER: THUAI8.PlaceType.Barrier,
MessageType.BUSH: THUAI8.PlaceType.Bush,
MessageType.ECONOMY_RESOURCE: THUAI8.PlaceType.EconomyResource,
MessageType.ADDITION_RESOURCE: THUAI8.PlaceType.AdditionResource,
MessageType.CONSTRUCTION: THUAI8.PlaceType.Construction,
MessageType.TRAP: THUAI8.PlaceType.Trap,
}
shapeTypeDict: Final[dict] = {
MessageType.NULL_SHAPE_TYPE: THUAI8.ShapeType.NullShapeType,
MessageType.CIRCLE: THUAI8.ShapeType.Circle,
MessageType.SQUARE: THUAI8.ShapeType.Square,
}
playerTypeDict: Final[dict] = {
MessageType.NULL_PLAYER_TYPE: THUAI8.PlayerType.NullPlayerType,
MessageType.SCHARACTER: THUAI8.PlayerType.Character,
MessageType.TEAM: THUAI8.PlayerType.Team,
}
characterTypeDict: Final[dict] = {
MessageType.NULL_CHARACTER_TYPE: THUAI8.CharacterType.NullCharacterType,
MessageType.CAMP1_CHARACTER1: THUAI8.CharacterType.Camp1Character1,
MessageType.CAMP1_CHARACTER2: THUAI8.CharacterType.Camp1Character2,
MessageType.CAMP1_CHARACTER3: THUAI8.CharacterType.Camp1Character3,
MessageType.CAMP1_CHARACTER4: THUAI8.CharacterType.Camp1Character4,
MessageType.CAMP1_CHARACTER5: THUAI8.CharacterType.Camp1Character5,
MessageType.CAMP1_CHARACTER6: THUAI8.CharacterType.Camp1Character6,
MessageType.CAMP2_CHARACTER1: THUAI8.CharacterType.Camp2Character1,
MessageType.CAMP2_CHARACTER2: THUAI8.CharacterType.Camp2Character2,
MessageType.CAMP2_CHARACTER3: THUAI8.CharacterType.Camp2Character3,
MessageType.CAMP2_CHARACTER4: THUAI8.CharacterType.Camp2Character4,
MessageType.CAMP2_CHARACTER5: THUAI8.CharacterType.Camp2Character5,
MessageType.CAMP2_CHARACTER6: THUAI8.CharacterType.Camp2Character6,
}
characterStateDict: Final[dict] = {
MessageType.NULL_CHARACTER_STATE: THUAI8.CharacterState.NullCharacterState,
MessageType.IDLE: THUAI8.CharacterState.Idle,
MessageType.HARVESTING: THUAI8.CharacterState.Harvesting,
MessageType.ATTACKING: THUAI8.CharacterState.Attacking,
MessageType.SKILL_CASTING: THUAI8.CharacterState.SkillCasting,
MessageType.CONSTRUCTING: THUAI8.CharacterState.Constructing,
MessageType.MOVING: THUAI8.CharacterState.Moving,
MessageType.BLIND: THUAI8.CharacterState.Blind,
MessageType.KNOCKED_BACK: THUAI8.CharacterState.KnockedBack,
MessageType.STUNNED: THUAI8.CharacterState.Stunned,
MessageType.INVISIBLE: THUAI8.CharacterState.Invisible,
MessageType.HEALING: THUAI8.CharacterState.Healing,
MessageType.BERSERK: THUAI8.CharacterState.Berserk,
MessageType.BURNED: THUAI8.CharacterState.Burned,
}
economyResourceTypeDict: Final[dict] = {
MessageType.NULL_ECONOMY_RESOURCE_TYPE: THUAI8.EconomyResourceType.NullEconomyResourceType,
MessageType.ECONOMY_RESOURCE: THUAI8.EconomyResourceType.EconomyResource,
}
additionResourceTypeDict: Final[dict] = {
MessageType.NULL_ADDITION_RESOURCE_TYPE: THUAI8.AdditionResourceType.NullAdditionResourceType,
MessageType.SMALL_ADDITION_RESOURCE1: THUAI8.AdditionResourceType.SmallAdditionResource1,
MessageType.MEDIUM_ADDITION_RESOURCE1: THUAI8.AdditionResourceType.MediumAdditionResource1,
MessageType.LARGE_ADDITION_RESOURCE1: THUAI8.AdditionResourceType.LargeAdditionResource1,
MessageType.SMALL_ADDITION_RESOURCE2: THUAI8.AdditionResourceType.SmallAdditionResource2,
MessageType.MEDIUM_ADDITION_RESOURCE2: THUAI8.AdditionResourceType.MediumAdditionResource2,
MessageType.LARGE_ADDITION_RESOURCE2: THUAI8.AdditionResourceType.LargeAdditionResource2,
MessageType.ADDITION_RESOURCE3: THUAI8.AdditionResourceType.AdditionResource3,
MessageType.ADDITION_RESOURCE4: THUAI8.AdditionResourceType.AdditionResource4,
}
economyResourceStateTypeDict: Final[dict] = {
MessageType.NULL_ECONOMY_RESOURCE_STATE: THUAI8.EconomyResourceState.NullEconomyResourceState,
MessageType.HARVESTABLE: THUAI8.EconomyResourceState.Harvestable,
MessageType.BEING_HARVESTED: THUAI8.EconomyResourceState.BeingHarvested,
MessageType.HARVESTED: THUAI8.EconomyResourceState.Harvested,
}
additionResourceStateTypeDict: Final[dict] = {
MessageType.NULL_ADDITION_RESOURCE_STATE: THUAI8.AdditionResourceState.NullAdditionResourceState,
MessageType.BEATABLE: THUAI8.AdditionResourceState.Beatable,
MessageType.BEING_BEATEN: THUAI8.AdditionResourceState.BeingBeaten,
MessageType.BEATEN: THUAI8.AdditionResourceState.Beaten,
}
equipmentTypeDict: Final[dict] = {
MessageType.NULL_EQUIPMENT_TYPE: THUAI8.EquipmentType.NullEquipmentType,
MessageType.SMALL_HEALTH_POTION: THUAI8.EquipmentType.SmallHealthPotion,
MessageType.MEDIUM_HEALTH_POTION: THUAI8.EquipmentType.MediumHealthPotion,
MessageType.LARGE_HEALTH_POTION: THUAI8.EquipmentType.LargeHealthPotion,
MessageType.SMALL_SHIELD: THUAI8.EquipmentType.SmallShield,
MessageType.MEDIUM_SHIELD: THUAI8.EquipmentType.MediumShield,
MessageType.LARGE_SHIELD: THUAI8.EquipmentType.LargeShield,
MessageType.SPEEDBOOTS: THUAI8.EquipmentType.Speedboots,
MessageType.PURIFICATION_POTION: THUAI8.EquipmentType.PurificationPotion,
MessageType.INVISIBILITY_POTION: THUAI8.EquipmentType.InvisibilityPotion,
MessageType.BERSERK_POTION: THUAI8.EquipmentType.BerserkPotion,
}
constructionTypeDict: Final[dict] = {
MessageType.NULL_CONSTRUCTION_TYPE: THUAI8.ConstructionType.NullConstructionType,
MessageType.BARRACKS: THUAI8.ConstructionType.Barracks,
MessageType.SPRING: THUAI8.ConstructionType.Spring,
MessageType.FARM: THUAI8.ConstructionType.Farm,
}
trapTypeDict: Final[dict] = {
MessageType.NULL_TRAP_TYPE: THUAI8.TrapType.NullTrapType,
MessageType.HOLE: THUAI8.TrapType.Hole,
MessageType.CAGE: THUAI8.TrapType.Cage,
}
newsTypeDict: Final[dict] = {
MessageType.NULL_NEWS_TYPE: THUAI8.NewsType.NullNewsType,
MessageType.TEXT: THUAI8.NewsType.TextMessage,
MessageType.BINARY: THUAI8.NewsType.BinaryMessage,
}
@staticmethod
def Protobuf2THUAI8Character(
characterMsg: Message2Clients.MessageOfCharacter,
) -> THUAI8.Character:
character = THUAI8.Character()
character.guid = characterMsg.guid
character.teamID = characterMsg.team_id
character.playerID = characterMsg.player_id
character.characterType = Proto2THUAI8.characterTypeDict[
characterMsg.character_type
]
character.characterActiveState = Proto2THUAI8.characterStateDict[
characterMsg.character_active_state
]
character.isBlind = characterMsg.is_blind
character.blindTime = characterMsg.blind_time
character.isStunned = characterMsg.is_stunned
character.stunnedTime = characterMsg.stunned_time
character.isInvisible = characterMsg.is_invisible
character.invisibleTime = characterMsg.invisible_time
character.isBurned = characterMsg.is_burned
character.burnedTime = characterMsg.burned_time
character.harmCut = characterMsg.harm_cut
character.harmCutTime = characterMsg.harm_cut_time
character.characterPassiveState = Proto2THUAI8.characterStateDict[
characterMsg.character_passive_state
]
character.x = characterMsg.x
character.y = characterMsg.y
character.facingDirection = characterMsg.facing_direction
character.speed = characterMsg.speed
character.viewRange = characterMsg.view_range
character.commonAttack = characterMsg.common_attack
character.commonAttackCD = characterMsg.common_attack_cd
character.commonAttackRange = characterMsg.common_attack_range
character.skillAttackCD = characterMsg.skill_attack_cd
character.economyDepletion = characterMsg.economy_depletion
character.killScore = characterMsg.kill_score
character.hp = characterMsg.hp
character.shieldEquipment = characterMsg.shield_equipment
character.shoesEquipment = characterMsg.shoes_equipment
character.shoesTime = characterMsg.shoes_time
character.isPurified = characterMsg.is_purified
character.purifiedTime = characterMsg.purified_time
character.isBerserk = characterMsg.is_berserk
character.berserkTime = characterMsg.berserk_time
character.attackBuffNum = characterMsg.attack_buff_num
character.attackBuffTime = characterMsg.attack_buff_time
character.speedBuffTime = characterMsg.speed_buff_time
character.visionBuffTime = characterMsg.vision_buff_time
return character
@staticmethod
def Protobuf2THUAI8Team(
teamMsg: Message2Clients.MessageOfTeam,
) -> THUAI8.Team:
team = THUAI8.Team()
team.teamID = teamMsg.team_id
team.playerID = teamMsg.player_id
team.score = teamMsg.score
team.energy = teamMsg.energy
return team
@staticmethod
def Protobuf2THUAI8GameInfo(
gameInfoMsg: Message2Clients.MessageOfGameInfo,
) -> THUAI8.GameInfo:
gameInfo = THUAI8.GameInfo()
gameInfo.gameState = Proto2THUAI8.gameStateDict[gameInfoMsg.game_state]
gameInfo.time = gameInfoMsg.time
gameInfo.placeType = Proto2THUAI8.placeTypeDict[gameInfoMsg.place_type]
return gameInfo
@staticmethod
def Protobuf2THUAI8Trap(
trapMsg: Message2Clients.MessageOfTrap,
) -> THUAI8.Trap:
trap = THUAI8.Trap()
trap.trapType = Proto2THUAI8.trapTypeDict[trapMsg.trap_type]
trap.x = trapMsg.x
trap.y = trapMsg.y
trap.teamID = trapMsg.team_id
return trap
@staticmethod
def Protobuf2THUAI8EconomyResource(
economyResourceMsg: Message2Clients.MessageOfEconomyResource,
) -> THUAI8.EconomyResource:
economyResource = THUAI8.EconomyResource()
economyResource.economyResourceType = Proto2THUAI8.economyResourceTypeDict[
economyResourceMsg.economy_resource_type
]
economyResource.economyResourceState = (
Proto2THUAI8.economyResourceStateTypeDict[
economyResourceMsg.economy_resource_state
]
)
economyResource.x = economyResourceMsg.x
economyResource.y = economyResourceMsg.y
return economyResource
@staticmethod
def Protobuf2THUAI8AdditionResource(
additionResourceMsg: Message2Clients.MessageOfAdditionResource,
) -> THUAI8.AdditionResource:
additionResource = THUAI8.AdditionResource()
additionResource.additionResourceType = Proto2THUAI8.additionResourceTypeDict[
additionResourceMsg.addition_resource_type
]
additionResource.additionResourceState = (
Proto2THUAI8.additionResourceStateTypeDict[
additionResourceMsg.addition_resource_state
]
)
additionResource.x = additionResourceMsg.x
additionResource.y = additionResourceMsg.y
return additionResource
@staticmethod
def Protobuf2THUAI8ConstructionState(
constructionStateMsg: Message2Clients.MessageOfConstructionState,
) -> THUAI8.ConstructionState:
constructionState = THUAI8.ConstructionState()
constructionState.teamID = constructionStateMsg.team_id
constructionState.hp = constructionStateMsg.hp
constructionState.constructionType = Proto2THUAI8.constructionTypeDict[
constructionStateMsg.construction_type
]
return constructionState
class THUAI82Proto:
gameStateDict: Final[dict] = {
THUAI8.GameState.NullGameState: MessageType.NULL_GAME_STATE,
THUAI8.GameState.GameStart: MessageType.GAME_START,
THUAI8.GameState.GameRunning: MessageType.GAME_RUNNING,
THUAI8.GameState.GameEnd: MessageType.GAME_END,
}
placeTypeDict: Final[dict] = {
THUAI8.PlaceType.NullPlaceType: MessageType.NULL_PLACE_TYPE,
THUAI8.PlaceType.Home: MessageType.HOME,
THUAI8.PlaceType.Space: MessageType.SPACE,
THUAI8.PlaceType.Barrier: MessageType.BARRIER,
THUAI8.PlaceType.Bush: MessageType.BUSH,
THUAI8.PlaceType.EconomyResource: MessageType.ECONOMY_RESOURCE,
THUAI8.PlaceType.AdditionResource: MessageType.ADDITION_RESOURCE,
THUAI8.PlaceType.Construction: MessageType.CONSTRUCTION,
THUAI8.PlaceType.Trap: MessageType.TRAP,
}
shapeTypeDict: Final[dict] = {
THUAI8.ShapeType.NullShapeType: MessageType.NULL_SHAPE_TYPE,
THUAI8.ShapeType.Circle: MessageType.CIRCLE,
THUAI8.ShapeType.Square: MessageType.SQUARE,
}
playerTeamDict: Final[dict] = {
THUAI8.PlayerTeam.NullTeam: MessageType.NULL_PLAYER_TEAM,
THUAI8.PlayerTeam.BuddhistsTeam: MessageType.BUDDHISTS_TEAM,
THUAI8.PlayerTeam.MonstersTeam: MessageType.MONSTERS_TEAM,
}
characterTypeDict: Final[dict] = {
THUAI8.CharacterType.NullCharacterType: MessageType.NULL_CHARACTER_TYPE,
THUAI8.CharacterType.Camp1Character1: MessageType.CAMP1_CHARACTER1,
THUAI8.CharacterType.Camp1Character2: MessageType.CAMP1_CHARACTER2,
THUAI8.CharacterType.Camp1Character3: MessageType.CAMP1_CHARACTER3,
THUAI8.CharacterType.Camp1Character4: MessageType.CAMP1_CHARACTER4,
THUAI8.CharacterType.Camp1Character5: MessageType.CAMP1_CHARACTER5,
THUAI8.CharacterType.Camp1Character6: MessageType.CAMP1_CHARACTER6,
THUAI8.CharacterType.Camp2Character1: MessageType.CAMP2_CHARACTER1,
THUAI8.CharacterType.Camp2Character2: MessageType.CAMP2_CHARACTER2,
THUAI8.CharacterType.Camp2Character3: MessageType.CAMP2_CHARACTER3,
THUAI8.CharacterType.Camp2Character4: MessageType.CAMP2_CHARACTER4,
THUAI8.CharacterType.Camp2Character5: MessageType.CAMP2_CHARACTER5,
THUAI8.CharacterType.Camp2Character6: MessageType.CAMP2_CHARACTER6,
}
equipmentTypeDict: Final[dict] = {
THUAI8.EquipmentType.NullEquipmentType: MessageType.NULL_EQUIPMENT_TYPE,
THUAI8.EquipmentType.SmallHealthPotion: MessageType.SMALL_HEALTH_POTION,
THUAI8.EquipmentType.MediumHealthPotion: MessageType.MEDIUM_HEALTH_POTION,
THUAI8.EquipmentType.LargeHealthPotion: MessageType.LARGE_HEALTH_POTION,
THUAI8.EquipmentType.SmallShield: MessageType.SMALL_SHIELD,
THUAI8.EquipmentType.MediumShield: MessageType.MEDIUM_SHIELD,
THUAI8.EquipmentType.LargeShield: MessageType.LARGE_SHIELD,
THUAI8.EquipmentType.Speedboots: MessageType.SPEEDBOOTS,
THUAI8.EquipmentType.PurificationPotion: MessageType.PURIFICATION_POTION,
THUAI8.EquipmentType.InvisibilityPotion: MessageType.INVISIBILITY_POTION,
THUAI8.EquipmentType.BerserkPotion: MessageType.BERSERK_POTION,
}
characterStateDict: Final[dict] = {
THUAI8.CharacterState.NullCharacterState: MessageType.NULL_CHARACTER_STATE,
THUAI8.CharacterState.Idle: MessageType.IDLE,
THUAI8.CharacterState.Harvesting: MessageType.HARVESTING,
THUAI8.CharacterState.Attacking: MessageType.ATTACKING,
THUAI8.CharacterState.SkillCasting: MessageType.SKILL_CASTING,
THUAI8.CharacterState.Constructing: MessageType.CONSTRUCTING,
THUAI8.CharacterState.Moving: MessageType.MOVING,
THUAI8.CharacterState.Blind: MessageType.BLIND,
THUAI8.CharacterState.KnockedBack: MessageType.KNOCKED_BACK,
THUAI8.CharacterState.Stunned: MessageType.STUNNED,
THUAI8.CharacterState.Invisible: MessageType.INVISIBLE,
THUAI8.CharacterState.Healing: MessageType.HEALING,
THUAI8.CharacterState.Berserk: MessageType.BERSERK,
THUAI8.CharacterState.Burned: MessageType.BURNED,
}
economyResourceTypeDict: Final[dict] = {
THUAI8.EconomyResourceType.NullEconomyResourceType: MessageType.NULL_ECONOMY_RESOURCE_TYPE,
THUAI8.EconomyResourceType.SmallEconomyResource: MessageType.SMALL_ECONOMY_RESOURCE,
THUAI8.EconomyResourceType.MediumEconomyResource: MessageType.MEDIUM_ECONOMY_RESOURCE,
THUAI8.EconomyResourceType.LargeEconomyResource: MessageType.LARGE_ECONOMY_RESOURCE,
}
additionResourceTypeDict: Final[dict] = {
THUAI8.AdditionResourceType.NullAdditionResourceType: MessageType.NULL_ADDITION_RESOURCE_TYPE,
THUAI8.AdditionResourceType.SmallAdditionResource1: MessageType.SMALL_ADDITION_RESOURCE1,
THUAI8.AdditionResourceType.MediumAdditionResource1: MessageType.MEDIUM_ADDITION_RESOURCE1,
THUAI8.AdditionResourceType.LargeAdditionResource1: MessageType.LARGE_ADDITION_RESOURCE1,
THUAI8.AdditionResourceType.SmallAdditionResource2: MessageType.SMALL_ADDITION_RESOURCE2,
THUAI8.AdditionResourceType.MediumAdditionResource2: MessageType.MEDIUM_ADDITION_RESOURCE2,
THUAI8.AdditionResourceType.LargeAdditionResource2: MessageType.LARGE_ADDITION_RESOURCE2,
THUAI8.AdditionResourceType.AdditionResource3: MessageType.ADDITION_RESOURCE3,
THUAI8.AdditionResourceType.AdditionResource4: MessageType.ADDITION_RESOURCE4,
}
economyResourceStateDict: Final[dict] = {
THUAI8.EconomyResourceState.NullEconomyResourceState: MessageType.NULL_ECONOMY_RESOURCE_STATE,
THUAI8.EconomyResourceState.Harvestable: MessageType.HARVESTABLE,
THUAI8.EconomyResourceState.BeingHarvested: MessageType.BEING_HARVESTED,
THUAI8.EconomyResourceState.Harvested: MessageType.HARVESTED,
}
additionResourceStateDict: Final[dict] = {
THUAI8.AdditionResourceState.NullAdditionResourceState: MessageType.NULL_ADDITION_RESOURCE_STATE,
THUAI8.AdditionResourceState.Beatable: MessageType.BEATABLE,
THUAI8.AdditionResourceState.BeingBeaten: MessageType.BEING_BEATEN,
THUAI8.AdditionResourceState.Beaten: MessageType.BEATEN,
}
constructionTypeDict: Final[dict] = {
THUAI8.ConstructionType.NullConstructionType: MessageType.NULL_CONSTRUCTION_TYPE,
THUAI8.ConstructionType.Barracks: MessageType.BARRACKS,
THUAI8.ConstructionType.Spring: MessageType.SPRING,
THUAI8.ConstructionType.Farm: MessageType.FARM,
}
trapTypeDict: Final[dict] = {
THUAI8.TrapType.NullTrapType: MessageType.NULL_TRAP_TYPE,
THUAI8.TrapType.Hole: MessageType.HOLE,
THUAI8.TrapType.Cage: MessageType.CAGE,
}
newsTypeDict: Final[dict] = {
THUAI8.NewsType.NullNewsType: MessageType.NULL_NEWS_TYPE,
THUAI8.NewsType.TextMessage: MessageType.TEXT,
THUAI8.NewsType.BinaryMessage: MessageType.BINARY,
}
messageOfObjDict: Final[dict] = {
THUAI8.MessageOfObj.NullMessageOfObj: MessageType.NULL_MESSAGE_OF_OBJ,
THUAI8.MessageOfObj.CharacterMessage: MessageType.CHARACTER_MESSAGE,
THUAI8.MessageOfObj.BarracksMessage: MessageType.BARRACKS_MESSAGE,
THUAI8.MessageOfObj.SpringMessage: MessageType.SPRING_MESSAGE,
THUAI8.MessageOfObj.FarmMessage: MessageType.FARM_MESSAGE,
THUAI8.MessageOfObj.TrapMessage: MessageType.TRAP_MESSAGE,
THUAI8.MessageOfObj.EconomyResourceMessage: MessageType.ECONOMY_RESOURCE_MESSAGE,
THUAI8.MessageOfObj.AdditionResourceMessage: MessageType.ADDITION_RESOURCE_MESSAGE,
THUAI8.MessageOfObj.MapMessage: MessageType.MAP_MESSAGE,
THUAI8.MessageOfObj.TeamMessage: MessageType.TEAM_MESSAGE,
THUAI8.MessageOfObj.NewsMessage: MessageType.NEWS_MESSAGE,
}
@staticmethod
def THUAI82ProtobufMoveMsg(
character: int, angle: float, time: int, team: int
) -> MessageType.MoveMsg:
moveMsg = MessageType.MoveMsg()
moveMsg.character_id = character
moveMsg.angle = angle
moveMsg.time_in_milliseconds = time
moveMsg.team_id = team
return moveMsg
@staticmethod
def THUAI82ProtobufIDMsg(playerID: int, teamID: int) -> MessageType.IDMsg:
IDMsg = MessageType.IDMsg()
IDMsg.player_id = playerID
IDMsg.team_id = teamID
return IDMsg
@staticmethod
def THUAI82ProtobufEquipMsg(
character_id: int, team_id: int, equipment_type: THUAI8.EquipmentType
) -> MessageType.EquipMsg:
equipMsg = MessageType.EquipMsg()
equipMsg.character_id = character_id
equipMsg.team_id = team_id
equipMsg.equipment_type = equipment_type
return equipMsg
@staticmethod
def THUAI82ProtobufCreatCharacterMsg(
team_id: int, character_type: THUAI8.CharacterType, birthpoint_index: int
) -> MessageType.CreatCharacterMsg:
creatCharacterMsg = MessageType.CreatCharacterMsg()
creatCharacterMsg.team_id = team_id
creatCharacterMsg.character_type = character_type
creatCharacterMsg.birthpoint_index = birthpoint_index
return creatCharacterMsg
@staticmethod
def THUAI82ProtobufConstructMsg(
character_id: int, team_id: int, construction_type: THUAI8.ConstructionType
) -> MessageType.ConstructMsg:
constructMsg = MessageType.ConstructMsg()
constructMsg.character_id = character_id
constructMsg.team_id = team_id
constructMsg.construction_type = construction_type
return constructMsg
@staticmethod
def THUAI82ProtobufCharacterMsg(
character_id: int, team_id: int, character_type: THUAI8.CharacterType
) -> MessageType.CharacterMsg:
characterMsg = MessageType.CharacterMsg()
characterMsg.character_id = character_id
characterMsg.team_id = team_id
characterMsg.character_type = character_type
return characterMsg
@staticmethod
def THUAI82ProtobufCastMsg(
character_id: int,
skill_id: int,
team_id: int,
attack_range: int,
x: int,
y: int,
angle: float,
) -> MessageType.CastMsg:
castMsg = MessageType.CastMsg()
castMsg.character_id = character_id
castMsg.skill_id = skill_id
castMsg.team_id = team_id
castMsg.attack_range = attack_range
castMsg.x = x
castMsg.y = y
castMsg.angle = angle
return castMsg
@staticmethod
def THUAI82ProtobufAttackMsg(
character_id: int, team_id: int, attacked_character_id: int, attack_range: int
) -> MessageType.AttackMsg:
attackMsg = MessageType.AttackMsg()
attackMsg.character_id = character_id
attackMsg.team_id = team_id
attackMsg.attacked_character_id = attacked_character_id
attackMsg.attack_range = attack_range
return attackMsg

View File

@ -24,63 +24,51 @@ message MessageOfCharacter
CharacterState character_active_state = 5;
//
CharacterState blind_state = 6;
bool is_blind = 6;
int64 blind_time = 7;
// CharacterState knockback_state = 8;
// double knockback_time = 9;
CharacterState stunned_state = 8;
bool is_stunned = 8;
int64 stunned_time = 9;
CharacterState invisible_state = 10;
bool is_invisible = 10;
int64 invisible_time = 11;
// CharacterState healing_state = 14;
// long healing_time = 15;
// CharacterState berserk_state = 16;
// long berserk_time = 17;
CharacterState burned_state = 12;
bool is_burned = 12;
int64 burned_time = 13;
double harm_cut = 14;
int64 harm_cut_time = 15;
CharacterState deceased_state = 16; //
CharacterState character_passive_state = 17; //
CharacterState character_passive_state = 16; //
int32 x = 18;
int32 y = 19;
int32 x = 17;
int32 y = 18;
double facing_direction = 20;
int32 speed = 21;
int32 view_range = 22;
double facing_direction = 19;
int32 speed = 20;
int32 view_range = 21;
int32 common_attack = 23;
int64 common_attack_cd = 24;
int32 common_attack_range = 25;
int32 common_attack = 22;
int64 common_attack_cd = 23;
int32 common_attack_range = 24;
int64 skill_attack_cd = 26;
int64 skill_attack_cd = 25;
int32 economy_depletion = 27; //
int32 kill_score = 28; //
int32 economy_depletion = 26; //
int32 kill_score = 27; //
int32 hp = 29;
int32 hp = 28;
//
int32 shield_equipment = 30; //
// EquipmentType shoes_equipment = ; //
int32 shoes_equipment = 31;
int64 shoes_equipment_time = 32;
// EquipmentType purification_equipment = ;
int64 purification_equipment_time = 33;
// EquipmentType invisibility_equipment = ;
// long invisibility_equipment_time = ;
// EquipmentType berserk_equipment = ;
// long berserk_equipment_time = ;
int32 shield_equipment = 29; // ?
int32 shoes_equipment = 30;
int64 shoes_time = 31;
bool is_purified = 32;
int64 purified_time = 33;
bool is_berserk = 34;
int64 berserk_time = 35;
// Buff
// CharacterBuffType attack_buff = 39;
int64 attack_buff_time = 34;
// CharacterBuffType speed_buff = 43;
int64 speed_buff_time = 35;
// CharacterBuffType vision_buff = 45;
int64 vision_buff_time = 36;
int32 attack_buff_num = 36;
int64 attack_buff_time = 37;
int64 speed_buff_time = 38;
int64 vision_buff_time = 39;
}
message MessageOfBarracks

View File

@ -77,27 +77,16 @@ namespace Server
CharacterActiveState = Transformation.CharacterStateToProto(player.CharacterState1),
BlindState = (player.blind) ? Protobuf.CharacterState.Blind : Protobuf.CharacterState.NullCharacterState,
IsBlind = player.blind,
BlindTime = player.BlindTime,
// 待修改Character.cs中没有knockedback
// KnockbackState = (player.knockedback) ? Protobuf.CharacterState.KnockedBack : Protobuf.CharacterState.NullCharacterState,
// KnockbackTime = player.KnockedBackTime,
StunnedState = (player.stunned) ? Protobuf.CharacterState.Stunned : Protobuf.CharacterState.NullCharacterState,
IsStunned = player.stunned,
StunnedTime = player.StunnedTime,
InvisibleState = (player.visible) ? Protobuf.CharacterState.NullCharacterState : Protobuf.CharacterState.Invisible,
// 待修改Character.cs中没有InvisibleTime
// InvisibleTime = (double)player.InvisibleTime,
// 貌似不需要治疗时间
// HealingState = (player.healing) ? Protobuf.CharacterState.Healing : Protobuf.CharacterState.NullCharacterState,
// HealingTime = (double)player.HealingTime,
// 待修改crazyman不知道是buff还是药水
// BerserkState = (player.CrazyManNum == 1) ? Protobuf.CharacterState.Berserk : Protobuf.CharacterState.NullCharacterState,
// BerserkTime = CrazyManTime,
BurnedState = (player.burned) ? Protobuf.CharacterState.Burned : Protobuf.CharacterState.NullCharacterState,
IsInvisible = !player.visible,
InvisibleTime = player.InvisibleTime,
IsBurned = player.burned,
BurnedTime = player.BurnedTime,
HarmCut = player.HarmCut,
HarmCutTime = player.HarmCutTime,
DeceasedState = (player.CharacterState2 == Preparation.Utility.CharacterState.DECEASED) ? Protobuf.CharacterState.Deceased : Protobuf.CharacterState.NullCharacterState,
CharacterPassiveState = Transformation.CharacterStateToProto(player.CharacterState2),
@ -121,24 +110,17 @@ namespace Server
Hp = (int)player.HP,
// 待修改Shield要分两类
ShieldEquipment = (int)player.Shield, // 加成值,只包含护盾装备
ShieldEquipment = (int)player.Shield, // 护盾装备
ShoesEquipment = (int)player.Shoes, // 加成值
ShoesEquipmentTime = player.QuickStepTime, // 包含所有速度加成的时间
// 待修改Transformation缺东西
// PurificationEquipment = (player.Purified) ? Protobuf.EquipmentType.PurificationPotion : Protobuf.PurificationEquipmentType.NullEquipmentType,
PurificationEquipmentTime = player.PurifiedTime,
// 待修改Character.cs没有隐身时间没有狂暴药水
// InvisibilityEquipment = player.Invisibility,
// InvisibilityEquipmentTime = player.InsvisibilityTime,
// Berserk = player.CrazyManNum, // 数值1~3表示等级0表示没有
// BerserkTime = player.CrazyManTime,
ShoesTime = player.ShoesTime, // 包含所有速度加成的时间
IsPurified = player.Purified,
PurifiedTime = player.PurifiedTime,
IsBerserk = player.IsBerserk,
BerserkTime = player.BerserkTime,
// 待修改Transformation缺东西
// AttackBuff = (player.CrazyManNum == 1) ? Protobuf.CharacterBuffType.AttackBuff1 : (player.CrazyManNum == 2) ? Protobuf.CharacterBuffType.AttackBuff2 : (player.CrazyManNum == 3) ? Protobuf.CharacterBuffType.AttackBuff3 : Protobuf.CharacterBuffType.NullAttackBuff,
AttackBuffNum = (int)player.CrazyManNum,
AttackBuffTime = player.CrazyManTime,
// 待修改
SpeedBuffTime = player.QuickStepTime,
// VisionBuff = (player.CanSeeAll) ? Protobuf.CharacterBuffType.VisionBuff : Protobuf.CharacterBuffType.NullCharacterBuffType,
VisionBuffTime = player.WideViewTime,
}
};