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/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/AttackManager.cs b/logic/Gaming/AttackManager.cs index 277c8775..d4863c7e 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; @@ -14,27 +15,46 @@ 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 => + { + Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); + if (obj.CanMove) + { + BulletBomb((Bullet)obj, null); + } + obj.CanMove.SetROri(false); + } ); - + } public void ProduceBulletNaturally(BulletType bulletType, Ship ship, double angle, XY pos) { // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange 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: @@ -77,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; @@ -120,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) @@ -161,9 +187,15 @@ public bool Attack(Ship ship, double angle) } } if (bullet != null) + { + Debugger.Output($"Player {ship.PlayerID} from Team {ship.TeamID} successfully attacked!"); return true; + } else + { + Debugger.Output($"Player {ship.PlayerID} from Team {ship.TeamID} failed to attack!"); return false; + } } } } 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); } } }