From f2ae345cab50a1f9e2a33df6bf6e06f18bf1b4fc Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Sat, 18 Mar 2023 22:07:50 +0800 Subject: [PATCH] feat: :sparkles: Produce prop in chests --- logic/GameClass/GameObj/Prop.cs | 24 ++++- logic/Gaming/PropManager.cs | 124 +++++++++++++++++--------- logic/Preparation/Utility/EnumType.cs | 4 +- logic/Preparation/Utility/GameData.cs | 9 +- logic/规则Logic.md | 1 - 5 files changed, 113 insertions(+), 49 deletions(-) diff --git a/logic/GameClass/GameObj/Prop.cs b/logic/GameClass/GameObj/Prop.cs index 9e4fea2..d0724ca 100644 --- a/logic/GameClass/GameObj/Prop.cs +++ b/logic/GameClass/GameObj/Prop.cs @@ -5,9 +5,6 @@ namespace GameClass.GameObj { public abstract class Prop : ObjOfCharacter { - protected bool laid = false; - public bool Laid => laid; // 道具是否放置在地图上 - public override bool IsRigid => true; protected override bool IgnoreCollideExecutor(IGameObj targetObj) @@ -83,6 +80,27 @@ namespace GameClass.GameObj } public override PropType GetPropType() => PropType.Spear; } + public sealed class Key3 : Prop + { + public Key3(XY initPos, PlaceType placeType) : base(initPos, placeType) + { + } + public override PropType GetPropType() => PropType.Key3; + } + public sealed class Key5 : Prop + { + public Key5(XY initPos, PlaceType placeType) : base(initPos, placeType) + { + } + public override PropType GetPropType() => PropType.Key5; + } + public sealed class Key6 : Prop + { + public Key6(XY initPos, PlaceType placeType) : base(initPos, placeType) + { + } + public override PropType GetPropType() => PropType.Key6; + } #endregion // #region 所有坑人地雷 ///// diff --git a/logic/Gaming/PropManager.cs b/logic/Gaming/PropManager.cs index d84787a..987ca21 100644 --- a/logic/Gaming/PropManager.cs +++ b/logic/Gaming/PropManager.cs @@ -5,6 +5,8 @@ using Preparation.Utility; using System; using Timothy.FrameRateTask; using GameEngine; +using System.Numerics; +using System.Reflection; namespace Gaming { @@ -15,18 +17,9 @@ namespace Gaming { private readonly Map gameMap; - private MoveEngine moveEngine; - - private bool isProducingProp = false; + //private MoveEngine moveEngine; private readonly List availableCellForGenerateProp; - public void StartProducing() - { - if (isProducingProp) - return; - isProducingProp = true; - ProduceProp(); - } public void UseProp(Character player, int indexing) { @@ -129,10 +122,77 @@ namespace Gaming gameMap.Add(prop); } - private void ProduceProp() + private Prop ProduceOnePropNotKey(Random r, XY Pos) + { + switch (r.Next(0, GameData.numOfPropTypeNotKey)) + { + case 0: + return new AddLIFE(Pos, gameMap.GetPlaceType(Pos)); + case 1: + return new AddSpeed(Pos, gameMap.GetPlaceType(Pos)); + case 2: + return new Shield(Pos, gameMap.GetPlaceType(Pos)); + case 3: + return new Spear(Pos, gameMap.GetPlaceType(Pos)); + default: + return null; + } + } + + private Chest GetChest(Random r) + { + int index = r.Next(0, GameData.numOfChest); + while (((Chest)(gameMap.GameObjDict[GameObjType.Chest][index])).PropInChest[0] != null) index = (index + 1) % GameData.numOfChest; + return (Chest)(gameMap.GameObjDict[GameObjType.Chest][index]); + } + + public void StartProducing() { int len = availableCellForGenerateProp.Count; Random r = new Random(Environment.TickCount); + + gameMap.GameObjLockDict[GameObjType.Chest].EnterWriteLock(); + try + { + int cou = 0; + while (cou < GameData.numOfKeyEachArea) + { + ++cou; + Chest chest = GetChest(r); + chest.PropInChest[1] = new Key3(chest.Position, PlaceType.Chest); + chest.PropInChest[0] = ProduceOnePropNotKey(r, chest.Position); + } + cou = 0; + while (cou < GameData.numOfKeyEachArea) + { + ++cou; + Chest chest = GetChest(r); + chest.PropInChest[1] = new Key5(chest.Position, PlaceType.Chest); + chest.PropInChest[0] = ProduceOnePropNotKey(r, chest.Position); + } + cou = 0; + while (cou < GameData.numOfKeyEachArea) + { + ++cou; + Chest chest = GetChest(r); + chest.PropInChest[1] = new Key6(chest.Position, PlaceType.Chest); + chest.PropInChest[0] = ProduceOnePropNotKey(r, chest.Position); + } + + foreach (Chest chest in gameMap.GameObjDict[GameObjType.Chest]) + { + if (chest.PropInChest[0] == null) + { + chest.PropInChest[0] = ProduceOnePropNotKey(r, chest.Position); + chest.PropInChest[1] = ProduceOnePropNotKey(r, chest.Position); + } + } + } + finally + { + gameMap.GameObjLockDict[GameObjType.Chest].ExitWriteLock(); + } + new Thread ( () => @@ -145,25 +205,7 @@ namespace Gaming { int rand = r.Next(0, len); XY randPos = availableCellForGenerateProp[rand]; - - - switch (r.Next(0, 4)) - { - case 0: - gameMap.Add(new AddLIFE(randPos, gameMap.GetPlaceType(randPos))); - break; - case 1: - gameMap.Add(new AddSpeed(randPos, gameMap.GetPlaceType(randPos))); - break; - case 2: - gameMap.Add(new Shield(randPos, gameMap.GetPlaceType(randPos))); - break; - case 3: - gameMap.Add(new Spear(randPos, gameMap.GetPlaceType(randPos))); - break; - default: - break; - } + gameMap.Add(ProduceOnePropNotKey(r, randPos)); }, GameData.PropProduceTime, () => 0 @@ -176,17 +218,17 @@ namespace Gaming public PropManager(Map gameMap) // 道具不能扔过墙 { this.gameMap = gameMap; - this.moveEngine = new MoveEngine( - gameMap: gameMap, - OnCollision: (obj, collision, moveVec) => - { return MoveEngine.AfterCollision.MoveMax; }, - EndMove: obj => - { - // obj.Place = gameMap.GetPlaceType((GameObj)obj); - obj.CanMove = false; - Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); - } - ); + /* this.moveEngine = new MoveEngine( + gameMap: gameMap, + OnCollision: (obj, collision, moveVec) => + { return MoveEngine.AfterCollision.MoveMax; }, + EndMove: obj => + { + // obj.Place = gameMap.GetPlaceType((GameObj)obj); + obj.CanMove = false; + Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); + } + );*/ availableCellForGenerateProp = new List(); for (int i = 0; i < gameMap.protoGameMap.GetLength(0); i++) { diff --git a/logic/Preparation/Utility/EnumType.cs b/logic/Preparation/Utility/EnumType.cs index 5247c50..3bcb845 100644 --- a/logic/Preparation/Utility/EnumType.cs +++ b/logic/Preparation/Utility/EnumType.cs @@ -67,7 +67,9 @@ namespace Preparation.Utility addLIFE = 2, Shield = 3, Spear = 4, - Gem = 5, // 新增:宝石 + Key3 = 5, + Key5 = 6, + Key6 = 7, } public enum CharacterType // 职业 { diff --git a/logic/Preparation/Utility/GameData.cs b/logic/Preparation/Utility/GameData.cs index b1e5b2b..a4eed21 100644 --- a/logic/Preparation/Utility/GameData.cs +++ b/logic/Preparation/Utility/GameData.cs @@ -1,6 +1,4 @@ using System; -using System.Reflection.Metadata.Ecma335; -using System.Threading; namespace Preparation.Utility { @@ -22,12 +20,14 @@ namespace Preparation.Utility public const int numOfBirthPoint = 5; // public const int numOfGenerator = 9; public const int numOfGeneratorRequiredForRepair = 7; + public const int numOfChest = 8; private const int numOfObjNotMap = 5; public static bool IsMap(GameObjType gameObjType) { return (uint)gameObjType > numOfObjNotMap; } + public static XY GetCellCenterPos(int x, int y) // 求格子的中心坐标 { XY ret = new(x * numOfPosGridPerCell + numOfPosGridPerCell / 2, y * numOfPosGridPerCell + numOfPosGridPerCell / 2); @@ -118,9 +118,12 @@ namespace Preparation.Utility public const int PropRadius = numOfPosGridPerCell / 2; public const int PropMoveSpeed = 3000; public const int PropMaxMoveDistance = 15 * numOfPosGridPerCell; - public const long GemProduceTime = 10000; public const long PropProduceTime = 10000; public const int PropDuration = 10000; + + public const int numOfKeyEachArea = 2; + public const int numOfPropTypeNotKey = 4; + public const int numOfTeachingBuilding = 3; #endregion #region 物体相关 public const int degreeOfFixedGenerator = 10300000; diff --git a/logic/规则Logic.md b/logic/规则Logic.md index aa881fb..a6aef48 100644 --- a/logic/规则Logic.md +++ b/logic/规则Logic.md @@ -160,7 +160,6 @@ - 子弹类型 ### 道具:所有物 -- 是否放置地图上 - 道具类型 ### 被捡起的道具:物体