Browse Source

fix: 🐛

tags/0.1.0
shangfengh 2 years ago
parent
commit
bde9fddf08
4 changed files with 115 additions and 118 deletions
  1. +3
    -3
      logic/GameClass/GameObj/Character/Character.cs
  2. +107
    -109
      logic/Gaming/AttackManager.cs
  3. +1
    -1
      logic/Gaming/PropManager.cs
  4. +4
    -5
      logic/Preparation/Utility/EnumType.cs

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

@@ -454,9 +454,9 @@ namespace GameClass.GameObj
this.MoveSpeed = OrgMoveSpeed; this.MoveSpeed = OrgMoveSpeed;
HP = MaxHp; HP = MaxHp;
PropInventory = null; PropInventory = null;
// BulletOfPlayer = OriBulletOfPlayer;
// lock (gameObjLock)
// bulletNum = maxBulletNum;
BulletOfPlayer = OriBulletOfPlayer;
lock (gameObjLock)
bulletNum = maxBulletNum;


buffManeger.ClearAll(); buffManeger.ClearAll();
IsInvisible = false; IsInvisible = false;


+ 107
- 109
logic/Gaming/AttackManager.cs View File

@@ -22,17 +22,15 @@ namespace Gaming
gameMap: gameMap, gameMap: gameMap,
OnCollision: (obj, collisionObj, moveVec) => OnCollision: (obj, collisionObj, moveVec) =>
{ {
//BulletBomb((Bullet)obj, (GameObj)collisionObj);
return MoveEngine.AfterCollision.Destroyed;
},
//BulletBomb((Bullet)obj, (GameObj)collisionObj);
return MoveEngine.AfterCollision.Destroyed; },
EndMove: obj => EndMove: obj =>
{ {
#if DEBUG #if DEBUG
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);


#endif #endif
BulletBomb((Bullet)obj, null);
}
BulletBomb((Bullet)obj, null); }
); );
} }
private void BombOnePlayer(Bullet bullet, Character playerBeingShot) private void BombOnePlayer(Bullet bullet, Character playerBeingShot)
@@ -77,136 +75,136 @@ namespace Gaming


Thread.Sleep(GameData.reviveTime); Thread.Sleep(GameData.reviveTime);


playerBeingShot.AddShield(GameData.shieldTimeAtBirth); // 复活加个盾
playerBeingShot.AddShield(GameData.shieldTimeAtBirth); // 复活加个盾


// gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
// try
//{
// gameMap.GameObjDict[GameObjIdx.Player].Add(playerBeingShot);
// }
// finally { gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock(); }
// gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
// try
//{
// gameMap.GameObjDict[GameObjIdx.Player].Add(playerBeingShot);
// }
// finally { gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock(); }


if (gameMap.Timer.IsGaming)
{
playerBeingShot.CanMove = true;
}
playerBeingShot.IsResetting = false;
}
if (gameMap.Timer.IsGaming)
{
playerBeingShot.CanMove = true;
}
playerBeingShot.IsResetting = false;
}
) )
{ IsBackground = true }.Start(); { IsBackground = true }.Start();
}
} }
private void BulletBomb(Bullet bullet, GameObj? objBeingShot)
{
}
private void BulletBomb(Bullet bullet, GameObj? objBeingShot)
{
#if DEBUG #if DEBUG
Debugger.Output(bullet, "bombed!");
Debugger.Output(bullet, "bombed!");
#endif #endif
bullet.CanMove = false;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
foreach (ObjOfCharacter _bullet in gameMap.GameObjDict[GameObjIdx.Bullet])
bullet.CanMove = false;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
foreach (ObjOfCharacter _bullet in gameMap.GameObjDict[GameObjIdx.Bullet])
{
if (_bullet.ID == bullet.ID)
{ {
if (_bullet.ID == bullet.ID)
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.BombedBullet].Add(new BombedBullet(bullet));
}
finally
{ {
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.BombedBullet].Add(new BombedBullet(bullet));
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].ExitWriteLock();
}
gameMap.GameObjDict[GameObjIdx.Bullet].Remove(_bullet);
break;
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].ExitWriteLock();
} }
gameMap.GameObjDict[GameObjIdx.Bullet].Remove(_bullet);
break;
} }
}
finally
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
}

/*if (objBeingShot != null)
{
else if (objBeingShot is Bullet) //子弹不能相互引爆,若要更改这一设定,取消注释即可。
{ {
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
new Thread(() => { BulletBomb((Bullet)objBeingShot, null); }) { IsBackground = true }.Start();
} }
}*/


/*if (objBeingShot != null)
{
else if (objBeingShot is Bullet) //子弹不能相互引爆,若要更改这一设定,取消注释即可。
// 子弹爆炸会发生的事↓↓↓
var beAttackedList = new List<Character>();
gameMap.GameObjLockDict[GameObjIdx.Player].EnterReadLock();
try
{
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
if (bullet.CanAttack(player))
{ {
new Thread(() => { BulletBomb((Bullet)objBeingShot, null); }) { IsBackground = true }.Start();
beAttackedList.Add(player);
if (player.ID != bullet.Parent.ID)
bullet.Parent.HP = (int)(bullet.Parent.HP + (bullet.Parent.Vampire * bullet.AP));
} }
}*/

