private static bool SaveCharacterItems(TContext ctx, bool save, Player player, int characterId, Item[] items, ItemType type, SlotItem[] existing) { for (var i = 0; i < items.Length; i++) { if (!SaveCharacterItem(ctx, save, player, characterId, type, items[i], i, existing)) return false; } return true; }
private static bool SaveCharacterItem(TContext ctx, bool save, Player player, int characterId, ItemType type, Item item, int slot, SlotItem[] existing) { var netId = 0; var prefix = 0; var stack = 0; var favorite = false; if (item != null) { netId = item.netID; prefix = item.prefix; stack = item.stack; favorite = item.favorited; } var slotItem = existing.SingleOrDefault(x => x.Slot == slot && x.Type == type && x.NetId == netId); if (slotItem != null) { slotItem.Favorite = favorite; slotItem.Stack = stack; slotItem.Prefix = prefix; } else { slotItem = new SlotItem() { CharacterId = characterId, Slot = slot, NetId = netId, Stack = stack, Prefix = prefix, Favorite = favorite, Type = type }; ctx.Items.Add(slotItem); } return true; }