Browse Source

perf: delete the faceDirection of Immovable and add the attackLock

dev
shangfengh 2 years ago
parent
commit
770115a6c9
8 changed files with 19 additions and 27 deletions
  1. +2
    -1
      logic/GameClass/GameObj/Bullet/BombedBullet.cs
  2. +0
    -11
      logic/GameClass/GameObj/Character/Character.Student.cs
  3. +9
    -8
      logic/GameClass/GameObj/Character/Character.cs
  4. +0
    -3
      logic/GameClass/GameObj/GameObj.cs
  5. +0
    -2
      logic/GameClass/GameObj/Immovable.cs
  6. +7
    -1
      logic/GameClass/GameObj/Moveable.cs
  7. +0
    -1
      logic/Preparation/Interface/IGameObj.cs
  8. +1
    -0
      logic/Preparation/Interface/IMoveable.cs

+ 2
- 1
logic/GameClass/GameObj/Bullet/BombedBullet.cs View File

@@ -8,7 +8,8 @@ namespace GameClass.GameObj
public override ShapeType Shape => ShapeType.Circle;
public override bool IsRigid => false;
public long MappingID { get; }
public Bullet bulletHasBombed;
public readonly Bullet bulletHasBombed;
public readonly XY facingDirection;

public BombedBullet(Bullet bullet) :
base(bullet.Position, bullet.Radius, GameObjType.BombedBullet)


+ 0
- 11
logic/GameClass/GameObj/Character/Character.Student.cs View File

@@ -88,17 +88,6 @@ namespace GameClass.GameObj
}
}

private int selfHealingTimes = 1;//剩余的自愈次数
public int SelfHealingTimes
{
get => selfHealingTimes;
set
{
lock (gameObjLock)
selfHealingTimes = (value > 0) ? value : 0;
}
}

private int degreeOfTreatment = 0;
public int DegreeOfTreatment
{


+ 9
- 8
logic/GameClass/GameObj/Character/Character.cs View File

@@ -17,6 +17,7 @@ namespace GameClass.GameObj
public object InventoryLock => inventoryLock;

#region 装弹、攻击相关的基本属性及方法
private readonly object attackLock = new();
/// <summary>
/// 装弹冷却
/// </summary>
@@ -25,7 +26,7 @@ namespace GameClass.GameObj
{
get
{
lock (actionLock)
lock (attackLock)
{
return cd;
}
@@ -36,7 +37,7 @@ namespace GameClass.GameObj
{
get
{
lock (actionLock)
lock (attackLock)
return orgCD;
}
}
@@ -47,14 +48,14 @@ namespace GameClass.GameObj
{
get
{
lock (actionLock)
lock (attackLock)
{
return bulletOfPlayer;
}
}
set
{
lock (actionLock)
lock (attackLock)
{
bulletOfPlayer = value;
cd = orgCD = (BulletFactory.BulletCD(value));
@@ -69,7 +70,7 @@ namespace GameClass.GameObj
{
get
{
lock (actionLock)
lock (attackLock)
{
return maxBulletNum;
}
@@ -80,7 +81,7 @@ namespace GameClass.GameObj

public int UpdateBulletNum(int time)
{
lock (actionLock)
lock (attackLock)
{
if (bulletNum < maxBulletNum)
{
@@ -98,7 +99,7 @@ namespace GameClass.GameObj
/// <returns>攻击操作发出的子弹</returns>
public Bullet? Attack(double angle, int time)
{
lock (actionLock)
lock (attackLock)
{
if (bulletOfPlayer == BulletType.Null)
return null;
@@ -115,7 +116,7 @@ namespace GameClass.GameObj
Bullet? bullet = BulletFactory.GetBullet(this, res, this.bulletOfPlayer);
if (bullet == null) return null;
if (TryAddAp()) bullet.AddAP(GameData.ApPropAdd);
facingDirection = new(angle, bullet.AttackDistance);
FacingDirection = new(angle, bullet.AttackDistance);
return bullet;
}
else


+ 0
- 3
logic/GameClass/GameObj/GameObj.cs View File

@@ -26,9 +26,6 @@ namespace GameClass.GameObj
protected XY position;
public abstract XY Position { get; }

protected XY facingDirection = new(1, 0);
public abstract XY FacingDirection { get; }

public abstract bool CanMove { get; }

public abstract bool IsRigid { get; }


+ 0
- 2
logic/GameClass/GameObj/Immovable.cs View File

@@ -7,8 +7,6 @@ namespace GameClass.GameObj

public override XY Position => position;

public override XY FacingDirection => facingDirection;

public override bool CanMove => false;

public Immovable(XY initPos, int initRadius, GameObjType initType) : base(initPos, initRadius, initType)


+ 7
- 1
logic/GameClass/GameObj/Moveable.cs View File

@@ -52,13 +52,19 @@ namespace GameClass.GameObj
}
}

public override XY FacingDirection
protected XY facingDirection = new(1, 0);
public XY FacingDirection
{
get
{
lock (actionLock)
return facingDirection;
}
set
{
lock (actionLock)
facingDirection = value;
}
}

private int isMoving = 0;


+ 0
- 1
logic/Preparation/Interface/IGameObj.cs View File

@@ -7,7 +7,6 @@ namespace Preparation.Interface
public GameObjType Type { get; }
public long ID { get; }
public XY Position { get; } // if Square, Pos equals the center
public XY FacingDirection { get; }
public bool IsRigid { get; }
public ShapeType Shape { get; }
public bool CanMove { get; }


+ 1
- 0
logic/Preparation/Interface/IMoveable.cs View File

@@ -6,6 +6,7 @@ namespace Preparation.Interface
{
public interface IMoveable : IGameObj
{
public XY FacingDirection { get; set; }
object ActionLock { get; }
public int MoveSpeed { get; }
public bool IsMoving { get; set; }


Loading…
Cancel
Save