private int AddItem(DB_Item item, int amount) { if (m_itemsHash.Contains(item.ID) && (item.Flags & ItemFlags.Stackable) > 0) { InventorySlot slot; for (int index = 0, count = m_items.Count; index < (m_data.InventorySlots - 1) && count > 0 && amount > 0; index++) { if (m_items.TryGetValue(index, out slot)) { count--; if (slot.Item.Id == item.ID && slot.Amount < item.Stack) { amount = AddSlot(index, item, amount); } } } if (amount > 0) { return(AddNewSlots(item, amount)); } } else { return(AddNewSlots(item, amount)); } return(0); }
private int AddItem(int index, DB_Item item, int amount) { if (!m_items.ContainsKey(index)) { return(amount); } if (!m_itemsHash.Contains(item.ID)) { m_itemsHash.Add(item.ID); } return(SetSlot(index, item, amount)); }
private int AddSlot(int index, DB_Item item, int amount) { if ((item.Flags & ItemFlags.Stackable) == 0) { return(amount); } var slot = m_items[index]; var nAmount = amount + slot.Amount; slot.Amount = nAmount < item.Stack ? nAmount : item.Stack; m_view.UpdateSlot(slot, index); return(amount - slot.Amount); }
public static bool SelectAllItems(out Dictionary <int, DB_Item> data) { var locked = false; data = new Dictionary <int, DB_Item>(); if (!IsConnected) { return(false); } try { using (MySqlCommand _cmd = _connection.CreateCommand()) { _cmd.CommandText = $"SELECT a.*, b.stat, b.value FROM {tb_04} a LEFT JOIN {tb_04_01} b ON a.id = b.id;"; Monitor.Enter(s_lock, ref locked); using (MySqlDataReader _result = _cmd.ExecuteReader()) { DB_Item entry; int id; if (_result.HasRows) { while (_result.Read()) { id = _result.GetInt32(0); if (data.ContainsKey(id)) { data[id].Stats.Add(new Tuple <Stats, int>((Stats)_result.GetByte(10), _result.GetInt32(11))); } else { entry = new DB_Item(id, _result.GetNullString(1), _result.GetByte(2), _result.GetByte(3), _result.GetByte(4), _result.GetUInt16(5), _result.GetByte(6), _result.GetInt32(7), _result.GetInt32(8), _result.GetUInt32(9)); if ((entry.Flags & ItemFlags.Stats) > 0) { entry.Stats.Add(new Tuple <Stats, int>((Stats)_result.GetByte(10), _result.GetInt32(11))); } data[id] = entry; } } } } } return(true); } catch { return(false); } finally { if (locked) { Monitor.Exit(s_lock); } } }
private int SetSlot(int index, DB_Item item, int amount) { var slot = new InventorySlot(item.ID, 0); if ((item.Flags & ItemFlags.Stackable) == 0) { slot.Amount = 1; } else { slot.Amount = amount < item.Stack ? amount : item.Stack; } m_items[index] = slot; m_view.UpdateSlot(slot, index); return(amount - slot.Amount); }
DB_Item CreateDBItemFromItemSet <T>(List <T> set, int setIndex, int characterID, byte color1, byte color2) where T : Item_Type { var item = new DB_Item(); var gameItem = set[setIndex]; item.ItemTypeID = gameItem.ResourceID; item.LocationSlot = (int)gameItem.EquipmentSlot; item.LocationType = (int)Game_Item.EItemLocationType.ILT_Equipment; item.LocationID = 0; item.Id = ServiceContainer.GetService <IDatabase>().Characters.AllocateItemID(); item.Color1 = color1; item.Color2 = color2; item.StackSize = 1; item.CharacterID = characterID; return(item); }
private int AddNewSlots(DB_Item item, int amount) { var index = GetFreeSlot(); if (index == -1) { return(-amount); } if (!m_itemsHash.Contains(item.ID)) { m_itemsHash.Add(item.ID); } while (index != -1 && (amount = SetSlot(index, item, amount)) > 0) { index = GetFreeSlot(); } return(amount); }
public static async Task <Dictionary <int, DB_Item> > SelectAllItemsAsync() { try { using (var connection = await GetConnectionAsync()) { using (var command = connection.CreateCommand()) { command.CommandText = $"SELECT a.*, b.stat, b.value FROM {tb_04} a LEFT JOIN {tb_04_01} b ON a.id = b.id;"; using (var reader = await command.ExecuteReaderAsyncEx()) { var result = new Dictionary <int, DB_Item>(); if (reader.HasRows) { while (await reader.ReadAsyncEx()) { var id = reader.GetInt32(0); if (result.TryGetValue(id, out var entry)) { entry.Stats.Add(((Stats)reader.GetByte(10), reader.GetInt32(11))); } else { entry = new DB_Item(id, reader.GetNullString(1), reader.GetByte(2), reader.GetByte(3), reader.GetByte(4), reader.GetUInt16(5), reader.GetByte(6), reader.GetInt32(7), reader.GetUInt32(8), reader.GetUInt32(9)); if ((entry.Flags & ItemFlags.Stats) > 0) { entry.Stats.Add(((Stats)reader.GetByte(10), reader.GetInt32(11))); } result[id] = entry; } } } return(result); } } } } catch (Exception exp) { ServerLogger.LogException(exp); return(null); } }
public static bool Select(int id, out DB_Item entry) { return(m_items.TryGetValue(id, out entry)); }
void OnEnable() { Target = (DB_Item)target; }