Skip to content

Commit

Permalink
Merge pull request eesast#361 from eesast/revert-358-dev
Browse files Browse the repository at this point in the history
Revert "feat: ✨ add Repair"
  • Loading branch information
DragonAura authored May 11, 2024
2 parents ac09459 + 87d7619 commit 5fa8518
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 116 deletions.
2 changes: 0 additions & 2 deletions dependency/proto/Services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ service AvailableService
rpc Produce(IDMsg) returns (BoolRes); // 开采
rpc Rebuild(ConstructMsg) returns (BoolRes); // 给建筑回血
rpc Construct(ConstructMsg) returns (BoolRes); // 修建建筑
rpc RepairHome(IDMsg) returns (BoolRes); // 修理大本营
rpc RepairWormhole(IDMsg) returns (BoolRes); // 修理虫洞
rpc Attack(AttackMsg) returns (BoolRes); // 攻击
rpc Send(SendMsg) returns (BoolRes); // 传递信息
// 大本营
Expand Down
16 changes: 1 addition & 15 deletions logic/GameClass/GameObj/Areas/Home.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Preparation.Interface;
using Preparation.Utility;
using Preparation.Utility.Value;
using Preparation.Utility.Value.SafeValue.Atomic;
using Preparation.Utility.Value.SafeValue.LockedValue;

namespace GameClass.GameObj.Areas;
Expand All @@ -13,23 +12,10 @@ public class Home(XY initPos, long id)
public InVariableRange<long> HP { get; } = new(GameData.HomeHP);
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;
public AtomicInt RepairNum { get; } = new AtomicInt(0);
public bool Repair(int constructSpeed, Ship ship)
{
return HP.AddVUseOtherRChange<long>(constructSpeed, ship.MoneyPool.Money, 1) > 0;
}

public void BeAttacked(Bullet bullet)
{
if (bullet!.Parent!.TeamID != TeamID)
HP.SubPositiveV(bullet.AP);
}
public void AddRepairNum(int add = 1)
{
RepairNum.Add(add);
}
public void SubRepairNum(int sub = 1)
{
RepairNum.Sub(sub);
}

}
57 changes: 1 addition & 56 deletions logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,62 +240,7 @@ public bool Construct(Ship ship, ConstructionType constructionType)
{ IsBackground = true }.Start();
return false;
}
public bool RepairHome(Ship ship)
{
Home? home = ((Home?)gameMap.OneForInteract(ship.Position, GameObjType.Home));
if (home == null)
{
return false;
}
if (home.HP.IsMaxV())
{
return false;
}
long stateNum = ship.SetShipState(RunningStateType.Waiting, ShipStateType.Constructing);
if (stateNum == -1)
{
return false;
}
new Thread
(
() =>
{
ship.ThreadNum.WaitOne();
if (!ship.StartThread(stateNum, RunningStateType.RunningActively))
{
ship.ThreadNum.Release();
return;
}
home.AddRepairNum();
Thread.Sleep(GameData.CheckInterval);
new FrameRateTaskExecutor<int>
(
loopCondition: () => stateNum == ship.StateNum && gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (!home.Repair(ship.ConstructSpeed / GameData.NumOfStepPerSecond, ship))
{
ship.ResetShipState(stateNum);
return false;
}
if (home.HP == home.HP.GetMaxV())
{
ship.ResetShipState(stateNum);
return false;
}
return true;
},
timeInterval: GameData.CheckInterval,
finallyReturn: () => 0
).Start();
ship.ThreadNum.Release();
home.SubRepairNum();
}
)
{ IsBackground = true }.Start();
return false;
}
public bool RepairWormhole(Ship ship)
public bool Repair(Ship ship)
{
Wormhole? wormhole = ((WormholeCell?)gameMap.OneForInteract(ship.Position, GameObjType.Wormhole))?.Wormhole;
if (wormhole == null)
Expand Down
13 changes: 2 additions & 11 deletions logic/Gaming/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,13 @@ public bool Recycle(long teamID, long shipID)
}
return false;
}
public bool RepairHome(long teamID, long shipID)
public bool Repair(long teamID, long shipID)
{
if (!gameMap.Timer.IsGaming)
return false;
Ship? ship = gameMap.FindShipInPlayerID(teamID, shipID);
if (ship != null)
return actionManager.RepairHome(ship);
return false;
}
public bool RepairWormhole(long teamID, long shipID)
{
if (!gameMap.Timer.IsGaming)
return false;
Ship? ship = gameMap.FindShipInPlayerID(teamID, shipID);
if (ship != null)
return actionManager.RepairWormhole(ship);
return actionManager.Repair(ship);
return false;
}
public bool Stop(long teamID, long shipID)
Expand Down
32 changes: 0 additions & 32 deletions logic/Server/RpcServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,38 +334,6 @@ public override Task<BoolRes> Construct(ConstructMsg request, ServerCallContext
return Task.FromResult(boolRes);
}

public override Task<BoolRes> RepairHome(IDMsg request, ServerCallContext context)
{
GameServerLogging.logger.ConsoleLogDebug(
$"TRY RepairHome: Player {request.PlayerId} from Team {request.TeamId}");
BoolRes boolRes = new();
if (request.PlayerId >= spectatorMinPlayerID)
{
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
// var gameID = communicationToGameID[request.TeamId][request.PlayerId];
boolRes.ActSuccess = game.RepairHome(request.TeamId, request.PlayerId);
GameServerLogging.logger.ConsoleLogDebug("END RepairHome");
return Task.FromResult(boolRes);
}

public override Task<BoolRes> RepairWormhole(IDMsg request, ServerCallContext context)
{
GameServerLogging.logger.ConsoleLogDebug(
$"TRY RepairWormhole: Player {request.PlayerId} from Team {request.TeamId}");
BoolRes boolRes = new();
if (request.PlayerId >= spectatorMinPlayerID)
{
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
// var gameID = communicationToGameID[request.TeamId][request.PlayerId];
boolRes.ActSuccess = game.RepairWormhole(request.TeamId, request.PlayerId);
GameServerLogging.logger.ConsoleLogDebug("END RepairWormhole");
return Task.FromResult(boolRes);
}

public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context)
{
GameServerLogging.logger.ConsoleLogDebug(
Expand Down

0 comments on commit 5fa8518

Please sign in to comment.