Browse Source

feat: update CopyInfo

tags/0.1.0
gsy1519 2 years ago
parent
commit
d5f11889d9
9 changed files with 228 additions and 311 deletions
  1. +3
    -3
      dependency/proto/Message2Clients.proto
  2. +1
    -0
      dependency/proto/MessageType.proto
  3. +140
    -292
      logic/Server/CopyInfo.cs
  4. +63
    -10
      logic/Server/GameServer.cs
  5. +2
    -1
      logic/Server/Server.csproj
  6. +6
    -0
      logic/logic.sln
  7. +2
    -2
      playback/Playback/MessageReader.cs
  8. +1
    -1
      playback/Playback/MessageWriter.cs
  9. +10
    -2
      playback/Playback/Playback.csproj

+ 3
- 3
dependency/proto/Message2Clients.proto View File

@@ -10,8 +10,8 @@ message MessageOfStudent
int32 y = 2;
int32 speed = 3;
int32 determination = 4; // 剩余的学习毅力,相当于血量
int32 fail_num = 5; // 挂科的科目数
double time_until_skill_available = 6;
//int32 fail_num = 5; // 挂科的科目数
repeated double time_until_skill_available = 6;
PlaceType place = 7;
repeated PropType prop = 8;
StudentType student_type = 9;
@@ -130,7 +130,6 @@ message MessageOfMap
repeated PlaceType col = 1;
}
repeated Row row = 2;
repeated MessageOfMapObj map_obj_message = 3;
}

message MessageOfObj
@@ -142,6 +141,7 @@ message MessageOfObj
MessageOfProp prop_message = 3;
MessageOfBullet bullet_message = 4;
MessageOfBombedBullet bombed_bullet_message = 5;
MessageOfMapObj map_obj_message = 6;
}
}



+ 1
- 0
dependency/proto/MessageType.proto View File

@@ -25,6 +25,7 @@ enum PlaceType // 地图中的所有物件类型
HIDDEN_GATE = 6;
WINDOW = 7;
DOOR = 8;
BOX = 9;
// 待补充有特殊效果的地形

}


+ 140
- 292
logic/Server/CopyInfo.cs View File

@@ -8,13 +8,14 @@ namespace Server
public static class CopyInfo
{
// 下面赋值为0的大概率是还没写完 2023-03-03
/*public static MessageOfObj? Auto(GameObj gameObj)
public static MessageOfObj? Auto(GameObj gameObj)
{
if (gameObj.Type == Preparation.Utility.GameObjType.Character)
{
Character character = (Character)gameObj;
if (character.IsGhost())
return Tri
return Tricker((Character)character);
else return Student((Character)character);
}
else if (gameObj.Type == Preparation.Utility.GameObjType.Bullet)
return Bullet((Bullet)gameObj);
@@ -25,28 +26,33 @@ namespace Server
else if (gameObj.Type == Preparation.Utility.GameObjType.PickedProp)
return PickedProp((PickedProp)gameObj);
else return null; //先写着防报错
}*/
}

