From e42d0d665589c24e670dc997b9cb6e9c5fa0fe82 Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Sat, 30 Mar 2024 15:48:47 +0800 Subject: [PATCH 1/4] fix: :bug: stunned? --- logic/Gaming/ActionManager.cs | 26 +++++++++++++------------- logic/Gaming/ShipManager.cs | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index fa73d0b7..0601f245 100755 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -18,19 +18,19 @@ private class ActionManager(Map gameMap, ShipManager shipManager) gameMap: gameMap, OnCollision: (obj, collisionObj, moveVec) => { - //Ship ship = (Ship)obj; - //switch (collisionObj.Type) - //{ - // case GameObjType.Bullet: - // if (((Bullet)collisionObj).Parent != ship) - // { - // // TODO - // gameMap.Remove((GameObj)collisionObj); - // } - // break; - // default: - // break; - //} + Ship ship = (Ship)obj; + switch (collisionObj.Type) + { + case GameObjType.Bullet: + if (((Bullet)collisionObj).Parent != ship) + { + ShipManager.BeStunned(ship, 1000); + gameMap.Remove((GameObj)collisionObj); + } + break; + default: + break; + } return MoveEngine.AfterCollision.MoveMax; }, EndMove: obj => diff --git a/logic/Gaming/ShipManager.cs b/logic/Gaming/ShipManager.cs index d584584e..b53e3c9f 100755 --- a/logic/Gaming/ShipManager.cs +++ b/logic/Gaming/ShipManager.cs @@ -39,10 +39,13 @@ public bool ActivateShip(Ship ship, XY pos) long stateNum = ship.SetShipState(RunningStateType.RunningActively, ShipStateType.Null); ship.ResetShipState(stateNum); ship.CanMove.SetROri(true); + Debugger.Output(ship, " is activated!"); return true; } public void BeAttacked(Ship ship, Bullet bullet) { + Debugger.Output(ship, " is attacked!"); + Debugger.Output(bullet, " 's AP is " + bullet.AP.ToString()); if (bullet!.Parent!.TeamID == ship.TeamID) { return; @@ -51,19 +54,24 @@ public void BeAttacked(Ship ship, Bullet bullet) if (bullet.TypeOfBullet != BulletType.Missile && ship.Shield > 0) { ship.Shield.SubPositiveV((long)(subHP * bullet.ShieldModifier)); + Debugger.Output(ship, " 's shield is " + ship.Shield.ToString()); } else if (ship.Armor > 0) { ship.Armor.SubPositiveV((long)(subHP * bullet.ArmorModifier)); + Debugger.Output(ship, " 's armor is " + ship.Armor.ToString()); } else { ship.HP.SubPositiveV(subHP); + Debugger.Output(ship, " 's HP is " + ship.HP.ToString()); } if (ship.HP == 0) { + Debugger.Output(ship, " is destroyed!"); var money = ship.GetCost(); bullet.Parent.AddMoney(money); + Debugger.Output(bullet.Parent, " get " + money.ToString() + " money because of destroying " + ship); Remove(ship); } } @@ -77,6 +85,7 @@ public static long BeStunned(Ship ship, int time) new Thread (() => { + Debugger.Output(ship, " is stunned for " + time.ToString() + " ms"); Thread.Sleep(time); ship.ResetShipState(stateNum); } @@ -98,6 +107,7 @@ public bool BackSwing(Ship ship, int time) new Thread (() => { + Debugger.Output(ship, " is swinging for " + time.ToString() + " ms"); Thread.Sleep(time); ship.ResetShipState(stateNum); } @@ -116,6 +126,7 @@ public bool Recover(Ship ship, long recover) return false; } long actualRecover = ship.HP.AddPositiveV(recover); + Debugger.Output(ship, " 's HP is recovered to " + ship.HP.ToString()); ship.SubMoney((long)(actualRecover * 1.2)); return true; } @@ -141,7 +152,9 @@ public bool Recycle(Ship ship) shipValue += ship.ArmorModule.Cost; shipValue += ship.ShieldModule.Cost; shipValue += ship.WeaponModule.Cost; + Debugger.Output(ship, " 's value is " + shipValue.ToString()); ship.AddMoney((long)(shipValue * 0.5 * ship.HP / ship.HP.GetMaxV())); + Debugger.Output(ship, " is recycled!"); Remove(ship); return false; } @@ -149,9 +162,11 @@ public void Remove(Ship ship) { if (!ship.TryToRemoveFromGame(ShipStateType.Deceased)) { + Debugger.Output(ship, " is not removed from game!"); return; } - gameMap.Remove(ship); // TODO + Debugger.Output(ship, " is removed from game!"); + gameMap.Remove(ship); } } } From ee236ae27d751d66b81d3ac2ad3885022ea55b77 Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Sat, 30 Mar 2024 20:28:28 +0800 Subject: [PATCH 2/4] fix: :bug: BulletBomb --- logic/Gaming/AttackManager.cs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index 277c8775..cf3eb490 100755 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -14,16 +14,32 @@ namespace Gaming public partial class Game { private readonly AttackManager attackManager; - private class AttackManager(Map gameMap, ShipManager shipManager) + private class AttackManager { - private readonly Map gameMap = gameMap; - private readonly ShipManager shipManager = shipManager; - public readonly MoveEngine moveEngine = new( + private readonly Map gameMap; + private readonly ShipManager shipManager; + private readonly MoveEngine moveEngine; + public AttackManager(Map gameMap, ShipManager shipManager) + { + this.gameMap = gameMap; + this.shipManager = shipManager; + moveEngine = new( gameMap: gameMap, - OnCollision: (obj, collisionObj, moveVec) => MoveEngine.AfterCollision.Destroyed, - EndMove: obj => obj.CanMove.SetROri(false) + OnCollision: (obj, collisionObj, moveVec) => + { + BulletBomb((Bullet)obj, (GameObj)collisionObj); + return MoveEngine.AfterCollision.Destroyed; + }, + EndMove: obj => + { + if (obj.CanMove) + { + BulletBomb((Bullet)obj, null); + } + obj.CanMove.SetROri(false); + } ); - + } public void ProduceBulletNaturally(BulletType bulletType, Ship ship, double angle, XY pos) { // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange From b28e6b5f1f986e5ca15bdcc663d8ebbf2983f557 Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Sat, 30 Mar 2024 20:42:27 +0800 Subject: [PATCH 3/4] fix: :bug: add debugger to attack manager --- logic/Gaming/AttackManager.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index cf3eb490..c9dc5780 100755 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -4,6 +4,7 @@ using GameEngine; using Preparation.Interface; using Preparation.Utility; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -32,6 +33,7 @@ public AttackManager(Map gameMap, ShipManager shipManager) }, EndMove: obj => { + Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); if (obj.CanMove) { BulletBomb((Bullet)obj, null); @@ -46,11 +48,13 @@ public void ProduceBulletNaturally(BulletType bulletType, Ship ship, double angl if (bulletType == BulletType.Null) return; Bullet? bullet = BulletFactory.GetBullet(ship, pos, bulletType); if (bullet == null) return; + Debugger.Output(bullet, "Attack in " + pos.ToString()); gameMap.Add(bullet); moveEngine.MoveObj(bullet, (int)(bullet.AttackDistance * 1000 / bullet.MoveSpeed), angle, ++bullet.StateNum); // 这里时间参数除出来的单位要是ms } private void BombObj(Bullet bullet, GameObj objBeingShot) { + Debugger.Output(bullet, "bombed " + objBeingShot.ToString()); switch (objBeingShot.Type) { case GameObjType.Ship: @@ -93,6 +97,11 @@ public bool TryRemoveBullet(Bullet bullet) } private void BulletBomb(Bullet bullet, GameObj? objBeingShot) { + if (objBeingShot != null) + Debugger.Output(bullet, "bombed with" + objBeingShot.ToString()); + else + Debugger.Output(bullet, "bombed without objBeingShot"); + if (!TryRemoveBullet(bullet)) { return; @@ -136,6 +145,7 @@ public bool Attack(Ship ship, double angle) Bullet? bullet = ship.Attack(angle); if (bullet != null) { + Debugger.Output(bullet, "Attack in " + bullet.Position.ToString()); gameMap.Add(bullet); moveEngine.MoveObj(bullet, (int)(bullet.AttackDistance * 1000 / bullet.MoveSpeed), angle, ++bullet.StateNum); // 这里时间参数除出来的单位要是ms if (bullet.CastTime > 0) @@ -177,9 +187,15 @@ public bool Attack(Ship ship, double angle) } } if (bullet != null) + { + Debugger.Output($"playerID:{ship.ID} successfully attacked!"); return true; + } else + { + Debugger.Output($"playerID:{ship.ID} failed to attack!"); return false; + } } } } From ee907a5a58ab9481bc1a1edc8fe95180a27d1a54 Mon Sep 17 00:00:00 2001 From: Xuc Pan Date: Sat, 30 Mar 2024 21:00:06 +0800 Subject: [PATCH 4/4] fix: :bug: add debugger --- logic/GameClass/GameObj/Map/Map.cs | 1 + logic/GameClass/GameObj/Ship.cs | 1 + logic/Gaming/AttackManager.cs | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/logic/GameClass/GameObj/Map/Map.cs b/logic/GameClass/GameObj/Map/Map.cs index 73b24cf3..4f5aa08a 100755 --- a/logic/GameClass/GameObj/Map/Map.cs +++ b/logic/GameClass/GameObj/Map/Map.cs @@ -178,6 +178,7 @@ public bool RemoveJustFromMap(GameObj gameObj) public void Add(IGameObj gameObj) { GameObjDict[gameObj.Type].Add(gameObj); + Debugger.Output("Found a " + gameObj.Type.ToString() + " at " + gameObj.Position.ToString()); } public Map(MapStruct mapResource) { diff --git a/logic/GameClass/GameObj/Ship.cs b/logic/GameClass/GameObj/Ship.cs index 79e0b207..a186824c 100755 --- a/logic/GameClass/GameObj/Ship.cs +++ b/logic/GameClass/GameObj/Ship.cs @@ -450,5 +450,6 @@ public Ship(int initRadius, ShipType shipType, MoneyPool moneyPool) : ModuleFactory.FindIShield(ShipType, shieldType), ModuleFactory.FindIWeapon(ShipType, weaponType) ); + Debugger.Output(this, "Ship created"); } } diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index c9dc5780..d4863c7e 100755 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -188,12 +188,12 @@ public bool Attack(Ship ship, double angle) } if (bullet != null) { - Debugger.Output($"playerID:{ship.ID} successfully attacked!"); + Debugger.Output($"Player {ship.PlayerID} from Team {ship.TeamID} successfully attacked!"); return true; } else { - Debugger.Output($"playerID:{ship.ID} failed to attack!"); + Debugger.Output($"Player {ship.PlayerID} from Team {ship.TeamID} failed to attack!"); return false; } }