Browse Source

feat: Produce prop in chests

tags/0.1.0
shangfengh 2 years ago
parent
commit
f2ae345cab
5 changed files with 113 additions and 49 deletions
  1. +21
    -3
      logic/GameClass/GameObj/Prop.cs
  2. +83
    -41
      logic/Gaming/PropManager.cs
  3. +3
    -1
      logic/Preparation/Utility/EnumType.cs
  4. +6
    -3
      logic/Preparation/Utility/GameData.cs
  5. +0
    -1
      logic/规则Logic.md

+ 21
- 3
logic/GameClass/GameObj/Prop.cs View File

@@ -5,9 +5,6 @@ namespace GameClass.GameObj
{ {
public abstract class Prop : ObjOfCharacter public abstract class Prop : ObjOfCharacter
{ {
protected bool laid = false;
public bool Laid => laid; // 道具是否放置在地图上

public override bool IsRigid => true; public override bool IsRigid => true;


protected override bool IgnoreCollideExecutor(IGameObj targetObj) protected override bool IgnoreCollideExecutor(IGameObj targetObj)
@@ -83,6 +80,27 @@ namespace GameClass.GameObj
} }
public override PropType GetPropType() => PropType.Spear; 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 #endregion
// #region 所有坑人地雷 // #region 所有坑人地雷
///// <summary> ///// <summary>


+ 83
- 41
logic/Gaming/PropManager.cs View File

@@ -5,6 +5,8 @@ using Preparation.Utility;
using System; using System;
using Timothy.FrameRateTask; using Timothy.FrameRateTask;
using GameEngine; using GameEngine;
using System.Numerics;
using System.Reflection;


namespace Gaming namespace Gaming
{ {
@@ -15,18 +17,9 @@ namespace Gaming
{ {
private readonly Map gameMap; private readonly Map gameMap;


private MoveEngine moveEngine;

private bool isProducingProp = false;
//private MoveEngine moveEngine;


private readonly List<XY> availableCellForGenerateProp; private readonly List<XY> availableCellForGenerateProp;
public void StartProducing()
{
if (isProducingProp)
return;
isProducingProp = true;
ProduceProp();
}


public void UseProp(Character player, int indexing) public void UseProp(Character player, int indexing)
{ {
@@ -129,10 +122,77 @@ namespace Gaming
gameMap.Add(prop); 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; int len = availableCellForGenerateProp.Count;
Random r = new Random(Environment.TickCount); 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 new Thread
( (
() => () =>
@@ -145,25 +205,7 @@ namespace Gaming
{ {
int rand = r.Next(0, len); int rand = r.Next(0, len);
XY randPos = availableCellForGenerateProp[rand]; 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, GameData.PropProduceTime,
() => 0 () => 0
@@ -176,17 +218,17 @@ namespace Gaming
public PropManager(Map gameMap) // 道具不能扔过墙 public PropManager(Map gameMap) // 道具不能扔过墙
{ {
this.gameMap = 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<XY>(); availableCellForGenerateProp = new List<XY>();
for (int i = 0; i < gameMap.protoGameMap.GetLength(0); i++) for (int i = 0; i < gameMap.protoGameMap.GetLength(0); i++)
{ {


+ 3
- 1
logic/Preparation/Utility/EnumType.cs View File

@@ -67,7 +67,9 @@ namespace Preparation.Utility
addLIFE = 2, addLIFE = 2,
Shield = 3, Shield = 3,
Spear = 4, Spear = 4,
Gem = 5, // 新增:宝石
Key3 = 5,
Key5 = 6,
Key6 = 7,
} }
public enum CharacterType // 职业 public enum CharacterType // 职业
{ {


+ 6
- 3
logic/Preparation/Utility/GameData.cs View File

@@ -1,6 +1,4 @@
using System; using System;
using System.Reflection.Metadata.Ecma335;
using System.Threading;


namespace Preparation.Utility namespace Preparation.Utility
{ {
@@ -22,12 +20,14 @@ namespace Preparation.Utility
public const int numOfBirthPoint = 5; public const int numOfBirthPoint = 5;
// public const int numOfGenerator = 9; // public const int numOfGenerator = 9;
public const int numOfGeneratorRequiredForRepair = 7; public const int numOfGeneratorRequiredForRepair = 7;
public const int numOfChest = 8;


private const int numOfObjNotMap = 5; private const int numOfObjNotMap = 5;
public static bool IsMap(GameObjType gameObjType) public static bool IsMap(GameObjType gameObjType)
{ {
return (uint)gameObjType > numOfObjNotMap; return (uint)gameObjType > numOfObjNotMap;
} }

public static XY GetCellCenterPos(int x, int y) // 求格子的中心坐标 public static XY GetCellCenterPos(int x, int y) // 求格子的中心坐标
{ {
XY ret = new(x * numOfPosGridPerCell + numOfPosGridPerCell / 2, y * numOfPosGridPerCell + numOfPosGridPerCell / 2); 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 PropRadius = numOfPosGridPerCell / 2;
public const int PropMoveSpeed = 3000; public const int PropMoveSpeed = 3000;
public const int PropMaxMoveDistance = 15 * numOfPosGridPerCell; public const int PropMaxMoveDistance = 15 * numOfPosGridPerCell;
public const long GemProduceTime = 10000;
public const long PropProduceTime = 10000; public const long PropProduceTime = 10000;
public const int PropDuration = 10000; public const int PropDuration = 10000;

public const int numOfKeyEachArea = 2;
public const int numOfPropTypeNotKey = 4;
public const int numOfTeachingBuilding = 3;
#endregion #endregion
#region 物体相关 #region 物体相关
public const int degreeOfFixedGenerator = 10300000; public const int degreeOfFixedGenerator = 10300000;


+ 0
- 1
logic/规则Logic.md View File

@@ -160,7 +160,6 @@
- 子弹类型 - 子弹类型


### 道具:所有物 ### 道具:所有物
- 是否放置地图上
- 道具类型 - 道具类型


### 被捡起的道具:物体 ### 被捡起的道具:物体


Loading…
Cancel
Save