ItemService.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using FL.Data.Items;
  2. using XGame.Database;
  3. using XGame.Framework.Data;
  4. namespace FL.Data
  5. {
  6. public class ItemService : DataSingleton<ItemService>
  7. {
  8. public bool IsEnough(int id, long needNum, bool showTips)
  9. {
  10. var num = ItemData.Instance.GetItemNum(id);
  11. if (needNum > num)
  12. {
  13. if (showTips)
  14. {
  15. var table = ItemTableRepo.Get(id);
  16. if (table != null)
  17. EventSingle.Instance.Notify(
  18. EventDefine.ShowTips,
  19. string.Format(StringDefine.itemNotEnough, table.Name)
  20. );
  21. }
  22. return false;
  23. }
  24. else
  25. {
  26. return true;
  27. }
  28. }
  29. /// <summary>
  30. /// 给界面上Itembase展示用,KindItem道具类型kind:技术定义类型 0默认道具表id 1装备临时库序号ID
  31. /// </summary>
  32. /// <param name="id"></param>
  33. /// <param name="count"></param>
  34. /// <param name="kind"></param>
  35. /// <returns></returns>
  36. public IItemBase GetItemBase(int id, long count, int kind, bool isGet = false)
  37. {
  38. if (kind == 1)
  39. {
  40. var equipItem = new EquipItemBase();
  41. equipItem.InitById(id);
  42. return equipItem;
  43. }
  44. else
  45. {
  46. var table = ItemTableRepo.Get(id);
  47. if (table.Type == (int)EItemType.Partner)
  48. {
  49. var item = new PartnerItemBase();
  50. item.Init(id);
  51. return item;
  52. }
  53. else
  54. {
  55. var item = new ItemBase();
  56. item.Init(id, count, isGet);
  57. return item;
  58. }
  59. }
  60. }
  61. }
  62. }