private static MessageOfStudent? Student(Character player)
private static MessageOfObj? Student(Character player)
{
MessageOfStudent msg = new MessageOfStudent();
if (player.IsGhost()) return null;

msg.X = player.Position.x;
msg.Y = player.Position.y;
msg.Speed = player.MoveSpeed;
msg.Determination = player.HP;
msg.FailNum = 0;
msg.TimeUntilSkillAvailable = 0;
msg.StudentType = StudentType.NullStudentType; // 下面写
msg.Guid = 0;
msg.State = StudentState.NullStatus;
msg.FailTime = 0;
msg.EmoTime = 0;
msg.PlayerId = 0;
msg.ViewRange = 0;
msg.Radius = 0;
MessageOfObj msg = new MessageOfObj();
if (player.IsGhost()) return null;

msg.StudentMessage.X = player.Position.x;
msg.StudentMessage.Y = player.Position.y;
msg.StudentMessage.Speed = player.MoveSpeed;
msg.StudentMessage.Determination = player.HP;
//msg.StudentMessage.FailNum = 0;
foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
//msg.StudentMessage.StudentType; // 下面写
msg.StudentMessage.Guid = player.ID;
msg.StudentMessage.State = StudentState.NullStatus;
msg.StudentMessage.FailTime = 0;
msg.StudentMessage.EmoTime = 0;
msg.StudentMessage.PlayerId = 0;
msg.StudentMessage.ViewRange = 0;
msg.StudentMessage.Radius = 0;
msg.StudentMessage.Damage = 0;
msg.StudentMessage.DangerAlert = 0;
msg.StudentMessage.Score = 0;
msg.StudentMessage.TreatProgress = 0;
msg.StudentMessage.RescueProgress = 0;

foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
{
@@ -55,179 +61,77 @@ namespace Server
switch (kvp.Key) // StudentBuffType具体内容待定
{
case Preparation.Utility.BuffType.Spear:
msg.Buff.Add(StudentBuffType.NullSbuffType);
msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
break;
case Preparation.Utility.BuffType.AddLIFE:
msg.Buff.Add(StudentBuffType.NullSbuffType);
msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
break;
case Preparation.Utility.BuffType.Shield:
msg.Buff.Add(StudentBuffType.NullSbuffType);
msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
break;
case Preparation.Utility.BuffType.AddSpeed:
msg.Buff.Add(StudentBuffType.NullSbuffType);
msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
break;
default:
break;
}
}
}
switch (player.Place)
{
case Preparation.Utility.PlaceType.EmergencyExit:
msg.Place = PlaceType.HiddenGate;
break;
case Preparation.Utility.PlaceType.Doorway:
msg.Place = PlaceType.Gate;
break;
case Preparation.Utility.PlaceType.Grass:
msg.Place = PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.BirthPoint1:
case Preparation.Utility.PlaceType.BirthPoint2:
case Preparation.Utility.PlaceType.BirthPoint3:
case Preparation.Utility.PlaceType.BirthPoint4:
case Preparation.Utility.PlaceType.BirthPoint5:
case Preparation.Utility.PlaceType.Null:
msg.Place = PlaceType.Land;
break;
// case Preparation.Utility.PlaceType.Invisible:
// msg.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible;
// break;
default:
msg.Place = PlaceType.NullPlaceType;
break;
}

//Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
//现在懒得改了,有时间再重整一波
if (player.PropInventory == null)
msg.Prop.Add(PropType.NullPropType);
msg.StudentMessage.Prop.Add(PropType.NullPropType);
else
{
switch (player.PropInventory.GetPropType())
{
case Preparation.Utility.PropType.Gem:
msg.Prop.Add(PropType.NullPropType);
msg.StudentMessage.Prop.Add(PropType.NullPropType);
break;
/*case Preparation.Utility.PropType.addLIFE:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
break;
case Preparation.Utility.PropType.addSpeed:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
break;
case Preparation.Utility.PropType.Shield:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
break;
case Preparation.Utility.PropType.Spear:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
break;
default:
msg.Prop = PropType.NullPropType;
msg.StudentMessage.Prop = PropType.NullPropType;
break;*/
}
}
/*switch (player.PassiveSkillType) 需要对接一下,proto里似乎没有这个
{
case Preparation.Utility.PassiveSkillType.RecoverAfterBattle:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.RecoverAfterBattle;
break;
case Preparation.Utility.PassiveSkillType.SpeedUpWhenLeavingGrass:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.SpeedUpWhenLeavingGrass;
break;
case Preparation.Utility.PassiveSkillType.Vampire:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.Vampire;
break;
default:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.NullPassiveSkillType;
break;
}

switch (player.CommonSkillType)
{
case Preparation.Utility.ActiveSkillType.BecomeAssassin:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeAssassin;
break;
case Preparation.Utility.ActiveSkillType.BecomeVampire:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeVampire;
break;
case Preparation.Utility.ActiveSkillType.NuclearWeapon:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.NuclearWeapon;
break;
case Preparation.Utility.ActiveSkillType.SuperFast:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.SuperFast;
break;
default:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.NullActiveSkillType;
break;
}

switch (player.BulletOfPlayer)
{
case Preparation.Utility.BulletType.AtomBomb:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.AtomBomb;
break;
case Preparation.Utility.BulletType.OrdinaryBullet:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.OrdinaryBullet;
break;
case Preparation.Utility.BulletType.FastBullet:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.FastBullet;
break;
case Preparation.Utility.BulletType.LineBullet:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.LineBullet;
break;
default:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.NullBulletType;
break;
}*/

