|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using System;
- using System.Runtime.InteropServices;
- using GameClass.GameObj;
- using GameEngine;
- 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 TryToFix(Character player)// 自动检查有无发电机可修
- {
- if (player.IsResetting || player.IsGhost())
- return false;
- Generator? generatorForFix = null;
-
-
- gameMap.GameObjLockDict[GameObjType.Generator].EnterReadLock();
- try
- {
- foreach (Generator generator in gameMap.GameObjDict[GameObjType.Generator])
- {
- if (GameData.ApproachToInteract(generator.Position, player.Position))
- {
- generatorForFix = generator;
- break;
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Generator].ExitReadLock();
- }
-
-
- if (generatorForFix != null)
- {
- gameMap.GameObjLockDict[GameObjType.Generator].EnterReadLock();
- try
- {
- if (generatorForFix.Repair(player.FixSpeed))
- {
- Doorway exit = (Doorway)gameMap.GameObjDict[GameObjType.Doorway][1];
- if (!exit.PowerSupply)
- {
- int numOfFixedGenerator = 0;
- foreach (Generator generator in gameMap.GameObjDict[GameObjType.Generator])
- if (generator.DegreeOfFRepair == GameData.degreeOfFixedGenerator)
- ++numOfFixedGenerator;
- if (numOfFixedGenerator >= GameData.numOfGeneratorRequiredForRepair)
- {
- gameMap.GameObjLockDict[GameObjType.Doorway].EnterWriteLock();
- try
- {
- foreach (Doorway doorway in gameMap.GameObjDict[GameObjType.Doorway])
- doorway.PowerSupply = true;
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Doorway].ExitWriteLock();
- }
- }
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Generator].ExitReadLock();
- }
- return true;
- }
- else
- return false;
- }
-
- public bool TryToEscape(Character player)
- {
- if (player.IsResetting || player.IsGhost())
- return false;
- Doorway? doorwayForEscape = null;
-
-
- gameMap.GameObjLockDict[GameObjType.Doorway].EnterReadLock();
- try
- {
- foreach (Doorway doorway in gameMap.GameObjDict[GameObjType.Doorway])
- {
- if (GameData.IsInTheSameCell(doorway.Position, player.Position))
- {
- doorwayForEscape = doorway;
- break;
- }
- }
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.Doorway].ExitReadLock();
- }
-
-
- if (doorwayForEscape != null && doorwayForEscape.IsOpen)
- {
- player.Escape();
- 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);
- }
- );
- }
- }
- }
- }
|