BuffComponent.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. using Common.Base;
  3. using MongoDB.Bson;
  4. using MongoDB.Bson.Serialization.Attributes;
  5. namespace Model
  6. {
  7. public class BuffComponent: Component<Unit>
  8. {
  9. [BsonElement]
  10. public HashSet<Buff> buffs;
  11. [BsonIgnore]
  12. public Dictionary<ObjectId, Buff> idBuff;
  13. [BsonIgnore]
  14. public MultiMap<BuffType, Buff> typeBuff;
  15. public BuffComponent()
  16. {
  17. this.buffs = new HashSet<Buff>();
  18. this.idBuff = new Dictionary<ObjectId, Buff>();
  19. this.typeBuff = new MultiMap<BuffType, Buff>();
  20. }
  21. public override void BeginInit()
  22. {
  23. base.BeginInit();
  24. this.buffs = new HashSet<Buff>();
  25. this.idBuff = new Dictionary<ObjectId, Buff>();
  26. this.typeBuff = new MultiMap<BuffType, Buff>();
  27. }
  28. public override void EndInit()
  29. {
  30. base.EndInit();
  31. foreach (var buff in this.buffs)
  32. {
  33. this.idBuff.Add(buff.Id, buff);
  34. this.typeBuff.Add(buff.Config.Type, buff);
  35. }
  36. }
  37. }
  38. }