From bc100b4e1df5a58c47faf1a552ae35929b684f99 Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Sun, 22 Jan 2023 00:16:16 +0800 Subject: [PATCH] feat: :sparkles: --- logic/GameClass/GameObj/Map/Generator.cs | 19 +++ logic/GameEngine/MoveEngine.cs | 2 +- logic/Gaming/ActionManager.cs | 151 +++++++++++++++++++++++ logic/Gaming/Game.cs | 4 +- logic/Gaming/MoveManager.cs | 66 ---------- logic/Gaming/PropManager.cs | 2 +- logic/Preparation/Utility/EnumType.cs | 13 +- 7 files changed, 182 insertions(+), 75 deletions(-) create mode 100644 logic/GameClass/GameObj/Map/Generator.cs create mode 100644 logic/Gaming/ActionManager.cs delete mode 100644 logic/Gaming/MoveManager.cs diff --git a/logic/GameClass/GameObj/Map/Generator.cs b/logic/GameClass/GameObj/Map/Generator.cs new file mode 100644 index 0000000..756e6bb --- /dev/null +++ b/logic/GameClass/GameObj/Map/Generator.cs @@ -0,0 +1,19 @@ +using Preparation.Utility; +using Preparation.GameData; + +namespace GameClass.GameObj +{ + /// + /// 发电机 + /// + public class Generator : GameObj + { + public Generator(XY initPos) : + base(initPos, GameData.numOfPosGridPerCell / 2, PlaceType.Land, GameObjType.Generator) + { + this.CanMove = false; + } + public override bool IsRigid => true; + public override ShapeType Shape => ShapeType.Square; + } +} diff --git a/logic/GameEngine/MoveEngine.cs b/logic/GameEngine/MoveEngine.cs index f596c4e..645c903 100644 --- a/logic/GameEngine/MoveEngine.cs +++ b/logic/GameEngine/MoveEngine.cs @@ -14,7 +14,7 @@ namespace GameEngine /// public enum AfterCollision { - ContinueCheck = 0, // 碰撞后继续检查其他碰撞 + ContinueCheck = 0, // 碰撞后继续检查其他碰撞,暂时没用 MoveMax = 1, // 行走最远距离 Destroyed = 2 // 物体已经毁坏 } diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs new file mode 100644 index 0000000..69a920e --- /dev/null +++ b/logic/Gaming/ActionManager.cs @@ -0,0 +1,151 @@ +using System; +using GameClass.GameObj; +using GameEngine; +using Preparation.GameData; +using Preparation.Utility; + +namespace Gaming +{ + public partial class Game + { + private readonly ActionManager actionManager; + private class ActionManager + { + + // 人物移动 + public void MovePlayer(Character playerToMove, int moveTimeInMilliseconds, double moveDirection) + { + moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection); + } + + public bool Fix(Character player, Generator? generator = null) + { + if (player.IsResetting) + return false; + + + Prop? pickProp = null; + if (propType == PropType.Null) // 自动检查有无道具可捡 + { + gameMap.GameObjLockDict[GameObjIdx.Prop].EnterReadLock(); + try + { + foreach (Prop prop in gameMap.GameObjDict[GameObjIdx.Prop]) + { + if (GameData.IsInTheSameCell(prop.Position, player.Position) && prop.CanMove == false) + { + pickProp = prop; + } + } + } + finally + { + gameMap.GameObjLockDict[GameObjIdx.Prop].ExitReadLock(); + } + } + else + { + gameMap.GameObjLockDict[GameObjIdx.Prop].EnterReadLock(); + try + { + foreach (Prop prop in gameMap.GameObjDict[GameObjIdx.Prop]) + { + if (prop.GetPropType() == propType) + { + if (GameData.IsInTheSameCell(prop.Position, player.Position) && prop.CanMove == false) + { + pickProp = prop; + } + } + } + } + finally + { + gameMap.GameObjLockDict[GameObjIdx.Prop].ExitReadLock(); + } + } + + if (pickProp != null) + { + // pickProp.CanMove = false; + Prop? dropProp = null; + if (player.PropInventory != null) // 若角色原来有道具,则原始道具掉落在原地 + { + dropProp = player.PropInventory; + dropProp.SetNewPos(GameData.GetCellCenterPos(player.Position.x / GameData.numOfPosGridPerCell, player.Position.y / GameData.numOfPosGridPerCell)); + } + player.PropInventory = pickProp; + gameMap.GameObjLockDict[GameObjIdx.Prop].EnterWriteLock(); + try + { + gameMap.GameObjDict[GameObjIdx.Prop].Remove(pickProp); + if (dropProp != null) + gameMap.GameObjDict[GameObjIdx.Prop].Add(dropProp); + } + finally + { + gameMap.GameObjLockDict[GameObjIdx.Prop].ExitWriteLock(); + } + gameMap.GameObjLockDict[GameObjIdx.PickedProp].EnterWriteLock(); + try + { + gameMap.GameObjDict[GameObjIdx.PickedProp].Add(new PickedProp(pickProp)); + } + finally + { + gameMap.GameObjLockDict[GameObjIdx.PickedProp].ExitWriteLock(); + } + + return true; + } + else + return false; + } + + /* + private void ActivateMine(Character player, Mine mine) + { + gameMap.ObjListLock.EnterWriteLock(); + try { gameMap.ObjList.Remove(mine); } + catch { } + finally { gameMap.ObjListLock.ExitWriteLock(); } + + switch (mine.GetPropType()) + { + case PropType.Dirt: + player.AddMoveSpeed(Constant.dirtMoveSpeedDebuff, Constant.buffPropTime); + break; + case PropType.Attenuator: + player.AddAP(Constant.attenuatorAtkDebuff, Constant.buffPropTime); + break; + case PropType.Divider: + player.ChangeCD(Constant.dividerCdDiscount, Constant.buffPropTime); + break; + } + } + */ + + // private readonly Map gameMap; + private readonly MoveEngine moveEngine; + public ActionManager(Map gameMap) + { + // this.gameMap = gameMap; + this.moveEngine = new MoveEngine( + gameMap: gameMap, + OnCollision: (obj, collisionObj, moveVec) => + { + //if (collisionObj is Mine) + //{ + // ActivateMine((Character)obj, (Mine)collisionObj); + // return MoveEngine.AfterCollision.ContinueCheck; + //} + return MoveEngine.AfterCollision.MoveMax; }, + EndMove: obj => + { + // Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); + } + ); + } + } + } +} diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index da727ed..c949eae 100644 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -182,7 +182,7 @@ public void MovePlayer(long playerID, int moveTimeInMilliseconds, double angle) Character? player = gameMap.FindPlayer(playerID); if (player != null) { - moveManager.MovePlayer(player, moveTimeInMilliseconds, angle); + actionManager.MovePlayer(player, moveTimeInMilliseconds, angle); #if DEBUG Console.WriteLine($"PlayerID:{playerID} move to ({player.Position.x},{player.Position.y})!"); #endif @@ -351,7 +351,7 @@ public Game(uint[,] mapResource, int numOfTeam) skillManager = new SkillManager(); attackManager = new AttackManager(gameMap); - moveManager = new MoveManager(gameMap); + actionManager = new ActionManager(gameMap); propManager = new PropManager(gameMap); } } diff --git a/logic/Gaming/MoveManager.cs b/logic/Gaming/MoveManager.cs deleted file mode 100644 index 7c15aa6..0000000 --- a/logic/Gaming/MoveManager.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using GameClass.GameObj; -using GameEngine; -using Preparation.Utility; - -namespace Gaming -{ - public partial class Game - { - private readonly MoveManager moveManager; - private class MoveManager - { - - // 人物移动 - public void MovePlayer(Character playerToMove, int moveTimeInMilliseconds, double moveDirection) - { - moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection); - } - - /* - private void ActivateMine(Character player, Mine mine) - { - gameMap.ObjListLock.EnterWriteLock(); - try { gameMap.ObjList.Remove(mine); } - catch { } - finally { gameMap.ObjListLock.ExitWriteLock(); } - - switch (mine.GetPropType()) - { - case PropType.Dirt: - player.AddMoveSpeed(Constant.dirtMoveSpeedDebuff, Constant.buffPropTime); - break; - case PropType.Attenuator: - player.AddAP(Constant.attenuatorAtkDebuff, Constant.buffPropTime); - break; - case PropType.Divider: - player.ChangeCD(Constant.dividerCdDiscount, Constant.buffPropTime); - break; - } - } - */ - - // private readonly Map gameMap; - private readonly MoveEngine moveEngine; - public MoveManager(Map gameMap) - { - // this.gameMap = gameMap; - this.moveEngine = new MoveEngine( - gameMap: gameMap, - OnCollision: (obj, collisionObj, moveVec) => - { - //if (collisionObj is Mine) - //{ - // ActivateMine((Character)obj, (Mine)collisionObj); - // return MoveEngine.AfterCollision.ContinueCheck; - //} - return MoveEngine.AfterCollision.MoveMax; }, - EndMove: obj => - { - // Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); - } - ); - } - } - } -} diff --git a/logic/Gaming/PropManager.cs b/logic/Gaming/PropManager.cs index c52e761..8f82276 100644 --- a/logic/Gaming/PropManager.cs +++ b/logic/Gaming/PropManager.cs @@ -234,7 +234,7 @@ namespace Gaming { 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)); } diff --git a/logic/Preparation/Utility/EnumType.cs b/logic/Preparation/Utility/EnumType.cs index 8630e94..7ecc3e7 100644 --- a/logic/Preparation/Utility/EnumType.cs +++ b/logic/Preparation/Utility/EnumType.cs @@ -98,9 +98,12 @@ public enum MapInfoObjType Grass1 = 2, Grass2 = 3, Grass3 = 4, - BirthPoint1 = 5, - BirthPoint2 = 6, - BirthPoint3 = 7, - BirthPoint4 = 8, - BirthPoint5 = 9, + Generator = 5, // 发电机 + Exit = 6, + EmergencyExit = 7, + BirthPoint1 = 8, + BirthPoint2 = 9, + BirthPoint3 = 10, + BirthPoint4 = 11, + BirthPoint5 = 12, } \ No newline at end of file