Browse Source

fix: 🐛 fix the CopyInfo and improve the performance about the fuction of Attack

tags/0.1.0
shangfengh 2 years ago
parent
commit
09ccd5147d
6 changed files with 49 additions and 34 deletions
  1. +1
    -1
      logic/Client/MainWindow.xaml.cs
  2. +14
    -0
      logic/GameClass/GameObj/Map/Map.cs
  3. +1
    -1
      logic/GameRules.md
  4. +28
    -30
      logic/Gaming/AttackManager.cs
  5. +2
    -2
      logic/Gaming/CharacterManager .cs
  6. +3
    -0
      logic/Server/CopyInfo.cs

+ 1
- 1
logic/Client/MainWindow.xaml.cs View File

@@ -851,7 +851,7 @@ namespace Client
{
case Protobuf.BulletType.BombBomb:
{
double bombRange = 1.0*data.BombRange / Preparation.Utility.GameData.numOfPosGridPerCell;
double bombRange = 1.0 * data.BombRange / Preparation.Utility.GameData.numOfPosGridPerCell;
Ellipse icon = new()
{
Width = 2 * bombRange * unitWidth,


+ 14
- 0
logic/GameClass/GameObj/Map/Map.cs View File

@@ -221,6 +221,20 @@ namespace GameClass.GameObj
}
return flag;
}
public bool RemoveJustFromMap(GameObj gameObj)
{
GameObjLockDict[gameObj.Type].EnterWriteLock();
bool flag;
try
{
flag = GameObjDict[gameObj.Type].Remove(gameObj);
}
finally
{
GameObjLockDict[gameObj.Type].ExitWriteLock();
}
return flag;
}
public void Add(GameObj gameObj)
{
GameObjLockDict[gameObj.Type].EnterWriteLock();


+ 1
- 1
logic/GameRules.md View File

@@ -1,5 +1,5 @@
# 规则
V4.0
V4.1
- [规则](#规则)
- [简则](#简则)
- [地图](#地图)


+ 28
- 30
logic/Gaming/AttackManager.cs View File

@@ -6,6 +6,7 @@ using Preparation.Utility;
using GameEngine;
using Preparation.Interface;
using Timothy.FrameRateTask;
using System.Numerics;

namespace Gaming
{
@@ -73,22 +74,34 @@ namespace Gaming
#endif
bullet.CanMove = false;

if (gameMap.Remove(bullet) && bullet.BulletBombRange > 0)
gameMap.Add(new BombedBullet(bullet));

if (bullet.BulletBombRange == 0)
{
gameMap.Remove(bullet);
if (objBeingShot == null)
{
characterManager.BackSwing((Character?)bullet.Parent, bullet.Backswing);
characterManager.BackSwing((Character)bullet.Parent, bullet.Backswing);
return;
}

BombObj(bullet, objBeingShot);
characterManager.BackSwing((Character?)bullet.Parent, bullet.RecoveryFromHit);
characterManager.BackSwing((Character)bullet.Parent, bullet.RecoveryFromHit);
return;
}

if (gameMap.Remove(bullet))
{
BombedBullet bombedBullet = new(bullet);
gameMap.Add(bombedBullet);
new Thread
(() =>
{
Thread.Sleep(GameData.frameDuration);
gameMap.RemoveJustFromMap(bombedBullet);
}
)
{ IsBackground = true }.Start();
}

/*if (objBeingShot != null)
{
else if (objBeingShot is Bullet) //子弹不能相互引爆,若要更改这一设定,取消注释即可。
@@ -138,10 +151,10 @@ namespace Gaming

if (objBeingShot == null)
{
characterManager.BackSwing((Character?)bullet.Parent, bullet.Backswing);
characterManager.BackSwing((Character)bullet.Parent, bullet.Backswing);
}
else
characterManager.BackSwing((Character?)bullet.Parent, bullet.RecoveryFromHit);
characterManager.BackSwing((Character)bullet.Parent, bullet.RecoveryFromHit);
}

public bool Attack(Character player, double angle)
@@ -169,35 +182,20 @@ namespace Gaming
if (bullet.CastTime > 0)
{
characterManager.SetPlayerState(player, PlayerStateType.TryingToAttack);

new Thread
if (bullet.IsRemoteAttack)
{
new Thread
(() =>
{
new FrameRateTaskExecutor<int>(
loopCondition: () => player.PlayerState == PlayerStateType.TryingToAttack && gameMap.Timer.IsGaming,
loopToDo: () =>
Thread.Sleep(bullet.CastTime);
if (player.PlayerState == PlayerStateType.TryingToAttack)
{
},
timeInterval: GameData.frameDuration,
finallyReturn: () => 0,
maxTotalDuration: bullet.CastTime
)

.Start();

if (gameMap.Timer.IsGaming)
{
if (player.PlayerState == PlayerStateType.TryingToAttack)
{
characterManager.SetPlayerState(player);
}
else
bullet.IsMoving = false;
gameMap.Remove(bullet);
characterManager.SetPlayerState(player);
}
}
)
{ IsBackground = true }.Start();
{ IsBackground = true }.Start();
}
}
}
if (bullet != null)


+ 2
- 2
logic/Gaming/CharacterManager .cs View File

@@ -354,9 +354,9 @@ namespace Gaming
else TryBeAwed(student, bullet);
}

public bool BackSwing(Character? player, int time)
public bool BackSwing(Character player, int time)
{
if (player == null || time <= 0) return false;
if (time <= 0) return false;
if (player.PlayerState == PlayerStateType.Swinging || (!player.Commandable() && player.PlayerState != PlayerStateType.TryingToAttack)) return false;
SetPlayerState(player, PlayerStateType.Swinging);



+ 3
- 0
logic/Server/CopyInfo.cs View File

@@ -148,6 +148,7 @@ namespace Server
{
BulletMessage = new()
{
Type = Transformation.ToBulletType(bullet.TypeOfBullet),
X = bullet.Position.x,
Y = bullet.Position.y,
FacingDirection = bullet.FacingDirection.Angle(),
@@ -184,6 +185,7 @@ namespace Server
{
BombedBulletMessage = new()
{
Type = Transformation.ToBulletType(bombedBullet.bulletHasBombed.TypeOfBullet),
X = bombedBullet.bulletHasBombed.Position.x,
Y = bombedBullet.bulletHasBombed.Position.y,
FacingDirection = bombedBullet.FacingDirection.Angle(),
@@ -191,6 +193,7 @@ namespace Server
BombRange = bombedBullet.bulletHasBombed.BulletBombRange
}
};
// Debugger.Output(bombedBullet, bombedBullet.Place.ToString()+" "+bombedBullet.Position.ToString());
return msg;
}



Loading…
Cancel
Save