return msg;
}

private static MessageOfTricker? Butcher(Character player)
private static MessageOfObj? Tricker(Character player)
{
MessageOfTricker msg = new MessageOfTricker();
MessageOfObj msg = new MessageOfObj();
if (!player.IsGhost()) return null;

msg.X = player.Position.x;
msg.Y = player.Position.y;
msg.Speed = player.MoveSpeed;
msg.Damage = 0;
msg.TimeUntilSkillAvailable = 0;
//msg.Place = 0; 下面写了
//msg.Prop = PropType.NullPropType; // 下面写
msg.TrickerType = TrickerType.NullTrickerType; // 下面写
msg.Guid = 0;
msg.Movable = false;
msg.PlayerId = 0;
msg.ViewRange = 0;
msg.Radius = 0;
//msg.Buff[0] = ButcherBuffType.NullSbuffType; 下面写了
msg.TrickerMessage.X = player.Position.x;
msg.TrickerMessage.Y = player.Position.y;
msg.TrickerMessage.Speed = player.MoveSpeed;
msg.TrickerMessage.Damage = 0;
msg.TrickerMessage.TimeUntilSkillAvailable = 0;
//msg.TrickerMessage.Place = 0; 下面写了
//msg.TrickerMessage.Prop = PropType.NullPropType; // 下面写
msg.TrickerMessage.TrickerType = TrickerType.NullTrickerType; // 下面写
msg.TrickerMessage.Guid = 0;
msg.TrickerMessage.Movable = false;
msg.TrickerMessage.PlayerId = 0;
msg.TrickerMessage.ViewRange = 0;
msg.TrickerMessage.Radius = 0;
//msg.TrickerMessage.Buff[0] = ButcherBuffType.NullSbuffType; 下面写了

/* THUAI5中的内容
msg.BulletNum = player.BulletNum;
msg.CanMove = player.CanMove;
msg.CD = player.CD;
msg.GemNum = player.GemNum;
msg.Guid = player.ID;
msg.IsDeceased = player.IsDeceased;
msg.LifeNum = player.DeathCount + 1;
msg.Radius = player.Radius;
msg.TimeUntilCommonSkillAvailable = player.TimeUntilCommonSkillAvailable;
msg.TeamID = player.TeamID;
msg.PlayerID = player.PlayerID;
msg.IsInvisible = player.IsInvisible;
msg.FacingDirection = player.FacingDirection;

//应该要发队伍分数,这里先发个人分数
msg.MessageOfHuman.Score = player.Score;

//这条暂时没啥用
msg.MessageOfHuman.TimeUntilUltimateSkillAvailable = 0;

msg.MessageOfHuman.Vampire = player.Vampire;*/

foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
{
if (kvp.Value)
@@ -235,16 +139,16 @@ namespace Server
switch (kvp.Key) // ButcherBuffType具体内容待定
{
case Preparation.Utility.BuffType.Spear:
msg.Buff.Add(TrickerBuffType.NullTbuffType);
msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
break;
case Preparation.Utility.BuffType.AddLIFE:
msg.Buff.Add(TrickerBuffType.NullTbuffType);
msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
break;
case Preparation.Utility.BuffType.Shield:
msg.Buff.Add(TrickerBuffType.NullTbuffType);
msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
break;
case Preparation.Utility.BuffType.AddSpeed:
msg.Buff.Add(TrickerBuffType.NullTbuffType);
msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
break;
default:
break;
@@ -254,261 +158,205 @@ namespace Server
/*switch (player.Place)
{
case Preparation.Utility.PlaceType.Land:
msg.Place = PlaceType.Land;
msg.TrickerMessage.Place = PlaceType.Land;
break;
case Preparation.Utility.PlaceType.Grass1:
msg.Place = PlaceType.Grass;
msg.TrickerMessage.Place = PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.Grass2:
msg.Place = PlaceType.Grass;
msg.TrickerMessage.Place = PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.Grass3:
msg.Place = PlaceType.Grass;
msg.TrickerMessage.Place = PlaceType.Grass;
break;
// case Preparation.Utility.PlaceType.Invisible:
// msg.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible;
// msg.TrickerMessage.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible;
// break;
default:
msg.Place = PlaceType.NullPlaceType;
msg.TrickerMessage.Place = PlaceType.NullPlaceType;
break;
}*/

//Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
//现在懒得改了,有时间再重整一波
/*if (player.PropInventory == null)
msg.Prop = PropType.NullPropType;
msg.TrickerMessage.Prop = PropType.NullPropType;
else
{
switch (player.PropInventory.GetPropType())
{
case Preparation.Utility.PropType.Gem:
msg.Prop = PropType.NullPropType;
msg.TrickerMessage.Prop = PropType.NullPropType;
break;
case Preparation.Utility.PropType.addLIFE:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
break;
case Preparation.Utility.PropType.addSpeed:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
break;
case Preparation.Utility.PropType.Shield:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
break;
case Preparation.Utility.PropType.Spear:
msg.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
break;
default:
msg.Prop = PropType.NullPropType;
msg.TrickerMessage.Prop = PropType.NullPropType;
break;
}
}*/
/*switch (player.PassiveSkillType) 需要对接一下,proto里似乎没有这个
{
case Preparation.Utility.PassiveSkillType.RecoverAfterBattle:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.RecoverAfterBattle;
break;
case Preparation.Utility.PassiveSkillType.SpeedUpWhenLeavingGrass:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.SpeedUpWhenLeavingGrass;
break;
case Preparation.Utility.PassiveSkillType.Vampire:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.Vampire;
break;
default:
msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.NullPassiveSkillType;
break;
}

switch (player.CommonSkillType)
{
case Preparation.Utility.ActiveSkillType.BecomeAssassin:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeAssassin;
break;
case Preparation.Utility.ActiveSkillType.BecomeVampire:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeVampire;
break;
case Preparation.Utility.ActiveSkillType.NuclearWeapon:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.NuclearWeapon;
break;
case Preparation.Utility.ActiveSkillType.SuperFast:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.SuperFast;
break;
default:
msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.NullActiveSkillType;
break;
}

switch (player.BulletOfPlayer)
{
case Preparation.Utility.BulletType.AtomBomb:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.AtomBomb;
break;
case Preparation.Utility.BulletType.OrdinaryBullet:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.OrdinaryBullet;
break;
case Preparation.Utility.BulletType.FastBullet:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.FastBullet;
break;
case Preparation.Utility.BulletType.LineBullet:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.LineBullet;
break;
default:
msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.NullBulletType;
break;
}*/

return msg;
}

/*private static MessageToClient.Types.GameObjMessage Bullet(Bullet bullet)
private static MessageOfObj Bullet(Bullet bullet)
{
MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
msg.MessageOfBullet = new MessageOfBullet();
msg.MessageOfBullet.FacingDirection = bullet.FacingDirection;
msg.MessageOfBullet.Guid = bullet.ID;
msg.MessageOfBullet.BombRange = BulletFactory.BulletBombRange(bullet.TypeOfBullet);
MessageOfObj msg = new MessageOfObj();
msg.BulletMessage.X = bullet.Position.x;
msg.BulletMessage.Y = bullet.Position.y;
//msg.BulletMessage.FacingDirection = bullet.FacingDirection; // XY转double?
msg.BulletMessage.Guid = bullet.ID;
msg.BulletMessage.Team = PlayerType.NullPlayerType;
msg.BulletMessage.Place = PlaceType.NullPlaceType;
msg.BulletMessage.BombRange = 0;
switch (bullet.TypeOfBullet)
{
case Preparation.Utility.BulletType.AtomBomb:
msg.MessageOfBullet.Type = Communication.Proto.BulletType.AtomBomb;
msg.BulletMessage.Type = BulletType.AtomBomb;
break;
case Preparation.Utility.BulletType.OrdinaryBullet:
msg.MessageOfBullet.Type = Communication.Proto.BulletType.OrdinaryBullet;
msg.BulletMessage.Type = BulletType.OrdinaryBullet;
break;
case Preparation.Utility.BulletType.FastBullet:
msg.MessageOfBullet.Type = Communication.Proto.BulletType.FastBullet;
msg.BulletMessage.Type = BulletType.FastBullet;
break;
case Preparation.Utility.BulletType.LineBullet:
msg.MessageOfBullet.Type = Communication.Proto.BulletType.LineBullet;
msg.BulletMessage.Type = BulletType.LineBullet;
break;
default:
msg.MessageOfBullet.Type = Communication.Proto.BulletType.NullBulletType;
msg.BulletMessage.Type = BulletType.NullBulletType;
break;
}
msg.MessageOfBullet.X = bullet.Position.x;
msg.MessageOfBullet.Y = bullet.Position.y;
if (bullet.Parent != null)
msg.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID;
switch (bullet.Place)
//if (bullet.Parent != null)
//msg.BulletMessage.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID;
/*switch (bullet.Place)
{
case Preparation.Utility.PlaceType.Null:
msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Null;
msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Null;
break;
case Preparation.Utility.PlaceType.Grass:
msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.Grass:
msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.Grass:
msg.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
break;
default:
msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType;
msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType;
break;
}
}*/
return msg;
}*/
}

