Esempio n. 1
0
        public static Item CreateEntry(ulong CID, string ID, uint StackNum, float health = 1f, int carId = 0)
        {
            var tblIdx = ItemTable.Items.FindIndex(i => i.ID == ID);

            if (tblIdx < 0)
            {
                Log.WriteError($"Failed to find item id {ID} for Item.CreateEntry");
                return(null);
            }

            using (var rc = Database.GetContext())
            {
                var lastItem = rc.Items.Where(i => i.CID == (long)CID).OrderByDescending(i => i.InvIdx).FirstOrDefault();

                var newItem = new Models.Item
                {
                    CID        = (long)CID,
                    ItemID     = ID,
                    StackNum   = (int)StackNum,
                    ItemHealth = health,
                    InvIdx     = (lastItem?.InvIdx ?? 0) + 1,
                    CurCarID   = carId,
                    LastCarID  = carId
                };

                rc.Items.Add(newItem);
                rc.SaveChanges();

                return(new Item(newItem.ItemID, newItem));
            }
        }
Esempio n. 2
0
        private Item(string id, Models.Item dbItem)
        {
            string lookupId = id;

            if (dbItem != null)
            {
                lookupId     = dbItem.ItemID;
                CID          = (ulong)dbItem.CID;
                curCarID     = (uint)dbItem.CurCarID;
                state        = (ushort)dbItem.State;
                slot         = (ushort)dbItem.Slot;
                stackNum     = (uint)dbItem.StackNum;
                lastCarID    = (uint)dbItem.LastCarID;
                assistA      = (uint)dbItem.AssistA;
                assistB      = (uint)dbItem.AssistB;
                assistC      = (uint)dbItem.AssistC;
                assistD      = (uint)dbItem.AssistD;
                assistE      = (uint)dbItem.AssistE;
                assistF      = (uint)dbItem.AssistF;
                assistG      = (uint)dbItem.AssistG;
                assistH      = (uint)dbItem.AssistH;
                assistI      = (uint)dbItem.AssistI;
                assistJ      = (uint)dbItem.AssistJ;
                box          = (uint)dbItem.Boxed;
                belonging    = (uint)dbItem.Bound;
                upgrade      = dbItem.UpgradeLevel;
                upgradePoint = dbItem.UpgradePoints;
                expireTick   = 0;
                //expireTick = dbItem.ExpireTimestamp;
                itemHealth = dbItem.ItemHealth;
                invIdx     = (uint)dbItem.InvIdx;
                random     = dbItem.Random;
            }

            tblIdx = ItemTable.Items.FindIndex(i => i.ID == lookupId);
            if (tblIdx == -1)
            {
                itemEntry = null;
                return;
            }
            ID        = lookupId;
            itemEntry = ItemTable.Items[tblIdx];
        }
Esempio n. 3
0
 public static Item FromDB(Models.Item dbItem) => new Item(dbItem.ItemID, dbItem);