| @@ -0,0 +1,19 @@ | |||
| using Preparation.Utility; | |||
| using Preparation.GameData; | |||
| namespace GameClass.GameObj | |||
| { | |||
| /// <summary> | |||
| /// 发电机 | |||
| /// </summary> | |||
| 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; | |||
| } | |||
| } | |||
| @@ -14,7 +14,7 @@ namespace GameEngine | |||
| /// </summary> | |||
| public enum AfterCollision | |||
| { | |||
| ContinueCheck = 0, // 碰撞后继续检查其他碰撞 | |||
| ContinueCheck = 0, // 碰撞后继续检查其他碰撞,暂时没用 | |||
| MoveMax = 1, // 行走最远距离 | |||
| Destroyed = 2 // 物体已经毁坏 | |||
| } | |||
| @@ -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); | |||
| } | |||
| ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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)); | |||
| } | |||
| @@ -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, | |||
| } | |||