diff --git a/Engine/CLEngine.Core/framework/ItemManager.cs b/Engine/CLEngine.Core/framework/ItemManager.cs index 3e8bbd7b1a2dc764b79a1fa02f601d31bb734d96..2e15076bc37dfc45f139e8b95f71b464bd0c5a47 100644 --- a/Engine/CLEngine.Core/framework/ItemManager.cs +++ b/Engine/CLEngine.Core/framework/ItemManager.cs @@ -15,6 +15,10 @@ namespace CLEngine.Core.framework /// private static Dictionary _worldItem; /// + /// 玩家背包 + /// + private static List _playerItem; + /// /// 全局物品Id /// private static int _worldId; @@ -69,5 +73,170 @@ namespace CLEngine.Core.framework throw new Exception(e.Message); } } + /// + /// 世界物品中通过名称找物品 + /// + /// + /// + public static ItemObject WorldFindItemByName(string name) + { + return _worldItem[name]; + } + /// + /// 世界物品中通过编号找物品 + /// + /// + /// + public static ItemObject WorldFindItemById(int id) + { + foreach (var item in _worldItem) + { + if (item.Value.Id == id) + { + return item.Value; + } + } + return null; + } + /// + /// 背包中通过名字找物品,返回第一个找到的 + /// + /// + /// + public static ItemObject BagFindItemByName(string name) + { + var max = _playerItem.Count; + ItemObject item; + for (int i = 0; i < max; i++) + { + item = _playerItem[i]; + if (item.Name == name) + { + return item; + } + } + return null; + } + /// + /// 背包中通过名字找物品,返回所有符合的物品 + /// + /// + /// + public static List BagFindAllItemByName(string name) + { + var max = _playerItem.Count; + var itemlist = new List(); + ItemObject item; + for (int i = 0; i < max; i++) + { + item = _playerItem[i]; + if (item.Name == name) + { + itemlist.Add(item); + } + } + return itemlist; + } + /// + /// 背包中通过编号找物品,返回第一个找到的 + /// + /// + /// + public static ItemObject BagFindItemById(int id) + { + var max = _playerItem.Count; + ItemObject item; + for (int i = 0; i < max; i++) + { + item = _playerItem[i]; + if (item.Id == id) + { + return item; + } + } + return null; + } + /// + /// 背包中通过编号找物品,返回所有找到的 + /// + /// + /// + public static List BagFindAllItemById(int id) + { + var max = _playerItem.Count; + var itemlist = new List(); + ItemObject item; + for (int i = 0; i < max; i++) + { + item = _playerItem[i]; + if (item.Id == id) + { + itemlist.Add(item); + } + } + return itemlist; + } + /// + /// 拾取物品时以编号作为获取参数 + /// + /// + /// + public static void GetItemById(int id, int number) + { + var onget = WorldFindItemById(id); + ItemObject item = null; + int max = _playerItem.Count; + bool is_finish = false; + for (int i = 0; i < max; i++) + { + item = _playerItem[i]; + if (item.Id == id) + { + if (item.Number + number <= item.MaxNumber) + { + item.Number += number; + is_finish = true; + break; + } + } + } + if (!is_finish) + { + onget.Number = number; + _playerItem.Add(onget); + } + onget.GetItem(); + } + /// + /// 拾取物品时以名称作为获取参数 + /// + /// + /// + public static void GetItemByName(string name, int number) + { + var onget = _worldItem[name]; + ItemObject item = null; + var max = _playerItem.Count; + var is_finish = false; + for (int i = 0; i < max; i++) + { + item = _playerItem[i]; + if (item.Name == name) + { + if (item.Number + number <= item.MaxNumber) + { + item.Number += number; + is_finish = true; + break; + } + } + } + if (!is_finish) + { + onget.Number = number; + _playerItem.Add(onget); + } + onget.GetItem(); + } } } \ No newline at end of file diff --git a/Engine/CLEngine.Core/framework/ItemObject.cs b/Engine/CLEngine.Core/framework/ItemObject.cs index dd9a07d858e175f785ad51c37f43e3f206306e81..8076d1942055fa6e736b2efc9d3d041d1d4fd076 100644 --- a/Engine/CLEngine.Core/framework/ItemObject.cs +++ b/Engine/CLEngine.Core/framework/ItemObject.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; using System.IO; using Microsoft.Xna.Framework; +using FairyGUI; namespace CLEngine.Core.framework { @@ -52,12 +53,17 @@ namespace CLEngine.Core.framework [DataMember] private string _iconPath; [DataMember] private string _name; + [DataMember] private string _showName; [DataMember] private string _description; [DataMember] private string _type; [DataMember] private int _userId; [DataMember] private int _id; + [DataMember] private string _belongBag; [DataMember] private int _number; [DataMember] private int _maxNumber; + [DataMember] private float _salePercent; + [DataMember] private int _buyPrice; + [DataMember] private Color _color; [DataMember] private int _hp; [DataMember] private int _maxHp; [DataMember] private int _addMoveSpeed; @@ -68,8 +74,40 @@ namespace CLEngine.Core.framework [DataMember] private int _addReturnHp; [DataMember] private int _addReturnMp; [DataMember] private Dictionary _customProp; + [DataMember] private Image _guiIcon; + [DataMember] private bool _isGuiShow; [NonSerialized] private Texture2D _texture; + private int _positionInBag; + public string ShowName { get { return _showName; } set { _showName = value; } } + /// + /// 属于哪个背包(名) + /// + public string BelongBag{ get { return _belongBag; }set{ _belongBag = value; } } + /// + /// 物品颜色级别 + /// + public Color ItemColor { get { return _color; } set { _color = value; } } + /// + /// 购买价格 + /// + public int BuyPrice { get { return _buyPrice; } set { _buyPrice = value; } } + /// + /// 出售价格折算比 + /// + public float SalePercent { get { return _salePercent; } set { _salePercent = value; } } + /// + /// 是否gui显示 + /// + public bool IsGuiShow { get { return _isGuiShow; } set { _isGuiShow = value; } } + /// + /// GUI中的图标 + /// + public Image GuiIcon { get { return _guiIcon; } set { _guiIcon = value; } } + /// + /// 在背包内的位置 + /// + public int PositionInBag { get { return _positionInBag; } set { _positionInBag = value; } } /// /// 物品类型 /// @@ -216,7 +254,7 @@ namespace CLEngine.Core.framework /// /// 获取物品 /// - public void getItem() + public void GetItem() { if (Get != null) { @@ -243,5 +281,9 @@ namespace CLEngine.Core.framework NumberChange.Invoke(this, new ItemEventArgs(userId)); } } + public ItemObject() + { + SalePercent = 1f; + } } }