Skip to content

Commit

Permalink
Merge pull request eesast#302 from shangfengh/dev
Browse files Browse the repository at this point in the history
fix(Logic): 🐛 fix the bug about the HP of the home
  • Loading branch information
DragonAura authored May 6, 2024
2 parents 75f29db + b212803 commit 31188ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Home(XY initPos, long id)
: Immovable(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Home), IHome
{
public long TeamID { get; } = id;
public InVariableRange<long> HP => new(GameData.HomeHP);
public InVariableRange<long> HP { get; } = new(GameData.HomeHP);
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;

Expand Down
9 changes: 9 additions & 0 deletions logic/GameClass/GameObj/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public Base(Home home)
ShipPool = new(
classfier: (ship) => ship.ShipType,
idleChecker: (ship) => ship.IsRemoved,
tryActivator: (ship) =>
{
if (ship.IsRemoved.TrySet(false))
{
ship.CanMove.SetROri(true);
return true;
}
return false;
},
activator: (ship) =>
{
ship.CanMove.SetROri(true);
Expand Down
5 changes: 5 additions & 0 deletions logic/GameClass/GameObj/GameObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
using Preparation.Utility;
using Preparation.Utility.Value;
using Preparation.Utility.Value.SafeValue.Atomic;
using Preparation.Utility.Logging;
using System.Threading;

namespace GameClass.GameObj
{
public static class GameObjLogger
{
public static readonly Logger logger = new("GameObj");
}
/// <summary>
/// 一切游戏元素的总基类,与THUAI4不同,继承IMoveable接口(出于一切物体其实都是可运动的指导思想)——LHR
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions logic/Preparation/Utility/Value/SafeValue/Atomic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override bool Equals(object? obj)
T? g = Get();
if (g == null) return obj == null;
if (g == obj) return true;
return obj != null && (obj is IReturnClass<T> k) && Get() == k.Get();
return obj != null && (obj is IReturnClass<T> k) && g == k.Get();
}
public override int GetHashCode()
{
Expand All @@ -48,7 +48,7 @@ public override bool Equals(object? obj)
T? g = Get();
if (g == null) return obj == null;
if (g == obj) return true;
return obj != null && (obj is IReturnClass<T> k) && Get() == k.Get();
return obj != null && (obj is IReturnClass<T> k) && g == k.Get();
}
public override int GetHashCode()
{
Expand Down
7 changes: 3 additions & 4 deletions logic/Preparation/Utility/Value/SafeValue/ObjPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Preparation.Utility.Value.SafeValue;

public class ObjPool<T, TType>(Func<T, TType> classfier,
Func<T, bool> idleChecker,
Func<T, bool> tryActivator,
Action<T> activator,
Action<T> inactivator)
: IObjPool<T, TType>
Expand All @@ -16,6 +17,7 @@ public class ObjPool<T, TType>(Func<T, TType> classfier,
private readonly Dictionary<TType, LockedClassList<T>> objs = [];
private readonly Func<T, TType> classfier = classfier;
private readonly Func<T, bool> idleChecker = idleChecker;
private readonly Func<T, bool> tryActivator = tryActivator;
private readonly Action<T> activator = activator;
private readonly Action<T> inactivator = inactivator;

Expand Down Expand Up @@ -89,10 +91,7 @@ public void Initiate(TType tp, int num, Func<T> func)
lock (dictLock)
{
if (CheckEmpty(tp) || GetIdleNum(tp) == 0) return null;
var ret = Find(tp, idleChecker);
if (ret is null) return null;
activator(ret);
return ret;
return Find(tp, tryActivator);
}
}
public void ReturnObj(T obj)
Expand Down

0 comments on commit 31188ea

Please sign in to comment.