|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- using System;
- using System.Diagnostics;
- using System.Net.NetworkInformation;
- using System.Threading;
- using GameClass.GameObj;
- using GameEngine;
- using Preparation.Interface;
- using Preparation.Utility;
- using Timothy.FrameRateTask;
-
- namespace Gaming
- {
- public partial class Game
- {
- private readonly ActionManager actionManager;
- private class ActionManager
- {
-
- // 人物移动
- private void SkillWhenColliding(Character player, IGameObj collisionObj)
- {
- if (collisionObj.Type == GameObjType.Bullet)
- {
- if (((Bullet)collisionObj).Parent != player && ((Bullet)collisionObj).TypeOfBullet == BulletType.JumpyDumpty)
- {
- if (CharacterManager.BeStunned((Character)player, ((Bullet)collisionObj).AP / GameData.timeFactorOfGhostFainting))
- player.AddScore(GameData.TrickerScoreStudentBeStunned(((Bullet)collisionObj).AP / GameData.timeFactorOfGhostFainting));
- gameMap.Remove((GameObj)collisionObj);
- }
- }
- if (player.FindIActiveSkill(ActiveSkillType.CanBeginToCharge).IsBeingUsed && collisionObj.Type == GameObjType.Character && ((Character)collisionObj).IsGhost())
- {
- if (CharacterManager.BeStunned((Character)collisionObj, GameData.TimeOfGhostFaintingWhenCharge))
- player.AddScore(GameData.StudentScoreTrickerBeStunned(GameData.TimeOfGhostFaintingWhenCharge));
- CharacterManager.BeStunned(player, GameData.TimeOfStudentFaintingWhenCharge);
- }
- }
- public bool MovePlayer(Character playerToMove, int moveTimeInMilliseconds, double moveDirection)
- {
- if (!playerToMove.Commandable()) return false;
- playerToMove.PlayerState = PlayerStateType.Moving;
- moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection);
- return true;
- }
-
- public static bool Stop(Character player)
- {
- if (player.Commandable())
- {
- player.PlayerState = PlayerStateType.Null;
- return true;
- }
- return false;
- }
-
- public bool Fix(Student player)// 自动检查有无发电机可修
- {
- if ((!player.Commandable()) || player.PlayerState == PlayerStateType.Fixing)
- return false;
- Generator? generatorForFix = (Generator?)gameMap.OneForInteract(player.Position, GameObjType.Generator);
-
- if (generatorForFix == null || generatorForFix.DegreeOfRepair == GameData.degreeOfFixedGenerator)
- return false;
-
- player.PlayerState = PlayerStateType.Fixing;
- new Thread
- (
- () =>
- {
- int ScoreAdded = GameData.StudentScoreFix(generatorForFix.DegreeOfRepair);
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.PlayerState == PlayerStateType.Fixing && gameMap.Timer.IsGaming && generatorForFix.DegreeOfRepair < GameData.degreeOfFixedGenerator,
- loopToDo: () =>
- {
- generatorForFix.Repair(player.FixSpeed * GameData.frameDuration);
- player.AddScore(GameData.StudentScoreFix(generatorForFix.DegreeOfRepair - ScoreAdded));
- ScoreAdded = GameData.StudentScoreFix(generatorForFix.DegreeOfRepair);
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
- .Start();
- if (generatorForFix.DegreeOfRepair >= GameData.degreeOfFixedGenerator)
- {
- gameMap.NumOfRepairedGenerators++;
- if (player.PlayerState == PlayerStateType.Fixing) player.PlayerState = PlayerStateType.Null;
- if (gameMap.NumOfRepairedGenerators == GameData.numOfGeneratorRequiredForEmergencyExit)
- {
- gameMap.GameObjLockDict[GameObjType.EmergencyExit].EnterWriteLock();
- try
- {
- Random r = new Random(Environment.TickCount);
- ((EmergencyExit)(gameMap.GameObjDict[GameObjType.EmergencyExit][r.Next(0, gameMap.GameObjDict[GameObjType.EmergencyExit].Count)])).CanOpen = true;
- }
- finally
- {
- gameMap.GameObjLockDict[GameObjType.EmergencyExit].ExitWriteLock();
- }
- }
- else
- if (gameMap.NumOfRepairedGenerators == 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();
- }
- }
-
- }
- }
-
- )
- { IsBackground = true }.Start();
-
- return true;
- }
-
- public bool OpenDoorway(Student player)
- {
- if (!(player.Commandable()) || player.PlayerState == PlayerStateType.OpeningTheDoorway)
- return false;
- Doorway? doorwayToOpen = (Doorway?)gameMap.OneForInteract(player.Position, GameObjType.Doorway);
- if (doorwayToOpen == null || doorwayToOpen.IsOpening || !doorwayToOpen.PowerSupply)
- return false;
-
- player.PlayerState = PlayerStateType.OpeningTheDoorway;
- doorwayToOpen.IsOpening = true;
- new Thread
- (
- () =>
- {
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.PlayerState == PlayerStateType.OpeningTheDoorway && gameMap.Timer.IsGaming && doorwayToOpen.OpenDegree < GameData.degreeOfOpenedDoorway,
- loopToDo: () =>
- {
- doorwayToOpen.OpenDegree += GameData.frameDuration;
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
-
- .Start();
- doorwayToOpen.IsOpening = false;
- if (doorwayToOpen.OpenDegree >= GameData.degreeOfOpenedDoorway)
- {
- if (player.PlayerState == PlayerStateType.OpeningTheDoorway)
- player.PlayerState = PlayerStateType.Null;
- }
- }
-
- )
- { IsBackground = true }.Start();
-
- return true;
- }
-
- public bool Escape(Student player)
- {
- if (!(player.Commandable()) || player.CharacterType == CharacterType.Robot)
- return false;
- Doorway? doorwayForEscape = (Doorway?)gameMap.OneForInteractInACross(player.Position, GameObjType.Doorway);
- if (doorwayForEscape != null)
- {
- if (doorwayForEscape.IsOpen())
- {
- player.AddScore(GameData.StudentScoreEscape);
- ++gameMap.NumOfEscapedStudent;
- player.Die(PlayerStateType.Escaped);
- return true;
- }
- else
- return false;
- }
- else
- {
- EmergencyExit? emergencyExit = (EmergencyExit?)gameMap.OneForInteractInACross(player.Position, GameObjType.EmergencyExit);
- if (emergencyExit != null && emergencyExit.IsOpen)
- {
- player.Die(PlayerStateType.Escaped);
- return true;
- }
- else
- return false;
- }
- }
-
- public bool Treat(Student player, Student? playerTreated = null)
- {
- if (playerTreated == null)
- {
- playerTreated = gameMap.StudentForInteract(player.Position);
- if (playerTreated == null) return false;
- }
- if (player == playerTreated || (!player.Commandable()) || player.PlayerState == PlayerStateType.Treating ||
- (!playerTreated.Commandable()) ||
- playerTreated.HP == playerTreated.MaxHp || !GameData.ApproachToInteract(playerTreated.Position, player.Position))
- return false;
-
- if (playerTreated.HP + playerTreated.DegreeOfTreatment >= playerTreated.MaxHp)
- {
- playerTreated.HP = playerTreated.MaxHp;
- playerTreated.DegreeOfTreatment = 0;
- return false;
- }
-
- if (playerTreated.DegreeOfTreatment >= GameData.basicTreatmentDegree)
- {
- playerTreated.HP += GameData.basicTreatmentDegree;
- playerTreated.DegreeOfTreatment = 0;
- return false;
- }
- new Thread
- (
- () =>
- {
- playerTreated.PlayerState = PlayerStateType.Treated;
- player.PlayerState = PlayerStateType.Treating;
- new FrameRateTaskExecutor<int>(
- loopCondition: () => playerTreated.PlayerState == PlayerStateType.Treated && player.PlayerState == PlayerStateType.Treating && gameMap.Timer.IsGaming && playerTreated.HP + playerTreated.DegreeOfTreatment < playerTreated.MaxHp && playerTreated.DegreeOfTreatment < GameData.basicTreatmentDegree && GameData.ApproachToInteract(playerTreated.Position, player.Position),
- loopToDo: () =>
- {
- playerTreated.DegreeOfTreatment += GameData.frameDuration * player.TreatSpeed;
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
-
- .Start();
-
- if (playerTreated.PlayerState == PlayerStateType.Treated) playerTreated.PlayerState = PlayerStateType.Null;
- if (player.PlayerState == PlayerStateType.Treating) player.PlayerState = PlayerStateType.Null;
-
- if (playerTreated.HP + playerTreated.DegreeOfTreatment >= playerTreated.MaxHp)
- {
- player.AddScore(GameData.StudentScoreTreat(playerTreated.MaxHp - playerTreated.HP));
- playerTreated.HP = playerTreated.MaxHp;
- playerTreated.DegreeOfTreatment = 0;
- }
- else
- if (playerTreated.DegreeOfTreatment >= GameData.basicTreatmentDegree)
- {
- player.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
- playerTreated.HP += GameData.basicTreatmentDegree;
- playerTreated.DegreeOfTreatment = 0;
- }
- }
- )
- { IsBackground = true }.Start();
- return true;
- }
- public bool Rescue(Student player, Student? playerRescued = null)
- {
- if (playerRescued == null)
- {
- playerRescued = gameMap.StudentForInteract(player.Position);
- if (playerRescued == null) return false;
- }
- if ((!player.Commandable()) || playerRescued.PlayerState != PlayerStateType.Addicted || player == playerRescued
- || !GameData.ApproachToInteract(playerRescued.Position, player.Position) || playerRescued.TimeOfRescue > 0)
- return false;
- player.PlayerState = PlayerStateType.Rescuing;
- playerRescued.PlayerState = PlayerStateType.Rescued;
-
- new Thread
- (
- () =>
- {
- new FrameRateTaskExecutor<int>(
- loopCondition: () => playerRescued.PlayerState == PlayerStateType.Rescued && player.PlayerState == PlayerStateType.Rescuing && gameMap.Timer.IsGaming && GameData.ApproachToInteract(playerRescued.Position, player.Position),
- loopToDo: () =>
- {
- playerRescued.TimeOfRescue += GameData.frameDuration;
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0,
- maxTotalDuration: GameData.basicTimeOfRescue
- )
- .Start();
-
- if (playerRescued.PlayerState == PlayerStateType.Rescued)
- {
- if (playerRescued.TimeOfRescue >= GameData.basicTimeOfRescue)
- {
- playerRescued.PlayerState = PlayerStateType.Null;
- playerRescued.HP = GameData.RemainHpWhenAddLife;
- player.AddScore(GameData.StudentScoreRescue);
- }
- else
- playerRescued.PlayerState = PlayerStateType.Addicted;
- }
- if (player.PlayerState == PlayerStateType.Rescuing) player.PlayerState = PlayerStateType.Null;
- playerRescued.TimeOfRescue = 0;
- }
- )
- { IsBackground = true }.Start();
-
- return true;
- }
- public bool OpenChest(Character player)
- {
- if ((!player.Commandable()) || player.PlayerState == PlayerStateType.OpeningTheChest)
- return false;
- Chest? chestToOpen = (Chest?)gameMap.OneForInteract(player.Position, GameObjType.Chest);
-
- if (chestToOpen == null || chestToOpen.IsOpen() || chestToOpen.OpenDegree > 0)
- return false;
-
- player.PlayerState = PlayerStateType.OpeningTheChest;
- new Thread
- (
- () =>
- {
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.PlayerState == PlayerStateType.OpeningTheChest && gameMap.Timer.IsGaming && (!chestToOpen.IsOpen()),
- loopToDo: () =>
- {
- chestToOpen.OpenDegree += GameData.frameDuration * player.SpeedOfOpenChest;
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
-
- .Start();
-
- if (chestToOpen.IsOpen())
- {
- if (player.PlayerState == PlayerStateType.OpeningTheChest)
- player.PlayerState = PlayerStateType.Null;
- for (int i = 0; i < GameData.maxNumOfPropInChest; ++i)
- {
- Prop prop = chestToOpen.PropInChest[i];
- chestToOpen.PropInChest[i] = new NullProp();
- prop.ReSetPos(player.Position, gameMap.GetPlaceType(player.Position));
- gameMap.Add(prop);
- }
- }
- else chestToOpen.OpenDegree = 0;
-
- }
-
- )
- { IsBackground = true }.Start();
-
- return true;
- }
- public bool ClimbingThroughWindow(Character player)
- {
- if (!player.Commandable())
- return false;
- Window? windowForClimb = (Window?)gameMap.OneForInteractInACross(player.Position, GameObjType.Window);
-
- if (windowForClimb == null || windowForClimb.WhoIsClimbing != null)
- return false;
-
- player.PlayerState = PlayerStateType.ClimbingThroughWindows;
- windowForClimb.WhoIsClimbing = player;
- XY windowToPlayer = new XY(
- (Math.Abs(player.Position.x - windowForClimb.Position.x) > GameData.numOfPosGridPerCell / 2) ? (GameData.numOfPosGridPerCell / 2 * (player.Position.x > windowForClimb.Position.x ? 1 : -1)) : 0,
- (Math.Abs(player.Position.y - windowForClimb.Position.y) > GameData.numOfPosGridPerCell / 2) ? (GameData.numOfPosGridPerCell / 2 * (player.Position.y > windowForClimb.Position.y ? 1 : -1)) : 0)
- ;
- new Thread
- (
- () =>
- {
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.PlayerState == PlayerStateType.ClimbingThroughWindows && gameMap.Timer.IsGaming,
- loopToDo: () => { },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0,
- maxTotalDuration: (int)((windowToPlayer + windowForClimb.Position - player.Position).Length() * 1000 / player.MoveSpeed)
- )
- .Start();
- if (player.PlayerState != PlayerStateType.ClimbingThroughWindows)
- {
- windowForClimb.WhoIsClimbing = null;
- return;
- }
-
- player.ReSetPos(windowToPlayer + windowForClimb.Position, PlaceType.Window);
- player.MoveSpeed = player.SpeedOfClimbingThroughWindows;
-
- moveEngine.MoveObj(player, (int)(windowToPlayer.Length() * 3.0 * 1000 / player.MoveSpeed), (-1 * windowToPlayer).Angle());
-
- new FrameRateTaskExecutor<int>(
- loopCondition: () => player.PlayerState == PlayerStateType.ClimbingThroughWindows && gameMap.Timer.IsGaming,
- loopToDo: () =>
- {
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0,
- maxTotalDuration: (int)(windowToPlayer.Length() * 3.0 * 1000 / player.MoveSpeed)
- )
- .Start();
- XY PosJumpOff = windowForClimb.Position - 2 * windowToPlayer;
- player.ReSetPos(PosJumpOff, gameMap.GetPlaceType(PosJumpOff));
- player.MoveSpeed = player.ReCalculateBuff(BuffType.AddSpeed, player.OrgMoveSpeed, GameData.MaxSpeed, GameData.MinSpeed);
- windowForClimb.WhoIsClimbing = null;
- if (player.PlayerState == PlayerStateType.ClimbingThroughWindows)
- {
- player.PlayerState = PlayerStateType.Null;
- }
- }
-
- )
- { IsBackground = true }.Start();
-
- return true;
- }
- public bool LockOrOpenDoor(Character player)
- {
- if (!(player.Commandable()) || player.PlayerState == PlayerStateType.LockingOrOpeningTheDoor)
- return false;
- Door? doorToLock = (Door?)gameMap.OneForInteract(player.Position, GameObjType.Door);
- if (doorToLock == null || doorToLock.OpenOrLockDegree > 0)
- return false;
- bool flag = false;
- foreach (Prop prop in player.PropInventory)
- {
- switch (prop.GetPropType())
- {
- case PropType.Key3:
- if (doorToLock.Place == PlaceType.Door3)
- flag = true;
- break;
- case PropType.Key5:
- if (doorToLock.Place == PlaceType.Door5)
- flag = true;
- break;
- case PropType.Key6:
- if (doorToLock.Place == PlaceType.Door6)
- flag = true;
- break;
- default:
- break;
- }
- if (flag) break;
- }
- if (!flag) return false;
-
- player.PlayerState = PlayerStateType.LockingOrOpeningTheDoor;
- new Thread
- (
- () =>
- {
- new FrameRateTaskExecutor<int>(
- loopCondition: () => flag && player.PlayerState == PlayerStateType.LockingOrOpeningTheDoor && gameMap.Timer.IsGaming && doorToLock.OpenOrLockDegree < GameData.degreeOfLockingOrOpeningTheDoor,
- loopToDo: () =>
- {
- flag = ((gameMap.OneInTheSameCell(doorToLock.Position, GameObjType.Character)) == null);
- doorToLock.OpenOrLockDegree += GameData.frameDuration * player.SpeedOfOpeningOrLocking;
- },
- timeInterval: GameData.frameDuration,
- finallyReturn: () => 0
- )
-
- .Start();
- if (doorToLock.OpenOrLockDegree >= GameData.degreeOfLockingOrOpeningTheDoor)
- {
- doorToLock.IsOpen = (!doorToLock.IsOpen);
- }
- if (player.PlayerState == PlayerStateType.LockingOrOpeningTheDoor)
- player.PlayerState = PlayerStateType.Null;
- doorToLock.OpenOrLockDegree = 0;
- }
-
- )
- { IsBackground = true }.Start();
-
- return true;
- }
-
- /*
- 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;
- public readonly MoveEngine moveEngine;
- public ActionManager(Map gameMap)
- {
- this.gameMap = gameMap;
- this.moveEngine = new MoveEngine(
- gameMap: gameMap,
- OnCollision: (obj, collisionObj, moveVec) =>
- {
- SkillWhenColliding((Character)obj, collisionObj);
- Preparation.Utility.Debugger.Output(obj, " end move with " + collisionObj.ToString());
- //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);
- }
- );
- }
- }
- }
- }
|