Skip to content

Commit

Permalink
Merge pull request eesast#215 from Panxuc/dev
Browse files Browse the repository at this point in the history
fix: 🐛 wormhole id
  • Loading branch information
panxuc authored Apr 13, 2024
2 parents 25db423 + 3b26b52 commit d25b6ac
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 34 deletions.
1 change: 1 addition & 0 deletions dependency/proto/Message2Clients.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ message MessageOfWormhole
int32 x = 1;
int32 y = 2;
int32 hp = 3; // 剩余的血量
int32 id = 4;
}

message MessageOfResource
Expand Down
24 changes: 12 additions & 12 deletions logic/Client/ViewModel/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,17 +584,17 @@ private void Refresh(object sender, EventArgs e)
{
DrawWormHole(data);
}
listOfWormhole.Sort(
delegate (MessageOfWormhole h1, MessageOfWormhole h2)
{
int re = h1.X.CompareTo(h2.X);
if (0 == re)
{
return h1.Y.CompareTo(h2.Y);
}
return re;
}
);
//listOfWormhole.Sort(
// delegate (MessageOfWormhole h1, MessageOfWormhole h2)
// {
// int re = h1.X.CompareTo(h2.X);
// if (0 == re)
// {
// return h1.Y.CompareTo(h2.Y);
// }
// return re;
// }
//);

foreach (var data in listOfFort)
{
Expand Down Expand Up @@ -975,7 +975,7 @@ Show the error message
ConnectToServer(new string[]{
"localhost",
"8888",
"0",
"1",
"0",
"1"
});
Expand Down
6 changes: 3 additions & 3 deletions logic/Client/ViewModel/MapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,10 @@ private void DrawFort(MessageOfFort data)

private void DrawWormHole(MessageOfWormhole data)
{
int x = data.X;
int y = data.Y;
//int x = data.X;
//int y = data.Y;
int hp = data.Hp;
int index = UtilFunctions.getGridIndex(x, y);
int index = data.Id;
MapPatchesList[index].Text = Convert.ToString(hp);
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.WormHole];
MapPatchesList[index].TextColor = Colors.White;
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool Construct(int constructSpeed, ConstructionType constructionType, Shi
}
}

return HP.AddVUseOtherRChange<long>(constructSpeed, ship.MoneyPool.Money, 10) > 0;
return HP.AddVUseOtherRChange<long>(constructSpeed, ship.MoneyPool.Money, 1) > 0;

}
public bool BeAttacked(Bullet bullet)
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Resource(XY initPos)
public AtomicInt ProduceNum { get; } = new AtomicInt(0);
public bool Produce(int produceSpeed, Ship ship)
{
return ship.MoneyPool.AddMoney(HP.SubRChange(produceSpeed)) > 0;
return ship.MoneyPool.AddMoney(-HP.SubRChange(produceSpeed)) > 0;
}
public void AddProduceNum(int add = 1)
{
Expand Down
10 changes: 3 additions & 7 deletions logic/GameClass/GameObj/Areas/Wormhole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@

namespace GameClass.GameObj.Areas;

public class Wormhole(List<WormholeCell> cells)
public class Wormhole(List<WormholeCell> cells, int id)
{
public InVariableRange<long> HP = new(GameData.WormholeHP);
private readonly List<WormholeCell> cells = cells;
public List<WormholeCell> Cells => cells;
public AtomicInt RepairNum { get; } = new AtomicInt(0);
public int ID { get; } = id;
public bool Repair(int constructSpeed, Ship ship)
{
var addHP = HP.GetMaxV() - HP > constructSpeed ? constructSpeed : HP.GetMaxV() - HP;
if (ship.MoneyPool.Money < addHP / 10)
{
return false;
}
return ship.MoneyPool.SubMoney(HP.AddRChange(addHP) / 10) > 0;
return HP.AddVUseOtherRChange<long>(constructSpeed, ship.MoneyPool.Money, 1) > 0;
}
public void BeAttacked(Bullet bullet)
{
Expand Down
9 changes: 8 additions & 1 deletion logic/GameClass/GameObj/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public Map(MapStruct mapResource)

if (wormholes.Find(wormhole => WormholeHasCell(wormhole)) == null)
{
var newWormhole = new Wormhole([]);
var newWormhole = new Wormhole([], wormholes.Count);
var newCell = new WormholeCell(GameData.GetCellCenterPos(i, j), newWormhole);
Add(newCell);
newWormhole.Cells.Add(newCell);
Expand All @@ -275,6 +275,13 @@ public Map(MapStruct mapResource)
}
}
Homes = GameObjDict[GameObjType.Home].Cast<Home>()?.ToNewList()!;
for (var i = 0; i < wormholes.Count; i++)
{
if (i != wormholes.Count / 2)
{
wormholes[i].HP.SetRNow(0);
}
}
}
}
}
9 changes: 3 additions & 6 deletions logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ public bool Produce(Ship ship)
loopCondition: () => stateNum == ship.StateNum && gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (!resource.Produce(ship.ProduceSpeed * GameData.CheckInterval, ship))
if (!resource.Produce(ship.ProduceSpeed / GameData.NumOfStepPerSecond, ship))
{
ship.ThreadNum.Release();
ship.ResetShipState(stateNum);
return false;
}
Expand Down Expand Up @@ -174,9 +173,8 @@ public bool Construct(Ship ship, ConstructionType constructionType)
loopCondition: () => stateNum == ship.StateNum && gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (!construction.Construct(ship.ConstructSpeed * GameData.CheckInterval, constructionType, ship))
if (!construction.Construct(ship.ConstructSpeed / GameData.NumOfStepPerSecond, constructionType, ship))
{
ship.ThreadNum.Release();
ship.ResetShipState(stateNum);
return false;
}
Expand Down Expand Up @@ -275,9 +273,8 @@ public bool Repair(Ship ship)
loopCondition: () => stateNum == ship.StateNum && gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (!wormhole.Repair(ship.ConstructSpeed * GameData.CheckInterval, ship))
if (!wormhole.Repair(ship.ConstructSpeed / GameData.NumOfStepPerSecond, ship))
{
ship.ThreadNum.Release();
ship.ResetShipState(stateNum);
return false;
}
Expand Down
9 changes: 6 additions & 3 deletions logic/Server/CopyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class CopyInfo
return Fort(construction);
return null;
case GameObjType.Wormhole:
return Wormhole(((WormholeCell)gameObj).Wormhole);
return Wormhole((WormholeCell)gameObj);
default: return null;
}
}
Expand Down Expand Up @@ -207,13 +207,16 @@ private static MessageOfObj Fort(Construction construction)
};
return msg;
}
private static MessageOfObj Wormhole(Wormhole wormhole)
private static MessageOfObj Wormhole(WormholeCell wormhole)
{
MessageOfObj msg = new()
{
WormholeMessage = new()
{
Hp = (int)wormhole.HP,
X = wormhole.Position.x,
Y = wormhole.Position.y,
Hp = (int)wormhole.Wormhole.HP,
Id = wormhole.Wormhole.ID,
}
};
return msg;
Expand Down

0 comments on commit d25b6ac

Please sign in to comment.