Skip to content

Commit

Permalink
Merge pull request #160 from Panxuc/dev
Browse files Browse the repository at this point in the history
fix: 🐛 repairments
  • Loading branch information
panxuc authored Mar 30, 2024
2 parents a87150d + ee907a5 commit b2eae67
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
1 change: 1 addition & 0 deletions logic/GameClass/GameObj/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions logic/GameClass/GameObj/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
26 changes: 13 additions & 13 deletions logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
46 changes: 39 additions & 7 deletions logic/Gaming/AttackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GameEngine;
using Preparation.Interface;
using Preparation.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion logic/Gaming/ShipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -141,17 +152,21 @@ 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;
}
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);
}
}
}
Expand Down

0 comments on commit b2eae67

Please sign in to comment.