Browse Source

Merge pull request #543 from shangfengh/new

feat:  add craftingBench and change Prop to consumables
tags/v0.1.0
Shawqeem GitHub 2 years ago
parent
commit
b4fcba3748
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 139 additions and 85 deletions
  1. +1
    -1
      logic/GameClass/GameObj/Bullet/Bullet.cs
  2. +10
    -11
      logic/GameClass/GameObj/Character/Character.cs
  3. +2
    -2
      logic/GameClass/GameObj/Map/Chest.cs
  4. +15
    -33
      logic/GameClass/GameObj/Prop/Consumables.cs
  5. +6
    -5
      logic/GameClass/GameObj/Prop/PickedProp.cs
  6. +68
    -0
      logic/GameClass/GameObj/Prop/Prop.cs
  7. +2
    -2
      logic/Gaming/ActionManager.cs
  8. +1
    -1
      logic/Gaming/CharacterManager.cs
  9. +10
    -10
      logic/Gaming/PropManager.cs
  10. +2
    -2
      logic/Preparation/Utility/EnumType.cs
  11. +2
    -2
      logic/Preparation/Utility/GameData.cs
  12. +20
    -16
      logic/Server/CopyInfo.cs

+ 1
- 1
logic/GameClass/GameObj/Bullet/Bullet.cs View File

@@ -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;
}


+ 10
- 11
logic/GameClass/GameObj/Character/Character.cs View File

@@ -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
/// 尝试减血
/// </summary>
/// <param name="sub">减血量</param>
/// <returns>减操作是否成功</returns>
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
/// 使用物品栏中的道具
/// </summary>
/// <returns>被使用的道具</returns>
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;
}


+ 2
- 2
logic/GameClass/GameObj/Map/Chest.cs View File

@@ -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;


logic/GameClass/GameObj/Prop.cs → logic/GameClass/GameObj/Prop/Consumables.cs View File

@@ -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
///// <summary>
///// 坑人地雷
///// </summary>
// 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 所有增益道具
/// <summary>
/// 增加速度
/// </summary>
public sealed class AddSpeed : BuffProp
public sealed class AddSpeed : Consumables
{
public AddSpeed(XY initPos) :
base(initPos)
@@ -68,7 +52,7 @@ namespace GameClass.GameObj
/// <summary>
/// 复活甲
/// </summary>
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
/// <summary>
/// 矛盾
/// </summary>
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:

logic/GameClass/GameObj/PickedProp.cs → logic/GameClass/GameObj/Prop/PickedProp.cs View File

@@ -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;
}
}
}*/
}

+ 68
- 0
logic/GameClass/GameObj/Prop/Prop.cs View File

@@ -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;
}
}


///// <summary>
///// 坑人地雷
///// </summary>
// 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 所有坑人地雷
///// <summary>
///// 减速
///// </summary>
// public sealed class MinusSpeed : DebuffMine
//{
// public MinusSpeed(XYPosition initPos) : base(initPos) { }
// public override PropType GetPropType() => PropType.minusSpeed;
// }
///// <summary>
///// 减少攻击力
///// </summary>
// public sealed class MinusAP : DebuffMine
//{
// public MinusAP(XYPosition initPos) : base(initPos) { }
// public override PropType GetPropType() => PropType.minusAP;
// }
///// <summary>
///// 增加冷却
///// </summary>
// public sealed class AddCD : DebuffMine
//{
// public AddCD(XYPosition initPos) : base(initPos) { }
// public override PropType GetPropType() => PropType.addCD;
// }
// #endregion
}

+ 2
- 2
logic/Gaming/ActionManager.cs View File

@@ -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())
{


+ 1
- 1
logic/Gaming/CharacterManager.cs View File

@@ -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);


+ 10
- 10
logic/Gaming/PropManager.cs View File

@@ -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)


+ 2
- 2
logic/Preparation/Utility/EnumType.cs View File

@@ -30,8 +30,8 @@ namespace Preparation.Utility
{
Null = 0,
Character = 1,
Prop = 2,
PickedProp = 3,
Consumables = 2,
Prop = 3,
Bullet = 4,
BombedBullet = 5,



+ 2
- 2
logic/Preparation/Utility/GameData.cs View File

@@ -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;
}*/



+ 20
- 16
logic/Server/CopyInfo.cs View File

@@ -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()


Loading…
Cancel
Save