using System; using System.Collections.Generic; using MongoDB.Bson.Serialization.Attributes; using ProtoBuf; namespace ET { [ProtoContract] [Config] public partial class CropConfigCategory : ProtoObject, IMerge { public static CropConfigCategory Instance; [ProtoIgnore] [BsonIgnore] private Dictionary dict = new Dictionary(); [BsonElement] [ProtoMember(1)] private List list = new List(); public CropConfigCategory() { Instance = this; } public void Merge(object o) { CropConfigCategory s = o as CropConfigCategory; this.list.AddRange(s.list); } public override void EndInit() { foreach (CropConfig config in list) { config.EndInit(); this.dict.Add(config.Id, config); } this.AfterEndInit(); } public CropConfig Get(int id) { this.dict.TryGetValue(id, out CropConfig item); if (item == null) { throw new Exception($"配置找不到,配置表名: {nameof (CropConfig)},配置id: {id}"); } return item; } public bool Contain(int id) { return this.dict.ContainsKey(id); } public Dictionary GetAll() { return this.dict; } public List GetList() { return this.list; } public CropConfig GetOne() { if (this.dict == null || this.dict.Count <= 0) { return null; } return this.dict.Values.GetEnumerator().Current; } } [ProtoContract] public partial class CropConfig: ProtoObject, IConfig { /// 编号 [ProtoMember(1)] public int Id { get; set; } /// 名称 [ProtoMember(2)] public string Name { get; set; } /// 季节 [ProtoMember(3)] public int[] Season { get; set; } /// 农田类型 [ProtoMember(4)] public int FieldType { get; set; } /// 种子需求 [ProtoMember(5)] public int SeedNeed { get; set; } /// 种子数量 [ProtoMember(6)] public int SeedNum { get; set; } /// 成长周期 [ProtoMember(7)] public int GrowthCycle { get; set; } /// 产品编号 [ProtoMember(8)] public int ProductID { get; set; } /// 基础产量 [ProtoMember(9)] public int BasicProduction { get; set; } /// 副产品编号 [ProtoMember(10)] public int ByProduct { get; set; } /// 副产品基础产量 [ProtoMember(11)] public int ByProductNum { get; set; } /// 种子产出量 [ProtoMember(12)] public int SeedProduce { get; set; } /// 作物图片 [ProtoMember(13)] public string CropPic { get; set; } } }