// 子弹爆炸会发生的事↓↓↓
var beAttackedList = new List<Character>();
gameMap.GameObjLockDict[GameObjIdx.Player].EnterReadLock();
try
{
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
if (bullet.CanAttack(player))
{
beAttackedList.Add(player);
if (player.ID != bullet.Parent.ID)
bullet.Parent.HP = (int)(bullet.Parent.HP + (bullet.Parent.Vampire * bullet.AP));
} }
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Player].ExitReadLock();
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Player].ExitReadLock();
}


foreach (Character beAttackedPlayer in beAttackedList)
{
BombOnePlayer(bullet, beAttackedPlayer);
}
beAttackedList.Clear();
foreach (Character beAttackedPlayer in beAttackedList)
{
BombOnePlayer(bullet, beAttackedPlayer);
} }
public bool Attack(Character? player, double angle) // 射出去的子弹泼出去的水(狗头)
{ // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange
if (player == null)
{
beAttackedList.Clear();
}
public bool Attack(Character? player, double angle) // 射出去的子弹泼出去的水(狗头)
{ // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange
if (player == null)
{
#if DEBUG #if DEBUG
Console.WriteLine("the player who will attack is NULL!");
Console.WriteLine("the player who will attack is NULL!");
#endif #endif
return false;
}
return false;
}


if (player.IsResetting)
return false;
Bullet? bullet = player.RemoteAttack(
new XY // 子弹紧贴人物生成。
(
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Cos(angle)),
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Sin(angle))
)
);
if (bullet != null)
{
bullet.CanMove = true;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.Bullet].Add(bullet);
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
}
moveEngine.MoveObj(bullet, (int)((player.AttackRange - player.Radius - BulletFactory.BulletRadius(player.BulletOfPlayer)) * 1000 / bullet.MoveSpeed), angle); // 这里时间参数除出来的单位要是ms
if (player.IsResetting)
return false;
Bullet? bullet = player.RemoteAttack(
new XY // 子弹紧贴人物生成。
(
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Cos(angle)),
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Sin(angle))
)
);
if (bullet != null)
{
bullet.CanMove = true;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.Bullet].Add(bullet);
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
}
moveEngine.MoveObj(bullet, (int)((player.AttackRange - player.Radius - BulletFactory.BulletRadius(player.BulletOfPlayer)) * 1000 / bullet.MoveSpeed), angle); // 这里时间参数除出来的单位要是ms
#if DEBUG #if DEBUG
Console.WriteLine($"playerID:{player.ID} successfully attacked!");
Console.WriteLine($"playerID:{player.ID} successfully attacked!");
#endif #endif
return true;
}
else
{
return true;
}
else
{
#if DEBUG #if DEBUG
Console.WriteLine($"playerID:{player.ID} has no bullets so that he can't attack!");
Console.WriteLine($"playerID:{player.ID} has no bullets so that he can't attack!");
#endif #endif
return false;
}
return false;
} }
} }
} }
} }
}

+ 1
- 1
logic/Gaming/PropManager.cs View File

@@ -235,7 +235,7 @@ namespace Gaming
{ {
for (int j = 0; j < gameMap.ProtoGameMap.GetLength(1); j++) for (int j = 0; j < gameMap.ProtoGameMap.GetLength(1); j++)
{ {
if (gameMap.ProtoGameMap[i, j] == (int)MapInfo.MapInfoObjType.Null)
if (gameMap.ProtoGameMap[i, j] == (int)MapInfoObjType.Null)
{ {
availableCellForGenerateProp.Add(GameData.GetCellCenterPos(i, j)); availableCellForGenerateProp.Add(GameData.GetCellCenterPos(i, j));
} }


+ 4
- 5
logic/Preparation/Utility/EnumType.cs View File

@@ -27,14 +27,13 @@ namespace Preparation.Utility
Circle = 1, // 子弹和人物为圆形,格子为方形 Circle = 1, // 子弹和人物为圆形,格子为方形
Square = 2 Square = 2
} }
public enum PlaceType // 位置标志,包括陆地,建筑,草丛。游戏中每一帧都要刷新各个物体的该属性
public enum PlaceType // 位置标志,包括陆地,草丛。游戏中每一帧都要刷新各个物体的该属性
{ {
Null = 0, Null = 0,
Land = 1, Land = 1,
Building = 2,
Grass1 = 3,
Grass2 = 4,
Grass3 = 5,
Grass1 = 2,
Grass2 = 3,
Grass3 = 4,
} }
public enum BulletType // 子弹类型 public enum BulletType // 子弹类型
{ {


Loading…
Cancel
Save