提交示例代码
This commit is contained in:
51
物品和背包的完整代码/Server/Entity/Gate/Container/Container.cs
Normal file
51
物品和背包的完整代码/Server/Entity/Gate/Container/Container.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Fantasy.DataStructure.Collection;
|
||||
using Fantasy.Entitas;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson.Serialization.Options;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
/// <summary>
|
||||
/// 代表一个容器的实体
|
||||
/// </summary>
|
||||
public sealed class Container : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置表ID
|
||||
/// </summary>
|
||||
public uint ConfigId;
|
||||
/// <summary>
|
||||
/// 账户的实体
|
||||
/// </summary>
|
||||
[BsonIgnore]
|
||||
public Account Account;
|
||||
/// <summary>
|
||||
/// 对应的Config配置文件
|
||||
/// </summary>
|
||||
[BsonIgnore]
|
||||
public ContainerConfig Config => ContainerConfigData.Instance.Get(ConfigId);
|
||||
/// <summary>
|
||||
/// 当前已经使用的格子的数量
|
||||
/// </summary>
|
||||
public int CurrentCellCount;
|
||||
/// <summary>
|
||||
/// 容器内的物品
|
||||
/// </summary>
|
||||
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
|
||||
public Dictionary<long, Item> Items = new Dictionary<long, Item>();
|
||||
/// <summary>
|
||||
/// 容器内的物品,按照格子进行存储
|
||||
/// </summary>
|
||||
[BsonIgnore]
|
||||
public Dictionary<long, Item> ItemsByCell = new Dictionary<long, Item>();
|
||||
/// <summary>
|
||||
/// 容器内的物品,按照物品配置ID进行分组
|
||||
/// </summary>
|
||||
[BsonIgnore]
|
||||
public readonly OneToManyList<uint, Item> ItemsByConfigId = new OneToManyListPool<uint, Item>();
|
||||
/// <summary>
|
||||
/// 容器内的物品,按照物品类型进行分组
|
||||
/// </summary>
|
||||
[BsonIgnore]
|
||||
public readonly OneToManyList<uint, Item> ItemsByType = new OneToManyListPool<uint, Item>();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson.Serialization.Options;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
/// <summary>
|
||||
/// 把用户的所有容器都放在一个组件里,这样保存的时候也会存储在一个文档里。
|
||||
/// 如果物品数据过多,可能会超过数据库单条的限制。
|
||||
/// MongoDB的数据库的单个文档的最大大小限制为16MB。
|
||||
/// 所以这个几乎不会出现的,完全不需要考虑这个大小的问题了。因为几乎把玩家可能有16MB的物品。
|
||||
/// </summary>
|
||||
public sealed class ContainerComponent : Entity, ISupportedDataBase
|
||||
{
|
||||
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
|
||||
public Dictionary<int, Container> Containers = new Dictionary<int, Container>();
|
||||
}
|
||||
// 如果不放心,可以把每个容器单独做一个组件存起来
|
||||
// 例如下面
|
||||
/// <summary>
|
||||
/// 背包容器组件
|
||||
/// </summary>
|
||||
public sealed class BagContainerComponent : Entity, ISupportedDataBase
|
||||
{
|
||||
public Container Container;
|
||||
}
|
||||
/// <summary>
|
||||
/// 装备容器组件
|
||||
/// </summary>
|
||||
public sealed class EquipContainerComponent : Entity, ISupportedDataBase
|
||||
{
|
||||
public Container Container;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson.Serialization.Options;
|
||||
|
||||
namespace Fantasy;
|
||||
/// <summary>
|
||||
/// 代表装备的某一个属性
|
||||
/// </summary>
|
||||
public class EquipAttr : Entity
|
||||
{
|
||||
[BsonElement("K")]
|
||||
public int Key; // 属性数值对应的Key
|
||||
[BsonElement("V")]
|
||||
public int Value; // 属性对应额数值
|
||||
[BsonElement("S")]
|
||||
public int SValue; // 附加或强化属性的对应数值
|
||||
[BsonIgnore]
|
||||
public int ValidValue => Value + SValue; // 真实的数值
|
||||
}
|
||||
/// <summary>
|
||||
/// 挂载到Item下的组件,用来表示这个Item是一个装备
|
||||
/// </summary>
|
||||
public class EquipComponent : Entity, ISupportedDataBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 主属性
|
||||
/// </summary>
|
||||
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
|
||||
public Dictionary<int, EquipAttr> MainAttrs = new Dictionary<int, EquipAttr>();
|
||||
/// <summary>
|
||||
/// 附加(副)属性
|
||||
/// </summary>
|
||||
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
|
||||
public Dictionary<int, EquipAttr> EntryAttrs = new Dictionary<int, EquipAttr>();
|
||||
/// <summary>
|
||||
/// 词缀
|
||||
/// </summary>
|
||||
public List<uint> Affixs = new List<uint>();
|
||||
public int DurableMax; // 耐久度上限
|
||||
public int Durable; // 耐久度
|
||||
}
|
||||
|
||||
/*
|
||||
* {"sdfsdfsdfsdf":111}
|
||||
* {"s":111}
|
||||
* 2000,100 = 150 - 50 = 100
|
||||
* 2001,200
|
||||
*
|
||||
* 优化后的处理方式
|
||||
* 2000,100 ,50 = 100 + 50 = 150
|
||||
* 50 - 50 = 0 , 100 + 0 = 100
|
||||
* 力量 + 50 (+20)
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Fantasy;
|
||||
|
||||
public enum EquipPosition
|
||||
{
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// 武器
|
||||
/// </summary>
|
||||
Weapon = 1,
|
||||
/// <summary>
|
||||
/// 头盔
|
||||
/// </summary>
|
||||
Helmet = 2,
|
||||
/// <summary>
|
||||
/// 衣服
|
||||
/// </summary>
|
||||
Clothing = 3,
|
||||
/// <summary>
|
||||
/// 护腿
|
||||
/// </summary>
|
||||
Leggings = 4,
|
||||
/// <summary>
|
||||
/// 护腕
|
||||
/// </summary>
|
||||
Bracer = 5,
|
||||
/// <summary>
|
||||
/// 鞋子
|
||||
/// </summary>
|
||||
Shoe = 6,
|
||||
}
|
||||
21
物品和背包的完整代码/Server/Entity/Gate/Container/ItemReason.cs
Normal file
21
物品和背包的完整代码/Server/Entity/Gate/Container/ItemReason.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Fantasy;
|
||||
|
||||
/// <summary>
|
||||
/// 物品操作原因
|
||||
/// </summary>
|
||||
public enum ItemReason
|
||||
{
|
||||
None = 0,
|
||||
ContainerAdd = 1, // 容器初始化添加物品
|
||||
ContainerRemove = 2, // 容器移除物品
|
||||
ContainerSplit = 3, // 容器拆分物品
|
||||
Drop = 4, // 掉落物品
|
||||
Mail = 5, // 邮件领取物品
|
||||
Sort = 6, // 物品排序
|
||||
ItemUse = 7, // 物品使用扣除
|
||||
ItemTestAdd = 8, // 测试添加物品
|
||||
UnMountEquipAdd = 9, // 卸载装备添加(一般是装备容器移除,然后添加到背包容器中)
|
||||
UnMountEquipRemove = 10, // 卸载装备移除(一般是在装备容器里移除掉)
|
||||
MountEquipAdd = 11, // 装备添加(一般是在装备容器里添加)
|
||||
MountEquipRemove = 12, // 装备移除(一般是在装备容器里添加,背包容器里移除)
|
||||
}
|
||||
Reference in New Issue
Block a user