Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
chore: fix a bug of function return too early
Browse files Browse the repository at this point in the history
  • Loading branch information
Ther-nullptr committed Apr 19, 2022
1 parent d0f6278 commit b366cf8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CAPI/API/include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class IAPI

// 使用主动技能。
virtual bool UseCommonSkill() = 0;
virtual bool UseSoftware() = 0;

// 给同队的队友发送消息。`toPlayerID` 指定发送的对象,`message` 指定发送的内容
virtual bool Send(int toPlayerID,std::string) = 0;
Expand Down Expand Up @@ -241,6 +242,7 @@ class API final :public IAPI_For_Logic
// 攻击
bool Attack(double angleInRadian) override;
bool UseCommonSkill() override;
bool UseSoftware() override;

// 通信
bool Send(int toPlayerID, std::string) override;
Expand Down Expand Up @@ -296,6 +298,7 @@ class DebugAPI final :public IAPI_For_Logic
// 攻击
bool Attack(double angleInRadian) override;
bool UseCommonSkill() override;
bool UseSoftware() override;

// 通信
bool Send(int toPlayerID, std::string) override;
Expand Down
7 changes: 7 additions & 0 deletions CAPI/API/src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ bool API::UseCommonSkill()
return logic.SendInfo(message);
}

bool API::UseSoftware()
{
Protobuf::MessageToServer message;
message.set_messagetype(Protobuf::MessageType::UseCommonSkill);
return logic.SendInfo(message);
}

bool API::Send(int toPlayerID, std::string to_message)
{
Protobuf::MessageToServer message;
Expand Down
42 changes: 25 additions & 17 deletions CAPI/API/src/DebugAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ bool DebugAPI::Attack(double angleInRadian)
Out << "Call Attack(" << angleInRadian << ") at " << Time::TimeSinceStart(StartPoint) << "ms" << std::endl;
if (ExamineValidity)
{

auto selfInfo = logic.GetSelfInfo();
if (selfInfo->isResetting)
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if (selfInfo->signalJammerNum == 0)
{
Out << "[Warning: You are out of signal jammers.]" << std::endl;
return false;
}
}

Expand All @@ -83,11 +80,33 @@ bool DebugAPI::UseCommonSkill()
if (selfInfo->isResetting)
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if(!CanUseSoftware(selfInfo))
if (!CanUseSoftware(selfInfo))
{
}
else
{
Out << "[Info: Using " << THUAI5::software_dict[selfInfo->softwareType] << ".]" << std::endl;
}
}

Protobuf::MessageToServer message;
message.set_messagetype(Protobuf::MessageType::UseCommonSkill);
return logic.SendInfo(message);
}

bool DebugAPI::UseSoftware()
{
Out << "Call UseCommonSkill() at " << Time::TimeSinceStart(StartPoint) << "ms" << std::endl;
if (ExamineValidity)
{
auto selfInfo = logic.GetSelfInfo();
if (selfInfo->isResetting)
{
Out << "[Warning: You have been slained.]" << std::endl;
}
if (!CanUseSoftware(selfInfo))
{
return false;
}
else
{
Expand All @@ -108,7 +127,6 @@ bool DebugAPI::Send(int toPlayerID, std::string to_message)
if (toPlayerID < 0 || toPlayerID >= 4)
{
Out << "[Error: Illegal player ID.]" << std::endl;
return false;
}
else
{
Expand All @@ -132,12 +150,10 @@ bool DebugAPI::Pick(THUAI5::PropType proptype)
if (selfInfo->isResetting)
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if (!CanPick(proptype, selfInfo))
{
Out << "[Warning: No such property to pick within the cell.]" << std::endl;
return false;
}
}

Expand All @@ -157,12 +173,10 @@ bool DebugAPI::ThrowProp(uint32_t timeInMilliseconds, double angleInRadian)
if (selfInfo->isResetting) // 正在复活中
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if (selfInfo->prop == THUAI5::PropType::NullPropType)
{
Out << "[Warning: You don't have any props.]" << std::endl;
return false;
}
else
{
Expand All @@ -187,12 +201,10 @@ bool DebugAPI::UseProp()
if (selfInfo->isResetting) // 正在复活中
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if (selfInfo->prop == THUAI5::PropType::NullPropType)
{
Out << "[Warning: You don't have any props.]" << std::endl;
return false;
}
else
{
Expand All @@ -215,12 +227,10 @@ bool DebugAPI::ThrowCPU(uint32_t timeInMilliseconds, double angleInRadian, uint3
if (selfInfo->isResetting) // 正在复活中
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if (selfInfo->cpuNum == 0)
{
Out << "[Warning: You don't have any CPUs.]" << std::endl;
return false;
}
}

Expand All @@ -242,12 +252,10 @@ bool DebugAPI::UseCPU(uint32_t cpuNum)
if (selfInfo->isResetting) // 正在复活中
{
Out << "[Warning: You have been slained.]" << std::endl;
return false;
}
if (selfInfo->cpuNum == 0)
{
Out << "[Warning: You don't have any CPUs.]" << std::endl;
return false;
}
}

Expand Down

0 comments on commit b366cf8

Please sign in to comment.