diff --git a/logic/GameClass/GameObj/Character/Character.Ghost.cs b/logic/GameClass/GameObj/Character/Character.Ghost.cs index e58d057..309e419 100644 --- a/logic/GameClass/GameObj/Character/Character.Ghost.cs +++ b/logic/GameClass/GameObj/Character/Character.Ghost.cs @@ -11,18 +11,8 @@ namespace GameClass.GameObj { public class Ghost : Character { - public Ghost(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace) + public Ghost(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) { - switch (characterType) - { - case CharacterType.Assassin: - this.Occupation = new Assassin(); - break; - default: - this.Occupation = null; - break; - } - this.CharacterType = characterType; } } } diff --git a/logic/GameClass/GameObj/Character/Character.SkillManager.cs b/logic/GameClass/GameObj/Character/Character.SkillManager.cs index 483bf23..2393340 100644 --- a/logic/GameClass/GameObj/Character/Character.SkillManager.cs +++ b/logic/GameClass/GameObj/Character/Character.SkillManager.cs @@ -7,9 +7,10 @@ namespace GameClass.GameObj { public partial class Character { - - public CharacterType CharacterType { protected set; get; } - public IOccupation Occupation { protected set; get; } + private readonly CharacterType characterType; + public CharacterType CharacterType => characterType; + private readonly IOccupation occupation; + public IOccupation Occupation => occupation; private Dictionary timeUntilActiveSkillAvailable; public Dictionary TimeUntilActiveSkillAvailable => timeUntilActiveSkillAvailable; @@ -58,14 +59,25 @@ namespace GameClass.GameObj }; } - protected Character(XY initPos, int initRadius, PlaceType initPlace) : + protected Character(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, GameObjType.Character) { this.CanMove = true; this.score = 0; this.propInventory = null; this.buffManager = new BuffManager(); - + switch (characterType) + { + case CharacterType.Assassin: + this.occupation = new Assassin(); + break; + case CharacterType.Athlete: + this.occupation = new Athlete(); + break; + default: + this.occupation = null; + break; + } this.MaxHp = Occupation.MaxHp; this.hp = Occupation.MaxHp; this.OrgMoveSpeed = Occupation.MoveSpeed; @@ -75,6 +87,7 @@ namespace GameClass.GameObj this.bulletNum = maxBulletNum; this.bulletOfPlayer = Occupation.InitBullet; this.OriBulletOfPlayer = Occupation.InitBullet; + this.characterType = characterType; foreach (var activeSkill in this.Occupation.ListOfIActiveSkill) { diff --git a/logic/GameClass/GameObj/Character/Character.Student.cs b/logic/GameClass/GameObj/Character/Character.Student.cs index 6fc3306..267ae54 100644 --- a/logic/GameClass/GameObj/Character/Character.Student.cs +++ b/logic/GameClass/GameObj/Character/Character.Student.cs @@ -101,19 +101,9 @@ namespace GameClass.GameObj IsResetting = true; PlayerState = PlayerStateType.IsEscaped; } - public Student(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace) + public Student(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) { - switch (characterType) - { - case CharacterType.Athlete: - this.Occupation = new Athlete(); - break; - default: - this.Occupation = null; - break; - } this.fixSpeed = ((IStudent)Occupation).FixSpeed; - this.CharacterType = characterType; } } } diff --git a/logic/GameClass/GameObj/Map/Map.cs b/logic/GameClass/GameObj/Map/Map.cs index fd3d8ad..8d25c3c 100644 --- a/logic/GameClass/GameObj/Map/Map.cs +++ b/logic/GameClass/GameObj/Map/Map.cs @@ -3,6 +3,7 @@ using System.Threading; using Preparation.Interface; using Preparation.Utility; using System; +using GameClass.GameObj; namespace GameClass.GameObj { @@ -72,7 +73,41 @@ namespace GameClass.GameObj } return player; } - public Map(uint[,] mapResource) + public bool Remove(GameObj gameObj) + { + bool flag = false; + GameObjLockDict[gameObj.Type].EnterWriteLock(); + try + { + foreach (GameObj obj in GameObjDict[gameObj.Type]) + { + if (gameObj.ID == obj.ID) + { + GameObjDict[gameObj.Type].Remove(obj); + flag=true; + break; + } + } + } + finally + { + GameObjLockDict[gameObj.Type].ExitWriteLock(); + } + return flag; + } + public void Add(GameObj gameObj) + { + GameObjLockDict[gameObj.Type].EnterWriteLock(); + try + { + GameObjDict[gameObj.Type].Add(gameObj); + } + finally + { + GameObjLockDict[gameObj.Type].ExitWriteLock(); + } + } +public Map(uint[,] mapResource) { gameObjDict = new Dictionary>(); gameObjLockDict = new Dictionary(); diff --git a/logic/Gaming/AttackManager.cs b/logic/Gaming/AttackManager.cs index 9ae8cce..5cee6a5 100644 --- a/logic/Gaming/AttackManager.cs +++ b/logic/Gaming/AttackManager.cs @@ -154,31 +154,9 @@ namespace Gaming Debugger.Output(bullet, "bombed!"); #endif bullet.CanMove = false; - gameMap.GameObjLockDict[GameObjType.Bullet].EnterWriteLock(); - try - { - foreach (ObjOfCharacter _bullet in gameMap.GameObjDict[GameObjType.Bullet]) - { - if (_bullet.ID == bullet.ID) - { - gameMap.GameObjLockDict[GameObjType.BombedBullet].EnterWriteLock(); - try - { - gameMap.GameObjDict[GameObjType.BombedBullet].Add(new BombedBullet(bullet)); - } - finally - { - gameMap.GameObjLockDict[GameObjType.BombedBullet].ExitWriteLock(); - } - gameMap.GameObjDict[GameObjType.Bullet].Remove(_bullet); - break; - } - } - } - finally - { - gameMap.GameObjLockDict[GameObjType.Bullet].ExitWriteLock(); - } + + if(gameMap.Remove(bullet)&&bullet.IsToBomb) + gameMap.Add(new BombedBullet(bullet)); if (!bullet.IsToBomb) { @@ -334,12 +312,27 @@ namespace Gaming new Thread (() => { - - Thread.Sleep(bullet.CastTime); - - if (gameMap.Timer.IsGaming && player.PlayerState == PlayerStateType.IsTryingToAttack) + new FrameRateTaskExecutor( + loopCondition: () => player.PlayerState == PlayerStateType.IsTryingToAttack && gameMap.Timer.IsGaming , + loopToDo: () => + { + }, + timeInterval: GameData.frameDuration, + finallyReturn: () => 0, + maxTotalDuration: bullet.CastTime + ) + + .Start(); + + if (gameMap.Timer.IsGaming) { - player.PlayerState = PlayerStateType.Null; + if (player.PlayerState == PlayerStateType.IsTryingToAttack) + { + player.PlayerState = PlayerStateType.Null; + } + else + bullet.IsMoving= false; + gameMap.Remove(bullet); } } ) diff --git a/logic/Server/CopyInfo.cs b/logic/Server/CopyInfo.cs index 70f42d6..f9facfa 100644 --- a/logic/Server/CopyInfo.cs +++ b/logic/Server/CopyInfo.cs @@ -77,17 +77,17 @@ namespace Server } switch (player.Place) { - case Preparation.Utility.PlacccceType.Land: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Land; + case Preparation.Utility.PlaceType.Null: + msg.MessageOfCharacter.Place = Communication.Proto.PlaceType.Null; break; - case Preparation.Utility.PlacccceType.Grass1: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass1; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfCharacter.Place = Communication.Proto.PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass2: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass2; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfCharacter.Place = Communication.Proto.PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass3: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass3; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfCharacter.Place = Communication.Proto.PlaceType.Grass; break; // case Preparation.Utility.PlacccceType.Invisible: // msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Invisible; @@ -212,17 +212,17 @@ namespace Server msg.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID; switch (bullet.Place) { - case Preparation.Utility.PlacccceType.Land: - msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Land; + case Preparation.Utility.PlaceType.Null: + msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Null; break; - case Preparation.Utility.PlacccceType.Grass1: - msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Grass1; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass2: - msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Grass2; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass3: - msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Grass3; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass; break; default: msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType; @@ -271,17 +271,17 @@ namespace Server } switch (prop.Place) { - case Preparation.Utility.PlacccceType.Land: - msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Land; + case Preparation.Utility.PlaceType.Null: + msg.MessageOfProp.Place = Communication.Proto.PlaceType.Null; break; - case Preparation.Utility.PlacccceType.Grass1: - msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Grass1; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfProp.Place = Communication.Proto.PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass2: - msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Grass2; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfProp.Place = Communication.Proto.PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass3: - msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Grass3; + case Preparation.Utility.PlaceType.Grass: + msg.MessageOfProp.Place = Communication.Proto.PlaceType.Grass; break; default: msg.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;