private static MessageOfProp Prop(Prop prop)
private static MessageOfObj Prop(Prop prop)
{
MessageOfProp msg = new MessageOfProp();
//msg.Type = PropType.NullPropType; 下面写
msg.X = prop.Position.x;
msg.Y = prop.Position.y;
msg.FacingDirection = 0;
msg.Guid = 0;
msg.Place = PlaceType.NullPlaceType;
msg.Size = 0;
msg.IsMoving = false;
/* THUAI5中的内容
msg.MessageOfProp.FacingDirection = prop.FacingDirection;
msg.MessageOfProp.Guid = prop.ID;
msg.MessageOfProp.IsMoving = prop.IsMoving;*/
MessageOfObj msg = new MessageOfObj();
//msg.PropMessage.Type = PropType.NullPropType; 下面写
msg.PropMessage.X = prop.Position.x;
msg.PropMessage.Y = prop.Position.y;
msg.PropMessage.FacingDirection = 0;
msg.PropMessage.Guid = 0;
msg.PropMessage.Place = PlaceType.NullPlaceType;
msg.PropMessage.Size = 0;
msg.PropMessage.IsMoving = false;

switch (prop.GetPropType())
{
/*case Preparation.Utility.PropType.Gem:
msg.Type = PropType.Gem;
msg.PropMessage.Type = PropType.Gem;
break;
case Preparation.Utility.PropType.addLIFE:
msg.Type = PropType.AddLife;
msg.PropMessage.Type = PropType.AddLife;
break;
case Preparation.Utility.PropType.addSpeed:
msg.Type = PropType.AddSpeed;
msg.PropMessage.Type = PropType.AddSpeed;
break;
case Preparation.Utility.PropType.Shield:
msg.Type = PropType.Shield;
msg.PropMessage.Type = PropType.Shield;
break;
case Preparation.Utility.PropType.Spear:
msg.Type = PropType.Spear;
msg.PropMessage.Type = PropType.Spear;
break;*/
default:
msg.Type = PropType.NullPropType;
msg.PropMessage.Type = PropType.NullPropType;
break;
}

/*if(prop is Gem)
{
msg.MessageOfProp.Size = ((Gem)prop).Size;
msg.PropMessage.MessageOfProp.Size = ((Gem)prop).Size;
}
else
{
msg.MessageOfProp.Size = 1;
msg.PropMessage.MessageOfProp.Size = 1;
}
switch (prop.Place)
{
case Preparation.Utility.PlaceType.Null:
msg.MessageOfProp.Place = Communication.Proto.PlaceType.Null;
msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Null;
break;
case Preparation.Utility.PlaceType.Grass:
msg.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.Grass:
msg.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
break;
case Preparation.Utility.PlaceType.Grass:
msg.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
break;
default:
msg.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;
msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;
break;
}*/
return msg;
}

