示例#1
0
        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);
        }
示例#2
0
        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
                    });
                }
            });
        }
示例#3
0
            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);
                }
            }
示例#4
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);
示例#5
0
        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);
            }
        }