EquipItemBase.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using XGame.Database;
  2. namespace FL.Data.Items
  3. {
  4. public class EquipItemBase : IItemBase
  5. {
  6. /// <summary>
  7. /// 装备唯一id
  8. /// </summary>
  9. public int Id { get; private set; }
  10. private EquipmentTable _table;
  11. private ItemTable _itemTable;
  12. /// <summary>
  13. /// 装备表格id
  14. /// </summary>
  15. public int TableId => _table.Id;
  16. public EItemType ItemType => EItemType.Equip;
  17. /// <summary>
  18. /// 装备部位
  19. /// </summary>
  20. public EEquipType EquipType => _table.Part;
  21. public EQualityLevel Quality => _table.Quality;
  22. public string Name => _table.Name;
  23. public int Level { get; set; }
  24. /// <summary>
  25. /// 装备属性转化的战斗力
  26. /// </summary>
  27. public long FightingPower { get; set; }
  28. public string Description { get; set; }
  29. public string Icon => _itemTable?.Icon;
  30. /// <summary>
  31. /// 根据uid从装备背包获取装备信息
  32. /// </summary>
  33. /// <param name="id"></param>
  34. public void InitById(int id)
  35. {
  36. var attr = EquipData.Instance.GetBagEquipItem(id);
  37. XGame.Framework.Assert.IsNotNull(attr, $"装备信息不存在,id:{id}");
  38. Id = id;
  39. Level = attr.Level;
  40. var tableId = attr.TableId;
  41. _table = EquipmentTableRepo.Get(tableId);
  42. XGame.Framework.Assert.IsNotNull(_table, $"装备表不存在,id:{tableId}");
  43. _itemTable = ItemTableRepo.Get(tableId);
  44. XGame.Framework.Assert.IsNotNull(_itemTable, $"道具表不存在,id:{tableId}");
  45. }
  46. /// <summary>
  47. /// 根据装备部位从身上穿戴的装备获取装备信息
  48. /// </summary>
  49. /// <param name="id"></param>
  50. public void InitByEquipPart(EEquipType equipPart)
  51. {
  52. var attr = EquipData.Instance.GetWearEquipData(equipPart);
  53. XGame.Framework.Assert.IsNotNull(attr, $"装备信息不存在,部位id:{equipPart}");
  54. Id = 0;
  55. Level = attr.Level;
  56. var tableId = attr.TableId;
  57. _table = EquipmentTableRepo.Get(tableId);
  58. XGame.Framework.Assert.IsNotNull(_table, $"装备表不存在,id:{tableId}");
  59. _itemTable = ItemTableRepo.Get(tableId);
  60. XGame.Framework.Assert.IsNotNull(_itemTable, $"道具表不存在,id:{tableId}");
  61. }
  62. }
  63. }