/*private static MessageOfBombedBullet BombedBullet(BombedBullet bombedBullet)
private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
{
MessageOfBombedBullet msg = new MessageOfBombedBullet;
msg.FacingDirection = bombedBullet.FacingDirection;
msg.X = bombedBullet.bulletHasBombed.Position.x;
msg.Y = bombedBullet.bulletHasBombed.Position.y;
msg.MappingID = bombedBullet.MappingID;
msg.BombRange = BulletFactory.BulletBombRange(bombedBullet.bulletHasBombed.TypeOfBullet);
MessageOfObj msg = new MessageOfObj();
msg.BombedBulletMessage.X = bombedBullet.bulletHasBombed.Position.x;
msg.BombedBulletMessage.Y = bombedBullet.bulletHasBombed.Position.y;
//msg.BombedBulletMessage.FacingDirection = bombedBullet.FacingDirection; XY类型转double?
msg.BombedBulletMessage.MappingId = bombedBullet.MappingID;
msg.BombedBulletMessage.BombRange = BulletFactory.BulletRadius(bombedBullet.bulletHasBombed.TypeOfBullet); // 待确认
switch (bombedBullet.bulletHasBombed.TypeOfBullet)
{
case Preparation.Utility.BulletType.OrdinaryBullet:
msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.OrdinaryBullet;
msg.BombedBulletMessage.Type = BulletType.OrdinaryBullet;
break;
case Preparation.Utility.BulletType.AtomBomb:
msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.AtomBomb;
msg.BombedBulletMessage.Type = BulletType.AtomBomb;
break;
case Preparation.Utility.BulletType.FastBullet:
msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.FastBullet;
msg.BombedBulletMessage.Type = BulletType.FastBullet;
break;
case Preparation.Utility.BulletType.LineBullet:
msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.LineBullet;
msg.BombedBulletMessage.Type = BulletType.LineBullet;
break;
default:
msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.NullBulletType;
msg.BombedBulletMessage.Type = BulletType.NullBulletType;
break;
}
return msg;
}*/
}

