From 0e2f05fcebab9c7199fd1418a640526554d8c77e Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Wed, 10 May 2023 15:49:03 +0800 Subject: [PATCH] fix: :bug: fix the bug about the wrong setting about the BulletType of JumpyDumpty --- logic/GameClass/GameObj/Bullet/Bullet.cs | 4 ++-- .../GameClass/GameObj/Character/Character.cs | 13 ++++++------ logic/GameClass/GameObj/Moveable.cs | 4 ++++ logic/GameEngine/MoveEngine.cs | 16 +++++++------- logic/Gaming/ActionManager.cs | 8 +++---- logic/Gaming/AttackManager.cs | 6 +++--- logic/Gaming/CharacterManager .cs | 21 +++++++------------ 7 files changed, 35 insertions(+), 37 deletions(-) diff --git a/logic/GameClass/GameObj/Bullet/Bullet.cs b/logic/GameClass/GameObj/Bullet/Bullet.cs index 6451c25..262bc92 100644 --- a/logic/GameClass/GameObj/Bullet/Bullet.cs +++ b/logic/GameClass/GameObj/Bullet/Bullet.cs @@ -56,9 +56,9 @@ namespace GameClass.GameObj public static class BulletFactory { - public static Bullet? GetBullet(Character character, XY pos) + public static Bullet? GetBullet(Character character, XY pos, BulletType bulletType) { - switch (character.BulletOfPlayer) + switch (bulletType) { case BulletType.FlyingKnife: return new FlyingKnife(character, pos); diff --git a/logic/GameClass/GameObj/Character/Character.cs b/logic/GameClass/GameObj/Character/Character.cs index 932f6e1..9ee3277 100644 --- a/logic/GameClass/GameObj/Character/Character.cs +++ b/logic/GameClass/GameObj/Character/Character.cs @@ -95,7 +95,7 @@ namespace GameClass.GameObj (int)(Math.Abs((Radius + BulletFactory.BulletRadius(bulletOfPlayer)) * Math.Cos(angle))) * Math.Sign(Math.Cos(angle)), (int)(Math.Abs((Radius + BulletFactory.BulletRadius(bulletOfPlayer)) * Math.Sin(angle))) * Math.Sign(Math.Sin(angle)) ); - Bullet? bullet = BulletFactory.GetBullet(this, res); + Bullet? bullet = BulletFactory.GetBullet(this, res, this.bulletOfPlayer); if (bullet == null) return null; bullet.AP += TryAddAp() ? GameData.ApPropAdd : 0; facingDirection = new(angle, bullet.AttackDistance); @@ -325,20 +325,20 @@ namespace GameClass.GameObj private GameObj? whatInteractingWith = null; public GameObj? WhatInteractingWith => whatInteractingWith; - public void ChangePlayerState(PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null) + public long ChangePlayerState(PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null) { lock (actionLock) { - ++stateNum; whatInteractingWith = gameObj; if (value != PlayerStateType.Moving) IsMoving = false; playerState = (value == PlayerStateType.Moving) ? PlayerStateType.Null : value; //Debugger.Output(this,playerState.ToString()+" "+IsMoving.ToString()); + return ++stateNum; } } - public void ChangePlayerStateInOneThread(PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null) + public long ChangePlayerStateInOneThread(PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null) { lock (actionLock) { @@ -347,17 +347,18 @@ namespace GameClass.GameObj IsMoving = false; playerState = (value == PlayerStateType.Moving) ? PlayerStateType.Null : value; //Debugger.Output(this,playerState.ToString()+" "+IsMoving.ToString()); + return stateNum; } } - public void SetPlayerStateNaturally() + public long SetPlayerStateNaturally() { lock (actionLock) { - ++stateNum; whatInteractingWith = null; IsMoving = false; playerState = PlayerStateType.Null; + return ++stateNum; } } diff --git a/logic/GameClass/GameObj/Moveable.cs b/logic/GameClass/GameObj/Moveable.cs index 63e3b72..f31d0ed 100644 --- a/logic/GameClass/GameObj/Moveable.cs +++ b/logic/GameClass/GameObj/Moveable.cs @@ -18,6 +18,10 @@ namespace GameClass.GameObj lock (actionLock) return stateNum; } + set + { + lock (actionLock) stateNum = value; + } } //规定moveReaderWriterLock>actionLock diff --git a/logic/GameEngine/MoveEngine.cs b/logic/GameEngine/MoveEngine.cs index 60c45c9..fd84018 100644 --- a/logic/GameEngine/MoveEngine.cs +++ b/logic/GameEngine/MoveEngine.cs @@ -73,14 +73,12 @@ namespace GameEngine obj.MovingSetPos(new XY(moveVec, maxLen)); } - public void MoveObj(IMoveable obj, int moveTime, double direction) + public void MoveObj(IMoveable obj, int moveTime, double direction, long threadNum) { if (!gameTimer.IsGaming) return; - long threadNum; lock (obj.ActionLock) { if (!obj.IsAvailableForMove) return; - threadNum = obj.StateNum; obj.IsMoving = true; } new Thread @@ -89,7 +87,7 @@ namespace GameEngine { double moveVecLength = 0.0; XY res = new(direction, moveVecLength); - double deltaLen = moveVecLength - Math.Sqrt(obj.MovingSetPos(res)); // 转向,并用deltaLen存储行走的误差 + double deltaLen = 0; // 转向,并用deltaLen存储行走的误差 IGameObj? collisionObj = null; bool isDestroyed = false; @@ -125,7 +123,7 @@ namespace GameEngine res = new XY(direction, moveVecLength); //对人特殊处理 - if (threadNum > 0 && ((ICharacter)obj).StateNum != threadNum) return false; + if (threadNum > 0 && obj.StateNum != threadNum) return false; // 越界情况处理:如果越界,则与越界方块碰撞 bool flag; // 循环标志 @@ -146,7 +144,7 @@ namespace GameEngine isDestroyed = true; return false; case AfterCollision.MoveMax: - if (threadNum == 0 || ((ICharacter)obj).StateNum == threadNum) + if (threadNum == 0 || obj.StateNum == threadNum) MoveMax(obj, res); moveVecLength = 0; res = new XY(direction, moveVecLength); @@ -154,7 +152,7 @@ namespace GameEngine } } while (flag); - if (threadNum == 0 || ((ICharacter)obj).StateNum == threadNum) + if (threadNum == 0 || obj.StateNum == threadNum) deltaLen += moveVecLength - Math.Sqrt(obj.MovingSetPos(res)); return true; @@ -173,7 +171,7 @@ namespace GameEngine res = new XY(direction, moveVecLength); if ((collisionObj = collisionChecker.CheckCollisionWhenMoving(obj, res)) == null) { - if (threadNum == 0 || ((ICharacter)obj).StateNum == threadNum) + if (threadNum == 0 || obj.StateNum == threadNum) obj.MovingSetPos(res); } else @@ -188,7 +186,7 @@ namespace GameEngine isDestroyed = true; break; case AfterCollision.MoveMax: - if (threadNum == 0 || ((ICharacter)obj).StateNum == threadNum) + if (threadNum == 0 || obj.StateNum == threadNum) MoveMax(obj, res); moveVecLength = 0; res = new XY(direction, moveVecLength); diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index 09c8aba..0997307 100644 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -38,8 +38,8 @@ namespace Gaming if (moveTimeInMilliseconds < 5) return false; if (!playerToMove.Commandable()) return false; if (playerToMove.IsMoving) return false; - characterManager.SetPlayerState(playerToMove, PlayerStateType.Moving); - moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection); + moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection, + characterManager.SetPlayerState(playerToMove, PlayerStateType.Moving)); return true; } @@ -47,7 +47,7 @@ namespace Gaming { if (!playerToMove.Commandable() && playerToMove.PlayerState != PlayerStateType.Stunned) return false; characterManager.BeStunned(playerToMove, moveTimeInMilliseconds); - moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection); + moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection, playerToMove.StateNum); return true; } @@ -326,7 +326,7 @@ namespace Gaming player.ReSetPos(windowToPlayer + windowForClimb.Position); player.MoveSpeed = player.SpeedOfClimbingThroughWindows; - moveEngine.MoveObj(player, (int)(windowToPlayer.Length() * 3.0 * 1000 / player.MoveSpeed), (-1 * windowToPlayer).Angle()); + moveEngine.MoveObj(player, (int)(windowToPlayer.Length() * 3.0 * 1000 / player.MoveSpeed), (-1 * windowToPlayer).Angle(), threadNum); new FrameRateTaskExecutor( loopCondition: () => threadNum == player.StateNum && gameMap.Timer.IsGaming, diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index 6b0245a..841fbe4 100644 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -43,11 +43,11 @@ namespace Gaming { // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange if (bulletType == BulletType.Null) return; - Bullet? bullet = BulletFactory.GetBullet(player, pos); + Bullet? bullet = BulletFactory.GetBullet(player, 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); // 这里时间参数除出来的单位要是ms + moveEngine.MoveObj(bullet, (int)(bullet.AttackDistance * 1000 / bullet.MoveSpeed), angle, ++bullet.StateNum); // 这里时间参数除出来的单位要是ms } private void BombObj(Bullet bullet, GameObj objBeingShot) @@ -195,7 +195,7 @@ namespace Gaming { Debugger.Output(bullet, "Attack in " + bullet.Position.ToString()); gameMap.Add(bullet); - moveEngine.MoveObj(bullet, (int)(bullet.AttackDistance * 1000 / bullet.MoveSpeed), angle); // 这里时间参数除出来的单位要是ms + moveEngine.MoveObj(bullet, (int)(bullet.AttackDistance * 1000 / bullet.MoveSpeed), angle, ++bullet.StateNum); // 这里时间参数除出来的单位要是ms if (bullet.CastTime > 0) { characterManager.SetPlayerState(player, PlayerStateType.TryingToAttack); diff --git a/logic/Gaming/CharacterManager .cs b/logic/Gaming/CharacterManager .cs index 25b8ec7..5f21c1d 100644 --- a/logic/Gaming/CharacterManager .cs +++ b/logic/Gaming/CharacterManager .cs @@ -17,7 +17,7 @@ namespace Gaming this.gameMap = gameMap; } - public void SetPlayerState(Character player, PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null) + public long SetPlayerState(Character player, PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null) { lock (player.ActionLock) { @@ -25,29 +25,24 @@ namespace Gaming { case PlayerStateType.OpeningTheChest: ((Chest)player.WhatInteractingWith!).StopOpen(); - player.ChangePlayerState(value, gameObj); - break; + return player.ChangePlayerState(value, gameObj); case PlayerStateType.OpeningTheDoorway: Doorway doorway = (Doorway)player.WhatInteractingWith!; doorway.OpenDegree += gameMap.Timer.nowTime() - doorway.OpenStartTime; doorway.OpenStartTime = 0; - player.ChangePlayerState(value, gameObj); - break; + return player.ChangePlayerState(value, gameObj); case PlayerStateType.Addicted: if (value == PlayerStateType.Rescued) - player.ChangePlayerStateInOneThread(value, gameObj); + return player.ChangePlayerStateInOneThread(value, gameObj); else - player.ChangePlayerState(value, gameObj); - break; + return player.ChangePlayerState(value, gameObj); case PlayerStateType.Rescued: if (value == PlayerStateType.Addicted) - player.ChangePlayerStateInOneThread(value, gameObj); + return player.ChangePlayerStateInOneThread(value, gameObj); else - player.ChangePlayerState(value, gameObj); - break; + return player.ChangePlayerState(value, gameObj); default: - player.ChangePlayerState(value, gameObj); - break; + return player.ChangePlayerState(value, gameObj); } } }