Browse Source

fix: 🐛 fix the bug of occupation initialzation

tags/0.1.0
shangfengh 2 years ago
parent
commit
33a4515c43
6 changed files with 103 additions and 82 deletions
  1. +1
    -11
      logic/GameClass/GameObj/Character/Character.Ghost.cs
  2. +18
    -5
      logic/GameClass/GameObj/Character/Character.SkillManager.cs
  3. +1
    -11
      logic/GameClass/GameObj/Character/Character.Student.cs
  4. +36
    -1
      logic/GameClass/GameObj/Map/Map.cs
  5. +23
    -30
      logic/Gaming/AttackManager.cs
  6. +24
    -24
      logic/Server/CopyInfo.cs

+ 1
- 11
logic/GameClass/GameObj/Character/Character.Ghost.cs View File

@@ -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;
}
}
}

+ 18
- 5
logic/GameClass/GameObj/Character/Character.SkillManager.cs View File

@@ -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<ActiveSkillType, int> timeUntilActiveSkillAvailable;
public Dictionary<ActiveSkillType, int> 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)
{


+ 1
- 11
logic/GameClass/GameObj/Character/Character.Student.cs View File

@@ -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;
}
}
}

+ 36
- 1
logic/GameClass/GameObj/Map/Map.cs View File

@@ -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<GameObjType, IList<IGameObj>>();
gameObjLockDict = new Dictionary<GameObjType, ReaderWriterLockSlim>();


+ 23
- 30
logic/Gaming/AttackManager.cs View File

@@ -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<int>(
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);
}
}
)


+ 24
- 24
logic/Server/CopyInfo.cs View File

@@ -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;


Loading…
Cancel
Save