/*private static MessageToClient.Types.GameObjMessage PickedProp(PickedProp pickedProp)
private static MessageOfObj PickedProp(PickedProp pickedProp)
{
MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
msg.MessageOfPickedProp = new MessageOfPickedProp();
MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
/*msg.MessageOfPickedProp = new MessageOfPickedProp();

msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
@@ -534,8 +382,8 @@ namespace Server
default:
msg.MessageOfPickedProp.Type = Communication.Proto.PropType.NullPropType;
break;
}
}*/
return msg;
}*/
}
}
}

+ 63
- 10
logic/Server/GameServer.cs View File

@@ -7,6 +7,7 @@ using System.Net.Http.Headers;
using Gaming;
using GameClass.GameObj;
using Preparation.Utility;
using Playback;


namespace Server
@@ -37,7 +38,7 @@ namespace Server
private readonly object messageToAllClientsLock = new();
public static readonly long SendMessageToClientIntervalInMilliseconds = 50;
private readonly Semaphore endGameInfoSema = new(0, 1);
// private MessageWriter? mwr = null;
private MessageWriter? mwr = null;

public SemaphoreSlim StartGameTest()
{
@@ -85,14 +86,24 @@ namespace Server
var waitHandle = new SemaphoreSlim(gameState == true ? 1 : 0); // 注意修改
new Thread(() =>
{
bool flag = true;
new FrameRateTaskExecutor<int>
(
() => game.GameMap.Timer.IsGaming,
ReportGame,
1000,
() =>
{
ReportGame(); // 最后发一次消息,唤醒发消息的线程,防止发消息的线程由于有概率处在 Wait 状态而卡住
if (flag == true)
{
ReportGame(GameState.GameStart);
flag = false;
}
else ReportGame(GameState.GameRunning);
},
SendMessageToClientIntervalInMilliseconds,
() =>
{
ReportGame(GameState.GameEnd); // 最后发一次消息,唤醒发消息的线程,防止发消息的线程由于有概率处在 Wait 状态而卡住
OnGameEnd();
return 0;
}
).Start();
@@ -109,12 +120,41 @@ namespace Server
public void WaitForEnd()
{
this.endGameSem.Wait();
mwr?.Dispose();
}

private void OnGameEnd()
{
game.ClearAllLists();
mwr?.Flush();
//if (options.ResultFileName != DefaultArgumentOptions.FileName)
//SaveGameResult(options.ResultFileName + ".json");
//SendGameResult();
endGameInfoSema.Release();
}

public void ReportGame()
public void ReportGame(GameState gameState, bool requiredGaming = true)
{
//currentGameInfo = null;
var gameObjList = game.GetGameObj();
var gameObjList = game.GetGameObj();
lock (messageToAllClientsLock)
{
//currentGameInfo.MapMessage = (Messa(game.GameMap));
switch (gameState)
{
case GameState.GameRunning:
case GameState.GameStart:
case GameState.GameEnd:
foreach (GameObj gameObj in gameObjList)
{
currentGameInfo.ObjMessage.Add(CopyInfo.Auto(gameObj));
}
currentGameInfo.GameState = gameState;
mwr?.WriteOne(currentGameInfo);
break;
default:
break;
}
}

foreach (var kvp in semaDict)
{
@@ -145,7 +185,19 @@ namespace Server
return true;
return false;
}

private MessageOfMap MapMsg(Map map)
{
MessageOfMap msgOfMap = new MessageOfMap();
for (int i = 0; i < GameData.rows; i++)
{
msgOfMap.Row.Add(new MessageOfMap.Types.Row());
for (int j = 0; j < GameData.cols; j++)
{
//msgOfMap.Row[i].Col.Add((int)map.ProtoGameMap[i, j]); int转placetype
}
}
return msgOfMap;
}
public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context)
{
Console.WriteLine($"TryConnection ID: {request.PlayerId}");
@@ -224,7 +276,8 @@ namespace Server
} while (game.GameMap.Timer.IsGaming);
}

public override Task<BoolRes> Trick(TrickMsg request, ServerCallContext context)
public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context)
{
game.Attack(request.PlayerId, request.Angle);
BoolRes boolRes = new();
@@ -348,7 +401,7 @@ namespace Server
{
try
{
//mwr = new MessageWriter(options.FileName, options.TeamCount, options.PlayerCountPerTeam);
mwr = new MessageWriter(options.FileName, options.TeamCount, options.PlayerCountPerTeam);
}
catch
{


+ 2
- 1
logic/Server/Server.csproj View File

@@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="FrameRateTask" Version="1.2.0" />
<PackageReference Include="Google.Protobuf" Version="3.22.0" />
<PackageReference Include="Google.Protobuf" Version="3.22.1" />
<PackageReference Include="Grpc" Version="2.46.6" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="Grpc.Tools" Version="2.52.0">
@@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="..\..\dependency\proto\Protos.csproj" />
<ProjectReference Include="..\..\playback\Playback\Playback.csproj" />
<ProjectReference Include="..\GameClass\GameClass.csproj" />
<ProjectReference Include="..\GameEngine\GameEngine.csproj" />
<ProjectReference Include="..\Gaming\Gaming.csproj" />


+ 6
- 0
logic/logic.sln View File

@@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protos", "..\dependency\pro
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameEngine", "GameEngine\GameEngine.csproj", "{1D1D07F3-C332-4407-AC1B-EAD73F8BB3F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Playback", "..\playback\Playback\Playback.csproj", "{FF22960A-6BD9-4C80-A029-9A39FB8F64C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +53,10 @@ Global
{1D1D07F3-C332-4407-AC1B-EAD73F8BB3F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D1D07F3-C332-4407-AC1B-EAD73F8BB3F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D1D07F3-C332-4407-AC1B-EAD73F8BB3F3}.Release|Any CPU.Build.0 = Release|Any CPU
{FF22960A-6BD9-4C80-A029-9A39FB8F64C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF22960A-6BD9-4C80-A029-9A39FB8F64C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF22960A-6BD9-4C80-A029-9A39FB8F64C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF22960A-6BD9-4C80-A029-9A39FB8F64C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 2
- 2
playback/Playback/MessageReader.cs View File

@@ -1,5 +1,5 @@
using Communication.Proto;
using Google.Protobuf;
using Google.Protobuf;
using Protobuf;
using System;
using System.IO;
using System.IO.Compression;


+ 1
- 1
playback/Playback/MessageWriter.cs View File

@@ -1,5 +1,5 @@
using Communication.Proto;
using Google.Protobuf;
using Protobuf;
using System;
using System.IO;
using System.IO.Compression;


+ 10
- 2
playback/Playback/Playback.csproj View File

@@ -1,9 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.22.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\dependency\proto\Protos.csproj" />
</ItemGroup>

</Project>

Loading…
Cancel
Save