Skip to content

Commit

Permalink
feat: ✨ add construct
Browse files Browse the repository at this point in the history
  • Loading branch information
panxuc committed Nov 18, 2023
1 parent ea8ceea commit def9fa4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GameClass.GameObj.Areas;

public class Construction : Immovable
{
public LongInTheVariableRange HP { get; } = new LongInTheVariableRange(0);
public LongInTheVariableRange HP { get; } = new LongInTheVariableRange(0, GameData.CommunityHP);
public override bool IsRigid => constructionType == ConstructionType.Community;
public override ShapeType Shape => ShapeType.Square;
private ConstructionType constructionType = ConstructionType.Null;
Expand Down
47 changes: 46 additions & 1 deletion logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,54 @@ public bool Produce(Ship ship)
}
public bool Construct(Ship ship)
{
Construction? construction = (Construction?)gameMap.OneForInteract(ship.Position, GameObjType.Construction);
if (construction == null)
{
return false;
}
if (construction.HP == construction.HP.GetMaxV())
{
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;
}
construction.AddConstructNum();
Thread.Sleep(GameData.CheckInterval);
new FrameRateTaskExecutor<int>
(
loopCondition: () => stateNum == ship.StateNum && gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (construction.HP == construction.HP.GetMaxV())
{
ship.ResetShipState(stateNum);
return false;
}
return true;
},
timeInterval: GameData.CheckInterval,
finallyReturn: () => 0
).Start();
ship.ThreadNum.Release();
construction.SubConstructNum();
}
)
{ IsBackground = true }.Start();
return false;
}

}
}
}

0 comments on commit def9fa4

Please sign in to comment.