diff --git a/logic/GameClass/GameObj/Bullet/Bullet.cs b/logic/GameClass/GameObj/Bullet/Bullet.cs index 2670f47..cb0fcce 100644 --- a/logic/GameClass/GameObj/Bullet/Bullet.cs +++ b/logic/GameClass/GameObj/Bullet/Bullet.cs @@ -35,7 +35,7 @@ namespace GameClass.GameObj public override bool IgnoreCollideExecutor(IGameObj targetObj) { if (targetObj == Parent) return true; - if (targetObj.Type == GameObjType.Prop || targetObj.Type == GameObjType.Bullet) + if (targetObj.Type == GameObjType.Consumables || targetObj.Type == GameObjType.Bullet) return true; return false; } diff --git a/logic/GameClass/GameObj/Character/Character.cs b/logic/GameClass/GameObj/Character/Character.cs index 3e8622c..5c2acdf 100644 --- a/logic/GameClass/GameObj/Character/Character.cs +++ b/logic/GameClass/GameObj/Character/Character.cs @@ -257,6 +257,7 @@ namespace GameClass.GameObj try { maxHp = value; + if (hp > maxHp) hp = maxHp; } finally { @@ -286,7 +287,7 @@ namespace GameClass.GameObj { if (value > 0) { - hp = value <= MaxHp ? value : MaxHp; + hp = value <= maxHp ? value : maxHp; } else hp = 0; @@ -302,7 +303,6 @@ namespace GameClass.GameObj /// 尝试减血 /// /// 减血量 - /// 减操作是否成功 public int TrySubHp(int sub) { HPReadWriterLock.EnterWriteLock(); @@ -359,7 +359,6 @@ namespace GameClass.GameObj } } } - private double oriVampire = 0; public double OriVampire { get; protected set; } #endregion #region 状态相关的基本属性与方法 @@ -597,9 +596,9 @@ namespace GameClass.GameObj } #region 道具和buff相关属性、方法 - private Prop[] propInventory = new Prop[GameData.maxNumOfPropInPropInventory] + private Consumables[] propInventory = new Consumables[GameData.maxNumOfPropInPropInventory] {new NullProp(), new NullProp(),new NullProp() }; - public Prop[] PropInventory + public Consumables[] PropInventory { get => propInventory; set @@ -616,19 +615,19 @@ namespace GameClass.GameObj /// 使用物品栏中的道具 /// /// 被使用的道具 - public Prop UseProp(int indexing) + public Consumables UseProp(int indexing) { if (indexing < 0 || indexing >= GameData.maxNumOfPropInPropInventory) return new NullProp(); lock (gameObjLock) { - Prop prop = propInventory[indexing]; + Consumables prop = propInventory[indexing]; PropInventory[indexing] = new NullProp(); return prop; } } - public Prop UseProp(PropType propType) + public Consumables UseProp(PropType propType) { lock (gameObjLock) { @@ -638,7 +637,7 @@ namespace GameClass.GameObj { if (PropInventory[indexing].GetPropType() != PropType.Null) { - Prop prop = PropInventory[indexing]; + Consumables prop = PropInventory[indexing]; PropInventory[indexing] = new NullProp(); return prop; } @@ -649,7 +648,7 @@ namespace GameClass.GameObj { if (PropInventory[indexing].GetPropType() == propType) { - Prop prop = PropInventory[indexing]; + Consumables prop = PropInventory[indexing]; PropInventory[indexing] = new NullProp(); return prop; } @@ -788,7 +787,7 @@ namespace GameClass.GameObj { if (IsRemoved) return true; - if (targetObj.Type == GameObjType.Prop) + if (targetObj.Type == GameObjType.Consumables) { return true; } diff --git a/logic/GameClass/GameObj/Map/Chest.cs b/logic/GameClass/GameObj/Map/Chest.cs index 41e51db..0e3d480 100644 --- a/logic/GameClass/GameObj/Map/Chest.cs +++ b/logic/GameClass/GameObj/Map/Chest.cs @@ -15,8 +15,8 @@ namespace GameClass.GameObj public override bool IsRigid => true; public override ShapeType Shape => ShapeType.Square; - private readonly Prop[] propInChest = new Prop[GameData.maxNumOfPropInChest] { new NullProp(), new NullProp() }; - public Prop[] PropInChest => propInChest; + private readonly Consumables[] propInChest = new Consumables[GameData.maxNumOfPropInChest] { new NullProp(), new NullProp() }; + public Consumables[] PropInChest => propInChest; private int openStartTime = 0; public int OpenStartTime => openStartTime; diff --git a/logic/GameClass/GameObj/Prop.cs b/logic/GameClass/GameObj/Prop/Consumables.cs similarity index 75% rename from logic/GameClass/GameObj/Prop.cs rename to logic/GameClass/GameObj/Prop/Consumables.cs index 363724f..df31131 100644 --- a/logic/GameClass/GameObj/Prop.cs +++ b/logic/GameClass/GameObj/Prop/Consumables.cs @@ -3,13 +3,13 @@ using Preparation.Utility; namespace GameClass.GameObj { - public abstract class Prop : ObjOfCharacter + public abstract class Consumables : ObjOfCharacter { public override bool IsRigid => true; public override bool IgnoreCollideExecutor(IGameObj targetObj) { - if (targetObj.Type == GameObjType.Prop || targetObj.Type == GameObjType.Bullet + if (targetObj.Type == GameObjType.Consumables || targetObj.Type == GameObjType.Bullet || targetObj.Type == GameObjType.Character || targetObj.Type == GameObjType.Chest) return true; return false; @@ -19,8 +19,8 @@ namespace GameClass.GameObj public abstract PropType GetPropType(); - public Prop(XY initPos, int radius = GameData.PropRadius) : - base(initPos, radius, GameObjType.Prop) + public Consumables(XY initPos, int radius = GameData.PropRadius) : + base(initPos, radius, GameObjType.Consumables) { this.canMove = false; this.MoveSpeed = GameData.PropMoveSpeed; @@ -31,32 +31,16 @@ namespace GameClass.GameObj ///// ///// 坑人地雷 ///// - // public abstract class DebuffMine : Prop + // public abstract class DebuffMine : Consumables //{ // public DebuffMine(XYPosition initPos) : base(initPos) { } // } - public sealed class CraftingBench : Prop - { - public override bool IsRigid => true; - public override bool IgnoreCollideExecutor(IGameObj targetObj) => false; - public CraftingBench(XY initPos) : - base(initPos) - { - } - public override PropType GetPropType() => PropType.CraftingBench; - } - - public abstract class BuffProp : Prop - { - public BuffProp(XY initPos) : base(initPos) { } - } - #region 所有增益道具 /// /// 增加速度 /// - public sealed class AddSpeed : BuffProp + public sealed class AddSpeed : Consumables { public AddSpeed(XY initPos) : base(initPos) @@ -68,7 +52,7 @@ namespace GameClass.GameObj /// /// 复活甲 /// - public sealed class AddLifeOrClairaudience : BuffProp + public sealed class AddLifeOrClairaudience : Consumables { public AddLifeOrClairaudience(XY initPos) : base(initPos) @@ -76,7 +60,7 @@ namespace GameClass.GameObj } public override PropType GetPropType() => PropType.AddLifeOrClairaudience; } - public sealed class AddHpOrAp : BuffProp + public sealed class AddHpOrAp : Consumables { public AddHpOrAp(XY initPos) : base(initPos) @@ -84,7 +68,7 @@ namespace GameClass.GameObj } public override PropType GetPropType() => PropType.AddHpOrAp; } - public sealed class RecoveryFromDizziness : BuffProp + public sealed class RecoveryFromDizziness : Consumables { public RecoveryFromDizziness(XY initPos) : base(initPos) @@ -95,35 +79,35 @@ namespace GameClass.GameObj /// /// 矛盾 /// - public sealed class ShieldOrSpear : BuffProp + public sealed class ShieldOrSpear : Consumables { public ShieldOrSpear(XY initPos) : base(initPos) { } public override PropType GetPropType() => PropType.ShieldOrSpear; } - public sealed class Key3 : BuffProp + public sealed class Key3 : Consumables { public Key3(XY initPos) : base(initPos) { } public override PropType GetPropType() => PropType.Key3; } - public sealed class Key5 : BuffProp + public sealed class Key5 : Consumables { public Key5(XY initPos) : base(initPos) { } public override PropType GetPropType() => PropType.Key5; } - public sealed class Key6 : BuffProp + public sealed class Key6 : Consumables { public Key6(XY initPos) : base(initPos) { } public override PropType GetPropType() => PropType.Key6; } - public sealed class NullProp : Prop + public sealed class NullProp : Consumables { public NullProp() : base(new XY(1, 1)) { @@ -159,12 +143,10 @@ namespace GameClass.GameObj // #endregion public static class PropFactory { - public static Prop GetProp(PropType propType, XY pos) + public static Consumables GetConsumables(PropType propType, XY pos) { switch (propType) { - case PropType.CraftingBench: - return new CraftingBench(pos); case PropType.AddSpeed: return new AddSpeed(pos); case PropType.AddLifeOrClairaudience: diff --git a/logic/GameClass/GameObj/PickedProp.cs b/logic/GameClass/GameObj/Prop/PickedProp.cs similarity index 68% rename from logic/GameClass/GameObj/PickedProp.cs rename to logic/GameClass/GameObj/Prop/PickedProp.cs index c924c82..3f100cf 100644 --- a/logic/GameClass/GameObj/PickedProp.cs +++ b/logic/GameClass/GameObj/Prop/PickedProp.cs @@ -3,17 +3,18 @@ using System; namespace GameClass.GameObj { // 为方便界面组做道具拾起特效,现引入“被捡起的道具”,在每帧发送给界面组 - public class PickedProp : Immovable + /* + public class Prop : Immovable { public override ShapeType Shape => ShapeType.Circle; public override bool IsRigid => false; public long MappingID { get; } - public readonly Prop propHasPicked; - public PickedProp(Prop prop) : - base(prop.Position, prop.Radius, GameObjType.PickedProp) + public readonly Consumables propHasPicked; + public Prop(Consumables prop) : + base(prop.Position, prop.Radius, GameObjType.Prop) { this.propHasPicked = prop; this.MappingID = prop.ID; } - } + }*/ } diff --git a/logic/GameClass/GameObj/Prop/Prop.cs b/logic/GameClass/GameObj/Prop/Prop.cs new file mode 100644 index 0000000..7071974 --- /dev/null +++ b/logic/GameClass/GameObj/Prop/Prop.cs @@ -0,0 +1,68 @@ +using Preparation.Interface; +using Preparation.Utility; + +namespace GameClass.GameObj +{ + public abstract class Prop : ObjOfCharacter + { + public override bool IsRigid => true; + + public override bool IgnoreCollideExecutor(IGameObj targetObj) => false; + + public override ShapeType Shape => ShapeType.Square; + + public abstract PropType GetPropType(); + + public Prop(XY initPos, int radius = GameData.PropRadius) : + base(initPos, radius, GameObjType.Prop) + { + this.canMove = false; + this.MoveSpeed = GameData.PropMoveSpeed; + } + } + + + ///// + ///// 坑人地雷 + ///// + // public abstract class DebuffMine : Consumables + //{ + // public DebuffMine(XYPosition initPos) : base(initPos) { } + // } + + public sealed class CraftingBench : Prop + { + public CraftingBench(XY initPos) : + base(initPos) + { + } + public override PropType GetPropType() => PropType.CraftingBench; + } + + // #region 所有坑人地雷 + ///// + ///// 减速 + ///// + // public sealed class MinusSpeed : DebuffMine + //{ + // public MinusSpeed(XYPosition initPos) : base(initPos) { } + // public override PropType GetPropType() => PropType.minusSpeed; + // } + ///// + ///// 减少攻击力 + ///// + // public sealed class MinusAP : DebuffMine + //{ + // public MinusAP(XYPosition initPos) : base(initPos) { } + // public override PropType GetPropType() => PropType.minusAP; + // } + ///// + ///// 增加冷却 + ///// + // public sealed class AddCD : DebuffMine + //{ + // public AddCD(XYPosition initPos) : base(initPos) { } + // public override PropType GetPropType() => PropType.addCD; + // } + // #endregion +} \ No newline at end of file diff --git a/logic/Gaming/ActionManager.cs b/logic/Gaming/ActionManager.cs index bbec6e2..5984106 100644 --- a/logic/Gaming/ActionManager.cs +++ b/logic/Gaming/ActionManager.cs @@ -303,7 +303,7 @@ namespace Gaming player.SetPlayerStateNaturally(); for (int i = 0; i < GameData.maxNumOfPropInChest; ++i) { - Prop prop = chestToOpen.PropInChest[i]; + Consumables prop = chestToOpen.PropInChest[i]; chestToOpen.PropInChest[i] = new NullProp(); prop.ReSetPos(player.Position); gameMap.Add(prop); @@ -395,7 +395,7 @@ namespace Gaming Door? doorToLock = (Door?)gameMap.OneForInteract(player.Position, GameObjType.Door); if (doorToLock == null) return false; bool flag = false; - foreach (Prop prop in player.PropInventory) + foreach (Consumables prop in player.PropInventory) { switch (prop.GetPropType()) { diff --git a/logic/Gaming/CharacterManager.cs b/logic/Gaming/CharacterManager.cs index 0645f1d..6f4d5fa 100644 --- a/logic/Gaming/CharacterManager.cs +++ b/logic/Gaming/CharacterManager.cs @@ -370,7 +370,7 @@ namespace Gaming for (int i = 0; i < GameData.maxNumOfPropInPropInventory; i++) { - Prop? prop = player.UseProp(i); + Consumables? prop = player.UseProp(i); if (prop != null) { prop.ReSetPos(player.Position); diff --git a/logic/Gaming/PropManager.cs b/logic/Gaming/PropManager.cs index 5079a73..01bea89 100644 --- a/logic/Gaming/PropManager.cs +++ b/logic/Gaming/PropManager.cs @@ -23,7 +23,7 @@ namespace Gaming { if (player.IsRemoved || player.CharacterType == CharacterType.Robot) return; - Prop prop = player.UseProp(propType); + Consumables prop = player.UseProp(propType); switch (prop.GetPropType()) { case PropType.ShieldOrSpear: @@ -79,17 +79,17 @@ namespace Gaming if (indexing == GameData.maxNumOfPropInPropInventory) return false; - Prop pickProp = new NullProp(); + Consumables pickProp = new NullProp(); if (propType == PropType.Null) // 自动检查有无道具可捡 { - pickProp = player.PropInventory[indexing] = ((Prop?)gameMap.OneInTheSameCell(player.Position, GameObjType.Prop)) ?? new NullProp(); + pickProp = player.PropInventory[indexing] = ((Consumables?)gameMap.OneInTheSameCell(player.Position, GameObjType.Consumables)) ?? new NullProp(); } else { - gameMap.GameObjLockDict[GameObjType.Prop].EnterReadLock(); + gameMap.GameObjLockDict[GameObjType.Consumables].EnterReadLock(); try { - foreach (Prop prop in gameMap.GameObjDict[GameObjType.Prop]) + foreach (Consumables prop in gameMap.GameObjDict[GameObjType.Consumables]) { if (prop.GetPropType() == propType) { @@ -102,14 +102,14 @@ namespace Gaming } finally { - gameMap.GameObjLockDict[GameObjType.Prop].ExitReadLock(); + gameMap.GameObjLockDict[GameObjType.Consumables].ExitReadLock(); } } if (pickProp.GetPropType() != PropType.Null) { gameMap.Remove(pickProp); - gameMap.Add(new PickedProp(pickProp)); + //gameMap.Add(new Prop(pickProp)); return true; } else @@ -120,7 +120,7 @@ namespace Gaming { if (!gameMap.Timer.IsGaming || player.IsRemoved) return; - Prop prop = player.UseProp(propType); + Consumables prop = player.UseProp(propType); if (prop.GetPropType() == PropType.Null) return; @@ -128,9 +128,9 @@ namespace Gaming gameMap.Add(prop); } - private static Prop ProduceOnePropNotKey(Random r, XY Pos) + private static Consumables ProduceOnePropNotKey(Random r, XY Pos) { - return PropFactory.GetProp((PropType)r.Next(GameData.numOfTeachingBuilding + 1, GameData.numOfPropSpecies + 1), Pos); + return PropFactory.GetConsumables((PropType)r.Next(GameData.numOfTeachingBuilding + 1, GameData.numOfPropSpecies + 1), Pos); } private Chest GetChest(Random r) diff --git a/logic/Preparation/Utility/EnumType.cs b/logic/Preparation/Utility/EnumType.cs index 8292b29..8e81850 100644 --- a/logic/Preparation/Utility/EnumType.cs +++ b/logic/Preparation/Utility/EnumType.cs @@ -30,8 +30,8 @@ namespace Preparation.Utility { Null = 0, Character = 1, - Prop = 2, - PickedProp = 3, + Consumables = 2, + Prop = 3, Bullet = 4, BombedBullet = 5, diff --git a/logic/Preparation/Utility/GameData.cs b/logic/Preparation/Utility/GameData.cs index 63f37d4..fb4d1bd 100644 --- a/logic/Preparation/Utility/GameData.cs +++ b/logic/Preparation/Utility/GameData.cs @@ -45,8 +45,8 @@ namespace Preparation.Utility { return gameObjType != GameObjType.Null && gameObjType != GameObjType.Grass && gameObjType != GameObjType.OutOfBoundBlock && gameObjType != GameObjType.Window - && gameObjType != GameObjType.Bullet&&gameObjType != GameObjType.Prop - &&gameObjType != GameObjType.PickedProp&&gameObjType != GameObjType.BombedBullet + && gameObjType != GameObjType.Bullet&&gameObjType != GameObjType.Consumables + &&gameObjType != GameObjType.Prop&&gameObjType != GameObjType.BombedBullet &&gameObjType != GameObjType.EmergencyExit&&gameObjType != GameObjType.Doorway; }*/ diff --git a/logic/Server/CopyInfo.cs b/logic/Server/CopyInfo.cs index 2cd8dae..651cad2 100644 --- a/logic/Server/CopyInfo.cs +++ b/logic/Server/CopyInfo.cs @@ -19,12 +19,8 @@ namespace Server else return Student((Student)character); case Preparation.Utility.GameObjType.Bullet: return Bullet((Bullet)gameObj); - case Preparation.Utility.GameObjType.Prop: - return Prop((Prop)gameObj); case Preparation.Utility.GameObjType.BombedBullet: return BombedBullet((BombedBullet)gameObj); - case Preparation.Utility.GameObjType.PickedProp: - return PickedProp((PickedProp)gameObj); case Preparation.Utility.GameObjType.Generator: return Classroom((Generator)gameObj); case Preparation.Utility.GameObjType.Chest: @@ -37,6 +33,10 @@ namespace Server else return null; case Preparation.Utility.GameObjType.Door: return Door((Door)gameObj); + case GameObjType.Prop: + return Prop((Prop)gameObj); + case Preparation.Utility.GameObjType.Consumables: + return Prop((Consumables)gameObj); default: return null; } } @@ -157,6 +157,22 @@ namespace Server return msg; } + private static MessageOfObj Prop(Consumables prop) + { + MessageOfObj msg = new() + { + PropMessage = new() + { + Type = Transformation.ToPropType(prop.GetPropType()), + X = prop.Position.x, + Y = prop.Position.y, + FacingDirection = prop.FacingDirection.Angle(), + Guid = prop.ID + } + }; + return msg; + } + private static MessageOfObj Prop(Prop prop) { MessageOfObj msg = new() @@ -191,18 +207,6 @@ namespace Server return msg; } - private static MessageOfObj PickedProp(PickedProp pickedProp) - { - MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp - /*msg.MessageOfPickedProp = new MessageOfPickedProp(); - - msg.MessageOfPickedProp.MappingID = pickedProp.MappingID; - msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x; - msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y; - msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;*/ - return msg; - } - private static MessageOfObj Classroom(Generator generator) { MessageOfObj msg = new()