public void GenerateMultipleIds() { var id1 = IdUtilities.GenerateId(); var id2 = IdUtilities.GenerateId(); Assert.That(id1, Is.Not.EqualTo(id2)); }
public long EquipUnmanagedItem(Lot lot, uint count = 1, int slot = -1, InventoryType inventoryType = InventoryType.None) { using var cdClient = new CdClientContext(); var cdClientObject = cdClient.ObjectsTable.FirstOrDefault( o => o.Id == lot ); var itemRegistryEntry = lot.GetComponentId(ComponentId.ItemComponent); if (cdClientObject == default || itemRegistryEntry == default) { Logger.Error($"{lot} is not a valid item"); return(-1); } var itemComponent = cdClient.ItemComponentTable.First( i => i.Id == itemRegistryEntry ); var id = IdUtilities.GenerateObjectId(); Items[itemComponent.EquipLocation] = new InventoryItem { InventoryItemId = id, Count = count, Slot = slot, LOT = lot, InventoryType = (int)inventoryType }; return(id); }
/// <summary> /// Constructor to create a basket for a given customer /// </summary> /// <param name="customerId">Id of the customer to create basket for.</param> public BasketOfItems(long customerId) { // Could get the database to generate the id. // However I think it is a bit more DDD to get the app to. Id = IdUtilities.GenerateId(); CustomerId = customerId; // Dont know if this should be a list, for now it will do. BasketItems = new List <BasketItem>(); }
protected InventoryComponent() { Listen(OnDestroyed, () => { OnEquipped.Clear(); OnUnEquipped.Clear(); }); Listen(OnStart, () => { using var cdClient = new CdClientContext(); var component = cdClient.ComponentsRegistryTable.FirstOrDefault(c => c.Id == GameObject.Lot && c.Componenttype == (int)ComponentId.InventoryComponent); var items = cdClient.InventoryComponentTable.Where(i => i.Id == component.Componentid).ToArray(); Items = new Dictionary <EquipLocation, InventoryItem>(); foreach (var item in items) { var cdClientObject = cdClient.ObjectsTable.FirstOrDefault( o => o.Id == item.Itemid ); var itemRegistryEntry = cdClient.ComponentsRegistryTable.FirstOrDefault( r => r.Id == item.Itemid && r.Componenttype == 11 ); if (cdClientObject == default || itemRegistryEntry == default) { Logger.Error($"{item.Itemid} is not a valid item"); continue; } var itemComponent = cdClient.ItemComponentTable.First( i => i.Id == itemRegistryEntry.Componentid ); Debug.Assert(item.Itemid != null, "item.Itemid != null"); Debug.Assert(item.Count != null, "item.Count != null"); Items.TryAdd(itemComponent.EquipLocation, new InventoryItem { InventoryItemId = IdUtilities.GenerateObjectId(), Count = (long)item.Count, LOT = (int)item.Itemid, Slot = -1, InventoryType = -1 }); } }); }
public void Serialize(BitWriter writer) { using var ctx = new UchuContext(); writer.Write <uint>(0); writer.Write((ushort)Mails.Length); writer.Write <ushort>(0); foreach (var mail in Mails) { var author = ctx.Characters.First(c => c.CharacterId == mail.AuthorId); writer.Write(mail.Id); writer.WriteString(mail.Subject, 50, true); writer.WriteString(mail.Body, 400, true); writer.WriteString(author.Name, 32, true); writer.Write <uint>(0); writer.Write(mail.AttachmentCurrency); writer.Write(mail.AttachmentLot > 0 ? IdUtilities.GenerateObjectId() : 0); // Unnecessary writer.Write(mail.AttachmentLot); writer.Write <uint>(0); writer.Write <long>(0); writer.Write(mail.AttachmentCount); for (var i = 0; i < 6; i++) { writer.Write <byte>(0); } writer.Write((ulong)((DateTimeOffset)mail.ExpirationTime).ToUnixTimeSeconds()); writer.Write((ulong)((DateTimeOffset)mail.SentTime).ToUnixTimeSeconds()); writer.Write((byte)(mail.Read ? 1 : 0)); writer.Write <byte>(0); writer.Write <ushort>(0); writer.Write <uint>(0); } }
public async Task HandleMinifigureCreation(CreateMinifigurePacket packet, Connection connection) { Logger.Information($"Creating character: {packet.MinifigureName}"); await using var ctx = new NovaContext(); var account = await ctx.Accounts .Include(a => a.Characters) .FirstOrDefaultAsync(a => a.Username == connection.Username); if (account == default) { connection.Send(new MinifigureListResponsePacket()); return; } if (await ctx.Characters.AnyAsync(c => c.Name == packet.MinifigureName)) { connection.Send(new CreateMinifigureResponsePacket { ResponseCode = 3 }); return; } account.Characters.Add(new Character { Name = packet.MinifigureName, ShirtColor = packet.ShirtColor, ShirtStyle = packet.ShirtStyle, PantsColor = packet.PantsColor, Eyebrows = packet.Eyebrows, Eyes = packet.Eyes, Rh = packet.Rh, Lh = packet.Lh, HairColor = packet.HairColor, HairStyle = packet.HairStyle, Mouth = packet.Mouth, ObjectId = IdUtilities.GenerateObjectId() }); await ctx.SaveChangesAsync(); connection.Send(new CreateMinifigureResponsePacket { ResponseCode = 0 }); await HandleMinifigureListRequest(default, connection);
/// <summary> /// Constructor to create a basket item /// </summary> /// <param name="productId">Id of product this basket item represents.</param> /// <param name="quantity">Quantity of item to be added. This can be updated via UpdateQuantity</param> public BasketItem(long productId, int quantity) { if (productId <= 0) { throw new ArgumentException(nameof(productId)); } if (quantity <= 0) { throw new ArgumentException(nameof(quantity)); } Id = IdUtilities.GenerateId(); ProductId = productId; // should probably make quantity an uint Quantity = quantity; }
public bool Add(PurchaseBillViewModel entity) { var purchaseBill = entity.MapToPuchaseBill(); purchaseBill.PurchaseBillId = IdUtilities.GenerateByTimeSpan(); purchaseBill.CreatedDate = DateTime.Now; purchaseBill.StaffId = StaffGlobal.StaffId; _purchaseBillRepository.Add(purchaseBill); //purchaseBill.PurchaseBillDetails = new List<PurchaseBillDetail>(); //var purchaseBillDetails = new List<PurchaseBillDetail>(); foreach (var item in entity.PurchaseBillDetailViewModels) { var purchaseBillDetail = item.MapToPurchaseBillDetail(); purchaseBillDetail.PurchaseBillId = purchaseBill.PurchaseBillId; _purchaseBillDetailRepository.Add(purchaseBillDetail); } return(true); }
public bool Add(SaleBillViewModel entity) { if (entity == null) { return(false); } var saleBill = entity.MapToSaleBill(); saleBill.SaleBillId = IdUtilities.GenerateByTimeSpan(); saleBill.CreatedDate = DateTime.Now; saleBill.StaffId = StaffGlobal.CurrentStaff.StaffId; _saleBillRepository.Add(saleBill); foreach (var item in entity.SaleBillDetailViewModels) { var saleBillDetail = item.MapToSaleBillDetail(); saleBillDetail.SaleBillId = saleBill.SaleBillId; _saleBillDetailRepository.Add(saleBillDetail); } return(true); }
public async Task CharacterCreate(CharacterCreateRequest packet, IRakConnection connection) { var session = Server.SessionCache.GetSession(connection.EndPoint); uint shirtLot; uint pantsLot; await using (var ctx = new CdClientContext()) { // // Shirt // var shirtColor = await ctx.BrickColorsTable.FirstOrDefaultAsync(c => c.Id == packet.ShirtColor); var shirtName = $"{(shirtColor != null ? shirtColor.Description : "Bright Red")} Shirt {packet.ShirtStyle}"; var shirt = ctx.ObjectsTable.ToArray().FirstOrDefault(o => string.Equals(o.Name, shirtName, StringComparison.CurrentCultureIgnoreCase)); shirtLot = (uint)(shirt != null ? shirt.Id : 4049); // Select 'Bright Red Shirt 1' if not found. // // Pants // var pantsColor = await ctx.BrickColorsTable.FirstOrDefaultAsync(c => c.Id == packet.PantsColor); var pantsName = $"{(pantsColor != null ? pantsColor.Description : "Bright Red")} Pants"; var pants = ctx.ObjectsTable.ToArray().FirstOrDefault(o => string.Equals(o.Name, pantsName, StringComparison.CurrentCultureIgnoreCase)); pantsLot = (uint)(pants != null ? pants.Id : 2508); // Select 'Bright Red Pants' if not found. } var first = (await Server.Resources.ReadTextAsync("names/minifigname_first.txt")).Split('\n'); var middle = (await Server.Resources.ReadTextAsync("names/minifigname_middle.txt")).Split('\n'); var last = (await Server.Resources.ReadTextAsync("names/minifigname_last.txt")).Split('\n'); var name = ( first[packet.Predefined.First] + middle[packet.Predefined.Middle] + last[packet.Predefined.Last] ).Replace("\r", ""); await using (var ctx = new UchuContext()) { if (ctx.Characters.Any(c => c.Name == packet.CharacterName)) { Logger.Debug($"{connection} character create rejected due to duplicate name"); connection.Send(new CharacterCreateResponse { ResponseId = CharacterCreationResponse.CustomNameInUse } ); return; } if (ctx.Characters.Any(c => c.Name == name)) { Logger.Debug($"{connection} character create rejected due to duplicate pre-made name"); connection.Send(new CharacterCreateResponse { ResponseId = CharacterCreationResponse.PredefinedNameInUse } ); return; } var user = await ctx.Users.Include(u => u.Characters).SingleAsync(u => u.UserId == session.UserId); user.Characters.Add(new Character { CharacterId = IdUtilities.GenerateObjectId(), Name = name, CustomName = packet.CharacterName, ShirtColor = packet.ShirtColor, ShirtStyle = packet.ShirtStyle, PantsColor = packet.PantsColor, HairStyle = packet.HairStyle, HairColor = packet.HairColor, Lh = packet.Lh, Rh = packet.Rh, EyebrowStyle = packet.EyebrowStyle, EyeStyle = packet.EyeStyle, MouthStyle = packet.MouthStyle, LastZone = (int)ZoneId.VentureExplorerCinematic, LastInstance = 0, LastClone = 0, InventorySize = 20, LastActivity = DateTimeOffset.Now.ToUnixTimeSeconds(), Items = new List <InventoryItem> { new InventoryItem { InventoryItemId = IdUtilities.GenerateObjectId(), LOT = (int)shirtLot, Slot = 0, Count = 1, InventoryType = (int)InventoryType.Items, IsEquipped = true }, new InventoryItem { InventoryItemId = IdUtilities.GenerateObjectId(), LOT = (int)pantsLot, Slot = 1, Count = 1, InventoryType = (int)InventoryType.Items, IsEquipped = true } }, CurrentImagination = 0, MaximumImagination = 0 }); Logger.Debug( $"{user.Username} created character \"{packet.CharacterName}\" with the pre-made name of \"{name}\""); await ctx.SaveChangesAsync(); connection.Send(new CharacterCreateResponse { ResponseId = CharacterCreationResponse.Success } ); await SendCharacterList(connection, session.UserId); } }