From 6429d6144fa27b6741b981bd3d30c1e1c4cdb455 Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Fri, 3 Mar 2023 23:06:22 +0800 Subject: [PATCH 1/9] feat: :mag: update server --- dependency/proto/Message2Clients.proto | 1 + logic/ClientTest/Program.cs | 8 +- .../Character/Character.SkillManager.cs | 2 +- logic/Server/CopyInfo.cs | 406 +++++++++++++----- logic/Server/GameServer.cs | 129 ++++-- logic/Server/Properties/launchSettings.json | 8 + 6 files changed, 416 insertions(+), 138 deletions(-) create mode 100644 logic/Server/Properties/launchSettings.json diff --git a/dependency/proto/Message2Clients.proto b/dependency/proto/Message2Clients.proto index 5f13f80..0745eec 100755 --- a/dependency/proto/Message2Clients.proto +++ b/dependency/proto/Message2Clients.proto @@ -78,6 +78,7 @@ message MessageOfProp // 可拾取道具的信息 bool is_moving = 8; } + message MessageOfPickedProp //for Unity,直接继承自THUAI5 { PropType type = 1; diff --git a/logic/ClientTest/Program.cs b/logic/ClientTest/Program.cs index ef30dc9..ed5751a 100644 --- a/logic/ClientTest/Program.cs +++ b/logic/ClientTest/Program.cs @@ -7,11 +7,13 @@ namespace ClientTest { public static async Task Main(string[] args) { - Channel channel = new Channel("0.0.0.0:8888", ChannelCredentials.Insecure); + Thread.Sleep(3000); + Channel channel = new Channel("127.0.0.1:8888", ChannelCredentials.Insecure); var client = new AvailableService.AvailableServiceClient(channel); PlayerMsg playerInfo = new(); - playerInfo.PlayerId = Convert.ToInt32(args[0]); - playerInfo.PlayerType = (PlayerType)Convert.ToInt32(args[1]); + playerInfo.PlayerId = 0; + playerInfo.PlayerType = PlayerType.HumanPlayer; + playerInfo.HumanType = HumanType.NullHumanType; var call = client.AddPlayer(playerInfo); while (await call.ResponseStream.MoveNext()) { diff --git a/logic/GameClass/GameObj/Character/Character.SkillManager.cs b/logic/GameClass/GameObj/Character/Character.SkillManager.cs index 483bf23..e274f42 100644 --- a/logic/GameClass/GameObj/Character/Character.SkillManager.cs +++ b/logic/GameClass/GameObj/Character/Character.SkillManager.cs @@ -58,7 +58,7 @@ namespace GameClass.GameObj }; } - protected Character(XY initPos, int initRadius, PlaceType initPlace) : + public Character(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, GameObjType.Character) { this.CanMove = true; diff --git a/logic/Server/CopyInfo.cs b/logic/Server/CopyInfo.cs index 70f42d6..32516bc 100644 --- a/logic/Server/CopyInfo.cs +++ b/logic/Server/CopyInfo.cs @@ -1,74 +1,253 @@ using Protobuf; using System.Collections.Generic; using GameClass.GameObj; -/* + namespace Server { + public static class CopyInfo { - public static MessageToClient.Types.GameObjMessage? Auto(GameObj gameObj) + // 下面赋值为0的大概率是还没写完 2023-03-03 + private static MessageOfHuman Human(Character player) { - if (gameObj.Type == Preparation.Utility.GameObjType.Character) - return Player((Character)gameObj); - else if (gameObj.Type == Preparation.Utility.GameObjType.Bullet) - return Bullet((Bullet)gameObj); - else if (gameObj.Type == Preparation.Utility.GameObjType.Prop) - return Prop((Prop)gameObj); - else if (gameObj.Type == Preparation.Utility.GameObjType.BombedBullet) - return BombedBullet((BombedBullet)gameObj); - else if (gameObj.Type == Preparation.Utility.GameObjType.PickedProp) - return PickedProp((PickedProp)gameObj); - else return null; //先写着防报错 + MessageOfHuman msg = new MessageOfHuman(); + if (player.IsGhost()) return null; + + msg.X = player.Position.x; + msg.Y = player.Position.y; + msg.Speed = player.MoveSpeed; + msg.Life = player.HP; + msg.HangedTime = 0; + msg.TimeUntilSkillAvailable = 0; + //msg.Place = 0; 下面写了 + msg.Prop = PropType.NullPropType; // 下面写 + msg.HumanType = HumanType.NullHumanType; // 下面写 + msg.Guid = 0; + msg.State = HumanState.NullStatus; + msg.ChairTime = 0; + msg.GroundTime = 0; + msg.PlayerId = 0; + msg.ViewRange = 0; + msg.Radius = 0; + //msg.Buff[0] = HumanBuffType.NullHbuffType; 下面写了 + + /* THUAI5中的内容 + msg.BulletNum = player.BulletNum; + msg.CanMove = player.CanMove; + msg.CD = player.CD; + msg.GemNum = player.GemNum; + msg.Guid = player.ID; + msg.IsResetting = player.IsResetting; + + 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 kvp in player.Buff) + { + if (kvp.Value) + { + switch (kvp.Key) // HumanBuffType具体内容待定 + { + case Preparation.Utility.BuffType.Spear: + msg.Buff.Add(HumanBuffType.NullHbuffType); + break; + case Preparation.Utility.BuffType.AddLIFE: + msg.Buff.Add(HumanBuffType.NullHbuffType); + break; + case Preparation.Utility.BuffType.Shield: + msg.Buff.Add(HumanBuffType.NullHbuffType); + break; + case Preparation.Utility.BuffType.AddSpeed: + msg.Buff.Add(HumanBuffType.NullHbuffType); + break; + default: + break; + } + } + } + switch (player.Place) + { + case Preparation.Utility.PlaceType.Land: + msg.Place = PlaceType.Land; + break; + case Preparation.Utility.PlaceType.Grass1: + msg.Place = PlaceType.Grass; + break; + case Preparation.Utility.PlaceType.Grass2: + msg.Place = PlaceType.Grass; + break; + case Preparation.Utility.PlaceType.Grass3: + msg.Place = PlaceType.Grass; + 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 = PropType.NullPropType; + else + { + switch (player.PropInventory.GetPropType()) + { + case Preparation.Utility.PropType.Gem: + msg.Prop = PropType.NullPropType; + break; + /*case Preparation.Utility.PropType.addLIFE: + msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife; + break; + case Preparation.Utility.PropType.addSpeed: + msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed; + break; + case Preparation.Utility.PropType.Shield: + msg.MessageOfHuman.Prop = Communication.Proto.PropType.Shield; + break; + case Preparation.Utility.PropType.Spear: + msg.MessageOfHuman.Prop = Communication.Proto.PropType.Spear; + break;*/ + default: + msg.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 Player(Character player) + private static MessageOfButcher Butcher(Character player) { - MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage(); - msg.MessageOfCharacter = new MessageOfCharacter(); + MessageOfButcher msg = new MessageOfButcher(); + if (!player.IsGhost()) return null; - msg.MessageOfCharacter.X = player.Position.x; - msg.MessageOfCharacter.Y = player.Position.y; - msg.MessageOfCharacter.AttackRange = player.AttackRange; - msg.MessageOfCharacter.BulletNum = player.BulletNum; - msg.MessageOfCharacter.CanMove = player.CanMove; - msg.MessageOfCharacter.CD = player.CD; - msg.MessageOfCharacter.GemNum = player.GemNum; - msg.MessageOfCharacter.Guid = player.ID; - msg.MessageOfCharacter.IsResetting = player.IsResetting; - msg.MessageOfCharacter.Life = player.HP; - msg.MessageOfCharacter.LifeNum = player.DeathCount + 1; - msg.MessageOfCharacter.Radius = player.Radius; - msg.MessageOfCharacter.Speed = player.MoveSpeed; - msg.MessageOfCharacter.TimeUntilCommonSkillAvailable = player.TimeUntilCommonSkillAvailable; - msg.MessageOfCharacter.TeamID = player.TeamID; - msg.MessageOfCharacter.PlayerID = player.PlayerID; - msg.MessageOfCharacter.IsInvisible = player.IsInvisible; - msg.MessageOfCharacter.FacingDirection = player.FacingDirection; + 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.ButcherType = ButcherType.NullButcherType; // 下面写 + msg.Guid = 0; + msg.Movable = false; + msg.PlayerId = 0; + msg.ViewRange = 0; + msg.Radius = 0; + //msg.Buff[0] = ButcherBuffType.NullHbuffType; 下面写了 + + /* THUAI5中的内容 + msg.BulletNum = player.BulletNum; + msg.CanMove = player.CanMove; + msg.CD = player.CD; + msg.GemNum = player.GemNum; + msg.Guid = player.ID; + msg.IsResetting = player.IsResetting; + + 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.MessageOfCharacter.Score = player.Score; + msg.MessageOfHuman.Score = player.Score; //这条暂时没啥用 - msg.MessageOfCharacter.TimeUntilUltimateSkillAvailable = 0; + msg.MessageOfHuman.TimeUntilUltimateSkillAvailable = 0; + + msg.MessageOfHuman.Vampire = player.Vampire;*/ - msg.MessageOfCharacter.Vampire = player.Vampire; foreach (KeyValuePair kvp in player.Buff) { if (kvp.Value) { - switch(kvp.Key) + switch (kvp.Key) // ButcherBuffType具体内容待定 { case Preparation.Utility.BuffType.Spear: - msg.MessageOfCharacter.Buff.Add(BuffType.SpearBuff); + msg.Buff.Add(ButcherBuffType.NullBbuffType); break; case Preparation.Utility.BuffType.AddLIFE: - msg.MessageOfCharacter.Buff.Add(BuffType.AddLife); + msg.Buff.Add(ButcherBuffType.NullBbuffType); break; case Preparation.Utility.BuffType.Shield: - msg.MessageOfCharacter.Buff.Add(BuffType.ShieldBuff); + msg.Buff.Add(ButcherBuffType.NullBbuffType); break; case Preparation.Utility.BuffType.AddSpeed: - msg.MessageOfCharacter.Buff.Add(BuffType.MoveSpeed); + msg.Buff.Add(ButcherBuffType.NullBbuffType); break; default: break; @@ -77,111 +256,112 @@ namespace Server } switch (player.Place) { - case Preparation.Utility.PlacccceType.Land: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Land; + case Preparation.Utility.PlaceType.Land: + msg.Place = PlaceType.Land; break; - case Preparation.Utility.PlacccceType.Grass1: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass1; + case Preparation.Utility.PlaceType.Grass1: + msg.Place = PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass2: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass2; + case Preparation.Utility.PlaceType.Grass2: + msg.Place = PlaceType.Grass; break; - case Preparation.Utility.PlacccceType.Grass3: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass3; + case Preparation.Utility.PlaceType.Grass3: + msg.Place = PlaceType.Grass; break; - // case Preparation.Utility.PlacccceType.Invisible: - // msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Invisible; - // break; + // case Preparation.Utility.PlaceType.Invisible: + // msg.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible; + // break; default: - msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.NullPlaceType; + msg.Place = PlaceType.NullPlaceType; break; } //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象 //现在懒得改了,有时间再重整一波 if (player.PropInventory == null) - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.NullPropType; + msg.Prop = PropType.NullPropType; else { switch (player.PropInventory.GetPropType()) { case Preparation.Utility.PropType.Gem: - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.Gem; + msg.Prop = PropType.NullPropType; break; - case Preparation.Utility.PropType.addLIFE: - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.AddLife; + /*case Preparation.Utility.PropType.addLIFE: + msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife; break; case Preparation.Utility.PropType.addSpeed: - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.AddSpeed; + msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed; break; case Preparation.Utility.PropType.Shield: - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.Shield; + msg.MessageOfHuman.Prop = Communication.Proto.PropType.Shield; break; case Preparation.Utility.PropType.Spear: - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.Spear; - break; + msg.MessageOfHuman.Prop = Communication.Proto.PropType.Spear; + break;*/ default: - msg.MessageOfCharacter.Prop = Communication.Proto.PropType.NullPropType; + msg.Prop = PropType.NullPropType; break; } } - switch (player.PassiveSkillType) + /*switch (player.PassiveSkillType) 需要对接一下,proto里似乎没有这个 { case Preparation.Utility.PassiveSkillType.RecoverAfterBattle: - msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.RecoverAfterBattle; + msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.RecoverAfterBattle; break; case Preparation.Utility.PassiveSkillType.SpeedUpWhenLeavingGrass: - msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.SpeedUpWhenLeavingGrass; + msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.SpeedUpWhenLeavingGrass; break; case Preparation.Utility.PassiveSkillType.Vampire: - msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.Vampire; + msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.Vampire; break; default: - msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.NullPassiveSkillType; + msg.MessageOfHuman.PassiveSkillType = Communication.Proto.PassiveSkillType.NullPassiveSkillType; break; } + switch (player.CommonSkillType) { case Preparation.Utility.ActiveSkillType.BecomeAssassin: - msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeAssassin; + msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeAssassin; break; case Preparation.Utility.ActiveSkillType.BecomeVampire: - msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeVampire; + msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeVampire; break; case Preparation.Utility.ActiveSkillType.NuclearWeapon: - msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.NuclearWeapon; + msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.NuclearWeapon; break; case Preparation.Utility.ActiveSkillType.SuperFast: - msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.SuperFast; + msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.SuperFast; break; default: - msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.NullActiveSkillType; + msg.MessageOfHuman.ActiveSkillType = Communication.Proto.ActiveSkillType.NullActiveSkillType; break; } switch (player.BulletOfPlayer) { case Preparation.Utility.BulletType.AtomBomb: - msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.AtomBomb; + msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.AtomBomb; break; case Preparation.Utility.BulletType.OrdinaryBullet: - msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.OrdinaryBullet; + msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.OrdinaryBullet; break; case Preparation.Utility.BulletType.FastBullet: - msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.FastBullet; + msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.FastBullet; break; case Preparation.Utility.BulletType.LineBullet: - msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.LineBullet; + msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.LineBullet; break; default: - msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.NullBulletType; + msg.MessageOfHuman.BulletType = Communication.Proto.BulletType.NullBulletType; break; - } + }*/ return msg; } - private static MessageToClient.Types.GameObjMessage Bullet(Bullet bullet) + /*private static MessageToClient.Types.GameObjMessage Bullet(Bullet bullet) { MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage(); msg.MessageOfBullet = new MessageOfBullet(); @@ -229,39 +409,47 @@ namespace Server break; } return msg; - } + }*/ - private static MessageToClient.Types.GameObjMessage Prop(Prop prop) + private static MessageOfProp Prop(Prop prop) { - MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage(); - msg.MessageOfProp = new MessageOfProp(); + 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; + msg.MessageOfProp.IsMoving = prop.IsMoving;*/ + switch (prop.GetPropType()) { - case Preparation.Utility.PropType.Gem: - msg.MessageOfProp.Type = Communication.Proto.PropType.Gem; + /*case Preparation.Utility.PropType.Gem: + msg.Type = PropType.Gem; break; case Preparation.Utility.PropType.addLIFE: - msg.MessageOfProp.Type = Communication.Proto.PropType.AddLife; + msg.Type = PropType.AddLife; break; case Preparation.Utility.PropType.addSpeed: - msg.MessageOfProp.Type = Communication.Proto.PropType.AddSpeed; + msg.Type = PropType.AddSpeed; break; case Preparation.Utility.PropType.Shield: - msg.MessageOfProp.Type = Communication.Proto.PropType.Shield; + msg.Type = PropType.Shield; break; case Preparation.Utility.PropType.Spear: - msg.MessageOfProp.Type = Communication.Proto.PropType.Spear; - break; + msg.Type = PropType.Spear; + break;*/ default: - msg.MessageOfProp.Type = Communication.Proto.PropType.NullPropType; + msg.Type = PropType.NullPropType; break; } - msg.MessageOfProp.X = prop.Position.x; - msg.MessageOfProp.Y = prop.Position.y; - if(prop is Gem) + + /*if(prop is Gem) { msg.MessageOfProp.Size = ((Gem)prop).Size; } @@ -286,20 +474,19 @@ namespace Server default: msg.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType; break; - } + }*/ return msg; } - private static MessageToClient.Types.GameObjMessage BombedBullet(BombedBullet bombedBullet) + /*private static MessageOfBombedBullet BombedBullet(BombedBullet bombedBullet) { - MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage(); - msg.MessageOfBombedBullet = new MessageOfBombedBullet(); + MessageOfBombedBullet msg = new MessageOfBombedBullet; - msg.MessageOfBombedBullet.FacingDirection = bombedBullet.bulletHasBombed.FacingDirection; - msg.MessageOfBombedBullet.X = bombedBullet.bulletHasBombed.Position.x; - msg.MessageOfBombedBullet.Y = bombedBullet.bulletHasBombed.Position.y; - msg.MessageOfBombedBullet.MappingID = bombedBullet.MappingID; - msg.MessageOfBombedBullet.BombRange = BulletFactory.BulletBombRange(bombedBullet.bulletHasBombed.TypeOfBullet); + 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); switch (bombedBullet.bulletHasBombed.TypeOfBullet) { case Preparation.Utility.BulletType.OrdinaryBullet: @@ -319,9 +506,9 @@ namespace Server break; } return msg; - } + }*/ - private static MessageToClient.Types.GameObjMessage PickedProp(PickedProp pickedProp) + /*private static MessageToClient.Types.GameObjMessage PickedProp(PickedProp pickedProp) { MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage(); msg.MessageOfPickedProp = new MessageOfPickedProp(); @@ -352,7 +539,6 @@ namespace Server break; } return msg; - } + }*/ } -}*/ -// 等Preparation完成再写 +} diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index 77e08de..c48e082 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -6,6 +6,8 @@ using System; using System.Net.Http.Headers; using Gaming; using GameClass.GameObj; +using Preparation.Utility; + namespace Server { @@ -13,9 +15,17 @@ namespace Server { private Dictionary semaDict = new(); private object gameLock = new(); - private const int playerNum = 2; // 注意修改 + private const int playerNum = 1; // 注意修改 private MessageToClient currentGameInfo = new(); private SemaphoreSlim endGameSem = new(0); + + object gameInfo = new(); + private int isGaming = 0; + public bool IsGaming + { + get => Interlocked.CompareExchange(ref isGaming, 0, 0) != 0; + set => Interlocked.Exchange(ref isGaming, value ? 1 : 0); + } // 以上是测试时用到的定义 protected readonly ArgumentOptions options; @@ -29,6 +39,46 @@ namespace Server private readonly Semaphore endGameInfoSema = new(0, 1); // private MessageWriter? mwr = null; + public SemaphoreSlim StartGameTest() + { + IsGaming = true; + var waitHandle = new SemaphoreSlim(0); + + new Thread + ( + () => + { + new FrameRateTaskExecutor + ( + () => IsGaming, + () => + { + lock (gameInfo) + { + /*for (int i = 0; i < gameInfo.GameObjs.Count; i++) + { + if (gameInfo.GameObjs[i].Character != null) + { + gameInfo.GameObjs[i].Character.X++; + gameInfo.GameObjs[i].Character.Y--; + } + }*/ + } + }, + 100, + () => + { + IsGaming = false; + waitHandle.Release(); + return 0; + }, + 3000//gameTime + ).Start(); + } + ) + { IsBackground = true }.Start(); + return waitHandle; + } public void StartGame() { bool gameState = game.StartGame((int)options.GameTimeInSecond * 1000); @@ -63,9 +113,7 @@ namespace Server public void ReportGame() { - // currentGameInfo = game.GetCopiedGameInfo(); - currentGameInfo.HumanMessage[0].X = 1; - currentGameInfo.ButcherMessage[0].X = 1; + //currentGameInfo = null; foreach (var kvp in semaDict) { @@ -77,13 +125,29 @@ namespace Server kvp.Value.Item2.Wait(); } } - private uint GetBirthPointIdx(long teamID, long playerID) // 获取出生点位置 + + private int PlayerTypeToTeamID(PlayerType playerType) + { + if (playerType == PlayerType.HumanPlayer) return 0; + if (playerType == PlayerType.ButcherPlayer) return 1; + return -1; + } + private uint GetBirthPointIdx(PlayerType playerType, long playerID) // 获取出生点位置 + { + return (uint)((PlayerTypeToTeamID(playerType) * options.PlayerCountPerTeam) + playerID + 1); + } + private bool ValidPlayerTypeAndPlayerID(PlayerType playerType, long playerID) { - return (uint)((teamID * options.PlayerCountPerTeam) + playerID); + if (playerType == PlayerType.HumanPlayer && 0 <= playerID && playerID < options.PlayerCountPerTeam) + return true; // 人数待修改 + if (playerType == PlayerType.ButcherPlayer && 0 <= playerID && playerID < options.PlayerCountPerTeam) + return true; + return false; } public override Task TryConnection(IDMsg request, ServerCallContext context) { + Console.WriteLine($"TryConnection ID: {request.PlayerId}"); var onConnection = new BoolRes(); lock (gameLock) { @@ -101,6 +165,7 @@ namespace Server protected readonly object addPlayerLock = new(); public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter responseStream, ServerCallContext context) { + Console.WriteLine($"AddPlayer: {request.PlayerId}"); if (request.PlayerId >= spectatorMinPlayerID && request.PlayerType == PlayerType.NullPlayerType) { // 观战模式 @@ -115,23 +180,23 @@ namespace Server if (game.GameMap.Timer.IsGaming) return; - /*if (!ValidTeamIDAndPlayerID(msg.TeamID, msg.PlayerID)) //玩家id是否正确 - return; - if (communicationToGameID[msg.TeamID, msg.PlayerID] != GameObj.invalidID) //是否已经添加了该玩家 - return false; + if (!ValidPlayerTypeAndPlayerID(request.PlayerType, request.PlayerId)) //玩家id是否正确 + return; + //if (communicationToGameID[PlayerTypeToTeamID(request.PlayerType), request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家 + //return; + + Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null; // 待修改 - Preparation.Utility.PassiveSkillType passiveSkill; - */ lock (addPlayerLock) { - /*Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(msg.TeamID, msg.PlayerID), msg.TeamID, msg.PlayerID, passiveSkill, commonSkill); + Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerType, request.PlayerId), PlayerTypeToTeamID(request.PlayerType), request.PlayerId, characterType); long newPlayerID = game.AddPlayer(playerInitInfo); - if (newPlayerID == GameObj.invalidID) - return false;*/ + //if (newPlayerID == GameObj.invalidID) + //return; // 内容待修改 var temp = (new SemaphoreSlim(0, 1), new SemaphoreSlim(0, 1)); bool start = false; - Console.WriteLine($"Id: {request.PlayerId} joins."); + Console.WriteLine($"PlayerType: {request.PlayerType} Id: {request.PlayerId} joins."); lock (semaDict) { semaDict.Add(request.PlayerId, temp); @@ -159,7 +224,10 @@ namespace Server public override Task Attack(AttackMsg request, ServerCallContext context) { - return base.Attack(request, context); + game.Attack(request.PlayerId, request.Angle); + BoolRes boolRes = new(); + boolRes.ActSuccess = true; + return Task.FromResult(boolRes); } public override Task CarryHuman(IDMsg request, ServerCallContext context) @@ -194,12 +262,20 @@ namespace Server public override Task Move(MoveMsg request, ServerCallContext context) { - return base.Move(request, context); + Console.WriteLine($"Move ID: {request.PlayerId}, TimeInMilliseconds: {request.TimeInMilliseconds}"); + game.MovePlayer(request.PlayerId, (int)request.TimeInMilliseconds, request.Angle); + // 之后game.MovePlayer可能改为bool类型 + MoveRes moveRes = new(); + moveRes.ActSuccess = true; + return Task.FromResult(moveRes); } public override Task PickProp(PickMsg request, ServerCallContext context) { - return base.PickProp(request, context); + BoolRes boolRes = new(); + if (request.PropType == Protobuf.PropType.NullPropType) + boolRes.ActSuccess = game.PickProp(request.PlayerId, Preparation.Utility.PropType.Null); + return Task.FromResult(boolRes); } public override Task ReleaseHuman(IDMsg request, ServerCallContext context) @@ -234,10 +310,10 @@ namespace Server public GameServer(ArgumentOptions options) { - /*this.options = options; - if (options.mapResource == DefaultArgumentOptions.MapResource) - this.game = new Game(MapInfo.defaultMap, options.TeamCount); - else + this.options = options; + //if (options.mapResource == DefaultArgumentOptions.MapResource) + // this.game = new Game(MapInfo.defaultMap, options.TeamCount); + //else { uint[,] map = new uint[GameData.rows, GameData.cols]; try @@ -277,6 +353,11 @@ namespace Server catch { map = MapInfo.defaultMap; + map[0, 0] = 1; + map[2, 2] = 2; + map[4, 2] = 3; + map[6, 2] = 4; + map[8, 2] = 5; } finally { this.game = new Game(map, options.TeamCount); } } @@ -305,7 +386,7 @@ namespace Server if (options.Url != DefaultArgumentOptions.Url && options.Token != DefaultArgumentOptions.Token) { //this.httpSender = new HttpSender(options.Url, options.Token, "PUT"); - }*/ + } } } } \ No newline at end of file diff --git a/logic/Server/Properties/launchSettings.json b/logic/Server/Properties/launchSettings.json new file mode 100644 index 0000000..4b6ecf3 --- /dev/null +++ b/logic/Server/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Server": { + "commandName": "Project", + "commandLineArgs": "-p 8888" + } + } +} \ No newline at end of file From 54f0dadb41815cabcf4db231664e56720274f672 Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Fri, 3 Mar 2023 23:57:34 +0800 Subject: [PATCH 2/9] feat: :rocket: update server --- logic/ClientTest/Program.cs | 16 ++++---- logic/Gaming/Game.cs | 1 + logic/Server/CopyInfo.cs | 52 +++++++++++++------------- logic/Server/GameServer.cs | 74 ++++++++++++------------------------- 4 files changed, 58 insertions(+), 85 deletions(-) diff --git a/logic/ClientTest/Program.cs b/logic/ClientTest/Program.cs index ed5751a..3d4cf80 100644 --- a/logic/ClientTest/Program.cs +++ b/logic/ClientTest/Program.cs @@ -12,24 +12,24 @@ namespace ClientTest var client = new AvailableService.AvailableServiceClient(channel); PlayerMsg playerInfo = new(); playerInfo.PlayerId = 0; - playerInfo.PlayerType = PlayerType.HumanPlayer; - playerInfo.HumanType = HumanType.NullHumanType; + playerInfo.PlayerType = PlayerType.StudentPlayer; + playerInfo.StudentType = StudentType.NullStudentType; var call = client.AddPlayer(playerInfo); while (await call.ResponseStream.MoveNext()) { var currentGameInfo = call.ResponseStream.Current; - if (playerInfo.PlayerType == PlayerType.HumanPlayer) + if (playerInfo.PlayerType == PlayerType.StudentPlayer) { - for (int i = 0; i < currentGameInfo.HumanMessage.Count; i++) + for (int i = 0; i < currentGameInfo.StudentMessage.Count; i++) { - Console.WriteLine($"Human is at ({currentGameInfo.HumanMessage[i].X}, {currentGameInfo.HumanMessage[i].Y})"); + Console.WriteLine($"Human is at ({currentGameInfo.StudentMessage[i].X}, {currentGameInfo.StudentMessage[i].Y})"); } } - if (playerInfo.PlayerType == PlayerType.ButcherPlayer) + if (playerInfo.PlayerType == PlayerType.TrickerPlayer) { - for (int i = 0; i < currentGameInfo.ButcherMessage.Count; i++) + for (int i = 0; i < currentGameInfo.TrickerMessage.Count; i++) { - Console.WriteLine($"Butcher is at ({currentGameInfo.ButcherMessage[i].X}, {currentGameInfo.ButcherMessage[i].Y})"); + Console.WriteLine($"Butcher is at ({currentGameInfo.TrickerMessage[i].X}, {currentGameInfo.TrickerMessage[i].Y})"); } } } diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index cf905e7..827cd90 100644 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -39,6 +39,7 @@ namespace Gaming XY pos = gameMap.BirthPointList[playerInitInfo.birthPointIndex]; // Console.WriteLine($"x,y: {pos.x},{pos.y}"); + Character newPlayer = (GameData.IsGhost(playerInitInfo.characterType)) ? new Ghost(pos, GameData.characterRadius, gameMap.GetPlaceType(pos), playerInitInfo.characterType) : new Student(pos, GameData.characterRadius, gameMap.GetPlaceType(pos), playerInitInfo.characterType); gameMap.GameObjLockDict[GameObjType.Character].EnterWriteLock(); try diff --git a/logic/Server/CopyInfo.cs b/logic/Server/CopyInfo.cs index 32516bc..cf82840 100644 --- a/logic/Server/CopyInfo.cs +++ b/logic/Server/CopyInfo.cs @@ -8,28 +8,28 @@ namespace Server public static class CopyInfo { // 下面赋值为0的大概率是还没写完 2023-03-03 - private static MessageOfHuman Human(Character player) + private static MessageOfStudent Human(Character player) { - MessageOfHuman msg = new MessageOfHuman(); + MessageOfStudent msg = new MessageOfStudent(); if (player.IsGhost()) return null; msg.X = player.Position.x; msg.Y = player.Position.y; msg.Speed = player.MoveSpeed; - msg.Life = player.HP; - msg.HangedTime = 0; + msg.Determination = player.HP; + msg.FailNum = 0; msg.TimeUntilSkillAvailable = 0; //msg.Place = 0; 下面写了 msg.Prop = PropType.NullPropType; // 下面写 - msg.HumanType = HumanType.NullHumanType; // 下面写 + msg.StudentType = StudentType.NullStudentType; // 下面写 msg.Guid = 0; - msg.State = HumanState.NullStatus; - msg.ChairTime = 0; - msg.GroundTime = 0; + msg.State = StudentState.NullStatus; + msg.FailTime = 0; + msg.EmoTime = 0; msg.PlayerId = 0; msg.ViewRange = 0; msg.Radius = 0; - //msg.Buff[0] = HumanBuffType.NullHbuffType; 下面写了 + //msg.Buff[0] = StudentBuffType.NullSbuffType; 下面写了 /* THUAI5中的内容 msg.BulletNum = player.BulletNum; @@ -60,26 +60,26 @@ namespace Server { if (kvp.Value) { - switch (kvp.Key) // HumanBuffType具体内容待定 + switch (kvp.Key) // StudentBuffType具体内容待定 { case Preparation.Utility.BuffType.Spear: - msg.Buff.Add(HumanBuffType.NullHbuffType); + msg.Buff.Add(StudentBuffType.NullSbuffType); break; case Preparation.Utility.BuffType.AddLIFE: - msg.Buff.Add(HumanBuffType.NullHbuffType); + msg.Buff.Add(StudentBuffType.NullSbuffType); break; case Preparation.Utility.BuffType.Shield: - msg.Buff.Add(HumanBuffType.NullHbuffType); + msg.Buff.Add(StudentBuffType.NullSbuffType); break; case Preparation.Utility.BuffType.AddSpeed: - msg.Buff.Add(HumanBuffType.NullHbuffType); + msg.Buff.Add(StudentBuffType.NullSbuffType); break; default: break; } } } - switch (player.Place) + /*switch (player.Place) { case Preparation.Utility.PlaceType.Land: msg.Place = PlaceType.Land; @@ -99,7 +99,7 @@ namespace Server default: msg.Place = PlaceType.NullPlaceType; break; - } + }*/ //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象 //现在懒得改了,有时间再重整一波 @@ -186,9 +186,9 @@ namespace Server return msg; } - private static MessageOfButcher Butcher(Character player) + private static MessageOfTricker Butcher(Character player) { - MessageOfButcher msg = new MessageOfButcher(); + MessageOfTricker msg = new MessageOfTricker(); if (!player.IsGhost()) return null; msg.X = player.Position.x; @@ -198,13 +198,13 @@ namespace Server msg.TimeUntilSkillAvailable = 0; //msg.Place = 0; 下面写了 msg.Prop = PropType.NullPropType; // 下面写 - msg.ButcherType = ButcherType.NullButcherType; // 下面写 + msg.TrickerType = TrickerType.NullTrickerType; // 下面写 msg.Guid = 0; msg.Movable = false; msg.PlayerId = 0; msg.ViewRange = 0; msg.Radius = 0; - //msg.Buff[0] = ButcherBuffType.NullHbuffType; 下面写了 + //msg.Buff[0] = ButcherBuffType.NullSbuffType; 下面写了 /* THUAI5中的内容 msg.BulletNum = player.BulletNum; @@ -238,23 +238,23 @@ namespace Server switch (kvp.Key) // ButcherBuffType具体内容待定 { case Preparation.Utility.BuffType.Spear: - msg.Buff.Add(ButcherBuffType.NullBbuffType); + msg.Buff.Add(TrickerBuffType.NullTbuffType); break; case Preparation.Utility.BuffType.AddLIFE: - msg.Buff.Add(ButcherBuffType.NullBbuffType); + msg.Buff.Add(TrickerBuffType.NullTbuffType); break; case Preparation.Utility.BuffType.Shield: - msg.Buff.Add(ButcherBuffType.NullBbuffType); + msg.Buff.Add(TrickerBuffType.NullTbuffType); break; case Preparation.Utility.BuffType.AddSpeed: - msg.Buff.Add(ButcherBuffType.NullBbuffType); + msg.Buff.Add(TrickerBuffType.NullTbuffType); break; default: break; } } } - switch (player.Place) + /*switch (player.Place) { case Preparation.Utility.PlaceType.Land: msg.Place = PlaceType.Land; @@ -274,7 +274,7 @@ namespace Server default: msg.Place = PlaceType.NullPlaceType; break; - } + }*/ //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象 //现在懒得改了,有时间再重整一波 diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index c48e082..a46966f 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -128,8 +128,8 @@ namespace Server private int PlayerTypeToTeamID(PlayerType playerType) { - if (playerType == PlayerType.HumanPlayer) return 0; - if (playerType == PlayerType.ButcherPlayer) return 1; + if (playerType == PlayerType.StudentPlayer) return 0; + if (playerType == PlayerType.TrickerPlayer) return 1; return -1; } private uint GetBirthPointIdx(PlayerType playerType, long playerID) // 获取出生点位置 @@ -138,9 +138,9 @@ namespace Server } private bool ValidPlayerTypeAndPlayerID(PlayerType playerType, long playerID) { - if (playerType == PlayerType.HumanPlayer && 0 <= playerID && playerID < options.PlayerCountPerTeam) + if (playerType == PlayerType.StudentPlayer && 0 <= playerID && playerID < options.PlayerCountPerTeam) return true; // 人数待修改 - if (playerType == PlayerType.ButcherPlayer && 0 <= playerID && playerID < options.PlayerCountPerTeam) + if (playerType == PlayerType.TrickerPlayer && 0 <= playerID && playerID < options.PlayerCountPerTeam) return true; return false; } @@ -185,7 +185,7 @@ namespace Server //if (communicationToGameID[PlayerTypeToTeamID(request.PlayerType), request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家 //return; - Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null; // 待修改 + Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Athlete; // 待修改 lock (addPlayerLock) { @@ -222,7 +222,7 @@ namespace Server } while (game.GameMap.Timer.IsGaming); } - public override Task Attack(AttackMsg request, ServerCallContext context) + public override Task Trick(TrickMsg request, ServerCallContext context) { game.Attack(request.PlayerId, request.Angle); BoolRes boolRes = new(); @@ -230,36 +230,11 @@ namespace Server return Task.FromResult(boolRes); } - public override Task CarryHuman(IDMsg request, ServerCallContext context) - { - return base.CarryHuman(request, context); - } - - public override Task EndFixMachine(IDMsg request, ServerCallContext context) - { - return base.EndFixMachine(request, context); - } - - public override Task EndSaveHuman(IDMsg request, ServerCallContext context) - { - return base.EndSaveHuman(request, context); - } - - public override Task Escape(IDMsg request, ServerCallContext context) - { - return base.Escape(request, context); - } - public override Task GetMessage(IDMsg request, IServerStreamWriter responseStream, ServerCallContext context) { return base.GetMessage(request, responseStream, context); } - public override Task HangHuman(IDMsg request, ServerCallContext context) - { - return base.HangHuman(request, context); - } - public override Task Move(MoveMsg request, ServerCallContext context) { Console.WriteLine($"Move ID: {request.PlayerId}, TimeInMilliseconds: {request.TimeInMilliseconds}"); @@ -278,34 +253,36 @@ namespace Server return Task.FromResult(boolRes); } - public override Task ReleaseHuman(IDMsg request, ServerCallContext context) - { - return base.ReleaseHuman(request, context); - } - public override Task SendMessage(SendMsg request, ServerCallContext context) { return base.SendMessage(request, context); - } + } - public override Task StartFixMachine(IDMsg request, ServerCallContext context) + public override Task UseProp(IDMsg request, ServerCallContext context) { - return base.StartFixMachine(request, context); + return base.UseProp(request, context); } - public override Task StartSaveHuman(IDMsg request, ServerCallContext context) + public override Task UseSkill(IDMsg request, ServerCallContext context) { - return base.StartSaveHuman(request, context); + return base.UseSkill(request, context); } - public override Task UseProp(IDMsg request, ServerCallContext context) + public override Task Graduate(IDMsg request, ServerCallContext context) { - return base.UseProp(request, context); + return base.Graduate(request, context); } - - public override Task UseSkill(IDMsg request, ServerCallContext context) + public override Task StartHealMate(IDMsg request, ServerCallContext context) { - return base.UseSkill(request, context); + return base.StartHealMate(request, context); + } + public override Task StartHelpMate(IDMsg request, ServerCallContext context) + { + return base.StartHelpMate(request, context); + } + public override Task StartLearning(IDMsg request, ServerCallContext context) + { + return base.StartLearning(request, context); } public GameServer(ArgumentOptions options) @@ -353,11 +330,6 @@ namespace Server catch { map = MapInfo.defaultMap; - map[0, 0] = 1; - map[2, 2] = 2; - map[4, 2] = 3; - map[6, 2] = 4; - map[8, 2] = 5; } finally { this.game = new Game(map, options.TeamCount); } } From e280f426a1111f31513fc46377924c6b23e56801 Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Sat, 4 Mar 2023 22:12:39 +0800 Subject: [PATCH 3/9] feat: :bug: update server --- logic/Gaming/Game.cs | 2 +- logic/Server/GameServer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index 827cd90..b63ecd0 100644 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -39,7 +39,7 @@ namespace Gaming XY pos = gameMap.BirthPointList[playerInitInfo.birthPointIndex]; // Console.WriteLine($"x,y: {pos.x},{pos.y}"); - + Character newPlayer = (GameData.IsGhost(playerInitInfo.characterType)) ? new Ghost(pos, GameData.characterRadius, gameMap.GetPlaceType(pos), playerInitInfo.characterType) : new Student(pos, GameData.characterRadius, gameMap.GetPlaceType(pos), playerInitInfo.characterType); gameMap.GameObjLockDict[GameObjType.Character].EnterWriteLock(); try diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index a46966f..1d18157 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -256,7 +256,7 @@ namespace Server public override Task SendMessage(SendMsg request, ServerCallContext context) { return base.SendMessage(request, context); - } + } public override Task UseProp(IDMsg request, ServerCallContext context) { From 78e79b1ea773607fe368687d01dfd92b0f354412 Mon Sep 17 00:00:00 2001 From: gsy1519 <108726816+gsy1519@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:57:26 +0800 Subject: [PATCH 4/9] Update logic/Server/Properties/launchSettings.json Co-authored-by: Timothy Liu --- logic/Server/Properties/launchSettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/Server/Properties/launchSettings.json b/logic/Server/Properties/launchSettings.json index 4b6ecf3..62a6702 100644 --- a/logic/Server/Properties/launchSettings.json +++ b/logic/Server/Properties/launchSettings.json @@ -5,4 +5,4 @@ "commandLineArgs": "-p 8888" } } -} \ No newline at end of file +} From ecb1f5216d14435a60bb76a83e7251fce1fea294 Mon Sep 17 00:00:00 2001 From: gsy1519 <108726816+gsy1519@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:09:56 +0800 Subject: [PATCH 5/9] Update logic/Server/GameServer.cs Co-authored-by: Timothy Liu --- logic/Server/GameServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index 1d18157..3a3079f 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -361,4 +361,4 @@ namespace Server } } } -} \ No newline at end of file +} From c94e3f5a7e32592b146021e1fe237503b49c17b0 Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Sat, 4 Mar 2023 22:50:04 +0800 Subject: [PATCH 6/9] feat: :zap: update server --- logic/GameClass/GameObj/Character/Character.Ghost.cs | 2 +- logic/GameClass/GameObj/Character/Character.Student.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/logic/GameClass/GameObj/Character/Character.Ghost.cs b/logic/GameClass/GameObj/Character/Character.Ghost.cs index e58d057..e1c1ded 100644 --- a/logic/GameClass/GameObj/Character/Character.Ghost.cs +++ b/logic/GameClass/GameObj/Character/Character.Ghost.cs @@ -11,7 +11,7 @@ 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) { diff --git a/logic/GameClass/GameObj/Character/Character.Student.cs b/logic/GameClass/GameObj/Character/Character.Student.cs index 6fc3306..ef1b796 100644 --- a/logic/GameClass/GameObj/Character/Character.Student.cs +++ b/logic/GameClass/GameObj/Character/Character.Student.cs @@ -101,7 +101,7 @@ 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) { From 8b5509723ad90f69adc3a234eedde5a8598dbf4b Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Sat, 4 Mar 2023 23:07:37 +0800 Subject: [PATCH 7/9] feat: :zap: update server --- .../GameObj/Character/Character.Ghost.cs | 10 +++++----- .../GameObj/Character/Character.SkillManager.cs | 4 ++-- .../GameObj/Character/Character.Student.cs | 17 +---------------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/logic/GameClass/GameObj/Character/Character.Ghost.cs b/logic/GameClass/GameObj/Character/Character.Ghost.cs index 309e419..11a7d80 100644 --- a/logic/GameClass/GameObj/Character/Character.Ghost.cs +++ b/logic/GameClass/GameObj/Character/Character.Ghost.cs @@ -7,12 +7,12 @@ using System.Numerics; using System.Runtime.InteropServices; using System.Threading; -namespace GameClass.GameObj -{ - public class Ghost : Character + namespace GameClass.GameObj { - public Ghost(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) + public class Ghost : Character { + public Ghost(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) + { + } } } -} diff --git a/logic/GameClass/GameObj/Character/Character.SkillManager.cs b/logic/GameClass/GameObj/Character/Character.SkillManager.cs index 942480c..bc6e7ad 100644 --- a/logic/GameClass/GameObj/Character/Character.SkillManager.cs +++ b/logic/GameClass/GameObj/Character/Character.SkillManager.cs @@ -59,7 +59,7 @@ namespace GameClass.GameObj }; } - public Character(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : + protected Character(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, GameObjType.Character) { this.CanMove = true; @@ -100,4 +100,4 @@ namespace GameClass.GameObj Debugger.Output(this, "constructed!"); } } -} +} \ No newline at end of file diff --git a/logic/GameClass/GameObj/Character/Character.Student.cs b/logic/GameClass/GameObj/Character/Character.Student.cs index b77770f..601ec5b 100644 --- a/logic/GameClass/GameObj/Character/Character.Student.cs +++ b/logic/GameClass/GameObj/Character/Character.Student.cs @@ -97,22 +97,7 @@ namespace GameClass.GameObj public Student(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) { - lock (gameObjLock) - IsResetting = true; - PlayerState = PlayerStateType.IsEscaped; - } - 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; } } -} +} \ No newline at end of file From aad91040cf83bf7d6fb1b57a9bbc295d40bf9e10 Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Sat, 4 Mar 2023 23:13:02 +0800 Subject: [PATCH 8/9] feat: :art: update server --- logic/Server/CopyInfo.cs | 19 +++++++++---------- logic/Server/GameServer.cs | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/logic/Server/CopyInfo.cs b/logic/Server/CopyInfo.cs index 0ede77f..e9e4003 100644 --- a/logic/Server/CopyInfo.cs +++ b/logic/Server/CopyInfo.cs @@ -20,7 +20,6 @@ namespace Server msg.FailNum = 0; msg.TimeUntilSkillAvailable = 0; //msg.Place = 0; 下面写了 - msg.Prop = PropType.NullPropType; // 下面写 msg.StudentType = StudentType.NullStudentType; // 下面写 msg.Guid = 0; msg.State = StudentState.NullStatus; @@ -103,7 +102,7 @@ namespace Server //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象 //现在懒得改了,有时间再重整一波 - if (player.PropInventory == null) + /*if (player.PropInventory == null) msg.Prop = PropType.NullPropType; else { @@ -112,7 +111,7 @@ namespace Server case Preparation.Utility.PropType.Gem: msg.Prop = PropType.NullPropType; break; - /*case Preparation.Utility.PropType.addLIFE: + case Preparation.Utility.PropType.addLIFE: msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife; break; case Preparation.Utility.PropType.addSpeed: @@ -123,12 +122,12 @@ namespace Server break; case Preparation.Utility.PropType.Spear: msg.MessageOfHuman.Prop = Communication.Proto.PropType.Spear; - break;*/ + break; default: msg.Prop = PropType.NullPropType; break; } - } + }*/ /*switch (player.PassiveSkillType) 需要对接一下,proto里似乎没有这个 { case Preparation.Utility.PassiveSkillType.RecoverAfterBattle: @@ -197,7 +196,7 @@ namespace Server msg.Damage = 0; msg.TimeUntilSkillAvailable = 0; //msg.Place = 0; 下面写了 - msg.Prop = PropType.NullPropType; // 下面写 + //msg.Prop = PropType.NullPropType; // 下面写 msg.TrickerType = TrickerType.NullTrickerType; // 下面写 msg.Guid = 0; msg.Movable = false; @@ -278,7 +277,7 @@ namespace Server //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象 //现在懒得改了,有时间再重整一波 - if (player.PropInventory == null) + /*if (player.PropInventory == null) msg.Prop = PropType.NullPropType; else { @@ -287,7 +286,7 @@ namespace Server case Preparation.Utility.PropType.Gem: msg.Prop = PropType.NullPropType; break; - /*case Preparation.Utility.PropType.addLIFE: + case Preparation.Utility.PropType.addLIFE: msg.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife; break; case Preparation.Utility.PropType.addSpeed: @@ -298,12 +297,12 @@ namespace Server break; case Preparation.Utility.PropType.Spear: msg.MessageOfHuman.Prop = Communication.Proto.PropType.Spear; - break;*/ + break; default: msg.Prop = PropType.NullPropType; break; } - } + }*/ /*switch (player.PassiveSkillType) 需要对接一下,proto里似乎没有这个 { case Preparation.Utility.PassiveSkillType.RecoverAfterBattle: diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index 3a3079f..83869d6 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -245,7 +245,7 @@ namespace Server return Task.FromResult(moveRes); } - public override Task PickProp(PickMsg request, ServerCallContext context) + public override Task PickProp(PropMsg request, ServerCallContext context) { BoolRes boolRes = new(); if (request.PropType == Protobuf.PropType.NullPropType) From 05875e1683e05577c661584d69c9721e4f53225c Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Sat, 4 Mar 2023 23:15:35 +0800 Subject: [PATCH 9/9] feat: :rocket: update server --- logic/GameClass/GameObj/Character/Character.Ghost.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/logic/GameClass/GameObj/Character/Character.Ghost.cs b/logic/GameClass/GameObj/Character/Character.Ghost.cs index 11a7d80..309e419 100644 --- a/logic/GameClass/GameObj/Character/Character.Ghost.cs +++ b/logic/GameClass/GameObj/Character/Character.Ghost.cs @@ -7,12 +7,12 @@ using System.Numerics; using System.Runtime.InteropServices; using System.Threading; - namespace GameClass.GameObj +namespace GameClass.GameObj +{ + public class Ghost : Character { - public class Ghost : Character + public Ghost(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) { - public Ghost(XY initPos, int initRadius, PlaceType initPlace, CharacterType characterType) : base(initPos, initRadius, initPlace, characterType) - { - } } } +}