Exemplo n.º 1
0
        /// <summary>
        /// Checks if a given area in the container is free, while excluding an item
        /// </summary>
        /// <param name="area">The area to check</param>
        /// <param name="item">The item to exclude from the check</param>
        /// <returns>If the given area is free</returns>
        public bool IsAreaFreeExcluding(RectInt area, Item item)
        {
            int        i          = FindItem(item);
            StoredItem storedItem = default;

            if (i != -1)
            {
                storedItem = items[i];
                items[i]   = new StoredItem(storedItem.Item, new Vector2Int(100000, 100000));
            }

            bool areaFree = IsAreaFree(area);

            if (i != -1)
            {
                items[i] = storedItem;
            }

            return(areaFree);
        }
Exemplo n.º 2
0
        public override void Update()
        {
            base.Update();

            ammo = MaxAmmo;
            if (duck != null)
            {
                StoredItem stored = PurpleBlock.GetStoredItem(duck.profile);

                if (stored.type == GetType())
                {
                    storeSound.Play();
                    duck.onFire = true;
                    duck.Zap(this);

                    stored.sprite = null;
                    stored.type   = null;
                    stored.thing  = null;
                }
            }
        }
Exemplo n.º 3
0
        public static int?Count(this StoredItem storedItem)
        {
            if (storedItem == null)
            {
                throw new ArgumentNullException(nameof(storedItem));
            }

            int count = 0;

            foreach (Position item in storedItem.Positions)
            {
                int?itemCount = item.Count();

                if (itemCount.HasValue)
                {
                    count += itemCount.Value;
                }
            }

            return(count);
        }
Exemplo n.º 4
0
    void TryToBuy(StoredItem s)
    {
        InventoryList merchantInventory = currentMerchant.baseInventory;
        Item          item     = s.item;
        bool          hasMoney = item.cost <= GlobalController.inventory.CheckMoney();

        if (hasMoney)
        {
            // copy
            StoredItem toAdd = new StoredItem(merchantInventory.GetItem(item).item);
            TakeMoney(item.cost);
            if (merchantInventory.GetItem(item).item.stackable)
            {
                if (merchantInventory.GetItem(s).count > 1)
                {
                    merchantInventory.GetItem(s).count -= 1;
                }
                else
                {
                    merchantInventory.RemoveItem(s);
                }
            }
            else
            {
                merchantInventory.RemoveItem(s);
            }
            AddItem(toAdd, false);
            inventoryUI.merchantLine.text = currentMerchant.GetThanksDialogue(item);
            itemBuy.PlayOneShot(itemBuy.clip);
            UpdateMoneyUI();
            currentMerchant.ReactToBuy();
        }
        else
        {
            inventoryUI.merchantLine.text = currentMerchant.notEnoughMoneyDialogue;
        }
        inventoryUI.PopulateItems(currentMerchant.baseInventory);
    }
Exemplo n.º 5
0
    public void PopulateItems(InventoryList inventoryList)
    {
        // don't want to modify the list in place, instead copy and iterate through that
        // it Just Works
        foreach (Transform oldItem in gridHolder.transform.Cast <Transform>().ToArray())
        {
            // Destroy is called after the Update loop, which screws up the first child selection logic
            // so we do this so it's not shown
            Destroy(oldItem.gameObject);
            oldItem.parent = null;
        }

        List <StoredItem> items = inventoryList.GetAll();

        for (int i = items.Count - 1; i >= 0; i--)
        {
            StoredItem item = items[i];
            GameObject g    = (GameObject)Instantiate(itemPaneTemplate);
            g.transform.parent = gridHolder;
            g.GetComponent <ItemPane>().PopulateSelfInfo(item);
        }
        SelectFirstChild();
    }
Exemplo n.º 6
0
        /// <summary>
        /// Removes multiple items from the container
        /// </summary>
        /// <param name="itemsToRemove">An array of items to remove</param>
        public void RemoveItems(Item[] itemsToRemove)
        {
            foreach (Item itemToRemove in itemsToRemove)
            {
                lock (modificationLock)
                {
                    for (var i = 0; i < items.Count; i++)
                    {
                        StoredItem storedItem = items[i];
                        if (storedItem.Item == itemToRemove)
                        {
                            StoredItems.RemoveAt(i);
                            itemToRemove.SetContainer(null, true, true);
                            break;
                        }
                    }
                }
            }

            LastModification = Time.time;

            OnContainerChanged(itemsToRemove, ContainerChangeType.Remove);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds an item to the list. The location of the item in the list is unspecified.
        /// </summary>
        public void Add(T item, UnorderedListMetadata metadata)
        {
            // Make sure the item is not in another list
            if (metadata.Index != -1)
            {
                throw new Exception(String.Format("Item {0} is already stored in another UnorderedList, or has been added twice to the same one", item));
            }

            // Grow the array if necessary
            if (Length == Items.Length)
            {
                Array.Resize(ref Items, Items.Length * 2);
            }

            // Add the item
            metadata.Index    = Length;
            metadata.StoredIn = this;
            Items[Length++]   = new StoredItem()
            {
                Item     = item,
                Metadata = metadata
            };
        }
Exemplo n.º 8
0
        public void Remove(IQuadTreeMonitor <T> monitor, Bound monitoredRegion)
        {
            // remove the stored monitor
            for (int i = 0; i < _monitors.Length; ++i)
            {
                if (ReferenceEquals(_monitors[i].Monitor, monitor))
                {
                    _monitors.Remove(i);
                    break;
                }
            }

            // remove all stored items from the monitor
            for (int i = 0; i < _items.Length; ++i)
            {
                StoredItem item = _items[i];

                if (monitoredRegion.Contains(item.Position))
                {
                    monitor.OnExit(item.Item);
                }
            }
        }
Exemplo n.º 9
0
        private Dictionary <string, object> ConvertStoredItem(StoredItem item)
        {
            var result = new Dictionary <string, object>()
            {
                { "itemName", item.Name },
                { "itemValue", item.BuyPrice },
                { "isHot", item.Hot },
                { "starsystemName", item.StarSystem },
                { "marketID", item.MarketId },
            };

            if (!String.IsNullOrEmpty(item.EngineerModifications))
            {
                var value = new Dictionary <string, object>()
                {
                    { "blueprintName", item.EngineerModifications },
                    { "blueprintLevel", item.Level },
                    { "blueprintQuality", item.Quality },
                };
                result.Add("engineering", value);
            }

            return(result);
        }
Exemplo n.º 10
0
 public void PopulateItems(InventoryList inventoryList)
 {
     // don't want to modify the list in place, instead copy and iterate through that
     // it Just Works
     foreach (Transform oldItem in gridHolder.transform.Cast <Transform>().ToArray())
     {
         // Destroy is called after the Update loop, which screws up the first child selection logic
         // so we do this so it's not shown
         Destroy(oldItem.gameObject);
         oldItem.SetParent(null, false);
     }
     for (int i = inventoryList.items.Count - 1; i >= 0; i--)
     {
         StoredItem storedItem = inventoryList.items[i];
         GameObject g          = Instantiate(
             itemPaneTemplate,
             Vector2.zero,
             Quaternion.identity,
             gridHolder
             );
         g.GetComponent <ItemPane>().PopulateSelfInfo(storedItem);
     }
     gridHolder.GetComponent <SelectFirstChild>().OnEnable();
 }
Exemplo n.º 11
0
 public void CheckState()
 {
     if (wanted != null)
     {
         StoredItem i       = GlobalController.inventory.items.GetItem(wanted);
         bool       hasItem = (i != null);
         if (setDisabled)
         {
             gameObject.SetActive(!hasItem);
         }
         else
         {
             gameObject.SetActive(hasItem);
         }
     }
     else
     {
         bool satisfied = true;
         foreach (Item i in wantedItems)
         {
             if (!GlobalController.inventory.items.HasItem(i))
             {
                 satisfied = false;
                 break;
             }
         }
         if (setDisabled)
         {
             gameObject.SetActive(!satisfied);
         }
         else
         {
             gameObject.SetActive(satisfied);
         }
     }
 }
Exemplo n.º 12
0
 public bool HasItem(StoredItem stored)
 {
     return(HasItem(stored.name));
 }
Exemplo n.º 13
0
 public StoredItem GetItem(StoredItem item)
 {
     return(GetItem(item.name));
 }
Exemplo n.º 14
0
 public bool StackItem(int count = 1)
 {
     return(StoredItem != null?StoredItem.Stack(count) : false);
 }
Exemplo n.º 15
0
    /// <summary>
    ///   Serializes the level to a byte array, with an optional root item. The root item
    ///   and its children, if specified, will be the only things saved
    /// </summary>
    /// <returns> The level data as a byte array </returns>
    /// <param name='urgent'> Whether to save even if serialization is suspended </param>
    /// <param name='id'> Identifier (or null) of an object to be the root of the data serialization </param>
    public static byte[] SerializeLevel(bool urgent, string id)
    {
        LevelData ld;


        using (new Radical.Logging())
        {
            //First we need to know the name of the last level loaded
            using (new UnitySerializer.SerializationScope())
            {
                ld = new LevelData()
                {
                    //The level to reload
                    Name = Application.loadedLevelName
                };
                //All of the currently active uniquely identified objects
                ld.StoredObjectNames = UniqueIdentifier
                                       .AllIdentifiers
                                       .Where(i => string.IsNullOrEmpty(id) || i.Id == id || HasParent(i, id))
                                       .Select(i => i.gameObject)
                                       .Where(go => go != null)
                                       .Where(go =>
                {
                    var shouldSerialize = go.FindInterface <IControlSerializationEx>();
                    return(shouldSerialize == null || shouldSerialize.ShouldSaveWholeObject());
                })
                                       .Where(go =>
                {
                    if (Store == null)
                    {
                        return(true);
                    }
                    var result = true;
                    Store(go, ref result);
                    return(result);
                })
                                       .Select(n =>
                {
                    try
                    {
                        var si = new StoredItem()
                        {
                            Active     = n.active,
                            Components =
                                n.GetComponents <Component>().Select(
                                    c => c.GetType().AssemblyQualifiedName).Distinct().
                                ToDictionary(v => v, v => true),
                            Name           = n.GetComponent <UniqueIdentifier>().Id,
                            GameObjectName = n.name,
                            ParentName     =
                                (n.transform.parent == null ||
                                 n.transform.parent.GetComponent <UniqueIdentifier>() ==
                                 null)
                                                                 ? null
                                                                 : (n.transform.parent.GetComponent <UniqueIdentifier>().
                                                                    Id),
                            ClassId = n.GetComponent <PrefabIdentifier>() != null
                                                                       ? n.GetComponent <PrefabIdentifier>().ClassId
                                                                       : string.Empty
                        };
                        if (n.GetComponent <StoreInformation>())
                        {
                            n.SendMessage("OnSerializing", SendMessageOptions.DontRequireReceiver);
                        }
                        var pf = n.GetComponent <PrefabIdentifier>();
                        if (pf != null)
                        {
                            var components = GetComponentsInChildrenWithClause(n);
                            si.Children    = components.GroupBy(c => c.ClassId).ToDictionary(c => c.Key,
                                                                                             c =>
                                                                                             c.Select(
                                                                                                 i => i.Id)
                                                                                             .ToList());
                        }
                        return(si);
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning("Failed to serialize status of " + n.name + " with error " +
                                         e.ToString());
                        return(null);
                    }
                })
                                       .Where(si => si != null)
                                       .ToList();

                //All of the data for the items to be stored

                var toBeProcessed = UniqueIdentifier
                                    .AllIdentifiers
                                    .Where(o => o.GetComponent <StoreInformation>() != null || o.GetComponent <PrefabIdentifier>() != null)
                                    .Where(i => string.IsNullOrEmpty(id) || i.Id == id)
                                    .Where(i => i != null)
                                    .Select(i => i.gameObject)
                                    .Where(i => i != null)
                                    .Where(go =>
                {
                    var shouldSerialize = go.FindInterface <IControlSerializationEx>();
                    return(shouldSerialize == null || shouldSerialize.ShouldSaveWholeObject());
                })
                                    .Distinct()
                                    .Where(go =>
                {
                    if (Store == null)
                    {
                        return(true);
                    }
                    var result = true;
                    Store(go, ref result);

                    return(result);
                })
                                    .SelectMany(o => o.GetComponents <Component>())
                                    .Where(c =>
                {
                    if (c == null)
                    {
                        return(false);
                    }
                    var tp = c.GetType();
                    return((!(c is IControlSerialization) || (c as IControlSerialization).ShouldSave()) &&
                           !tp.IsDefined(typeof(DoNotSerialize), false) &&
                           !tp.IsDefined(typeof(DontStoreAttribute), true) &&
                           !IgnoreTypes.Contains(tp.FullName));
                })
                                    .Select(c => new
                {
                    Identifier =
                        (StoreInformation)c.gameObject.GetComponent(typeof(StoreInformation)),
                    Component = c
                })
                                    .Where(cp =>
                                           (cp.Identifier.StoreAllComponents ||
                                            cp.Identifier.Components.Contains(cp.Component.GetType().FullName)))
                                    .OrderBy(cp => cp.Identifier.Id)
                                    .ThenBy(cp => cp.Component.GetType().AssemblyQualifiedName).ToList();
                var processed = 0;
                ld.StoredItems = toBeProcessed
                                 .Select(cp =>
                {
                    try
                    {
                        if (Radical.IsLogging())
                        {
                            Radical.Log("<{0} : {1} - {2}>", cp.Component.gameObject.GetFullName(),
                                        cp.Component.GetType().Name,
                                        cp.Component.GetComponent <UniqueIdentifier>().Id);
                            Radical.IndentLog();
                        }
                        var sd = new StoredData()
                        {
                            Type    = cp.Component.GetType().AssemblyQualifiedName,
                            ClassId = cp.Identifier.ClassId,
                            Name    = cp.Component.GetComponent <UniqueIdentifier>().Id
                        };

                        if (CustomSerializers.ContainsKey(cp.Component.GetType()))
                        {
                            sd.Data = CustomSerializers[cp.Component.GetType()].Serialize(cp.Component);
                        }
                        else
                        {
                            sd.Data = UnitySerializer.SerializeForDeserializeInto(cp.Component);
                        }
                        if (Radical.IsLogging())
                        {
                            Radical.OutdentLog();
                            Radical.Log("</{0} : {1}>", cp.Component.gameObject.GetFullName(),
                                        cp.Component.GetType().Name);
                        }
                        processed++;
                        Progress("Storing", (float)processed / (float)toBeProcessed.Count);
                        return(sd);
                    }
                    catch (Exception e)
                    {
                        processed++;
                        Debug.LogWarning("Failed to serialize data (" +
                                         cp.Component.GetType().AssemblyQualifiedName + ") of " +
                                         cp.Component.name + " with error " + e.ToString());
                        return(null);
                    }
                })
                                 .Where(s => s != null)
                                 .ToList();
            }
        }

        var data = UnitySerializer.Serialize(ld);

        return(data);
    }
Exemplo n.º 16
0
 public void PopulateSelfInfo(StoredItem s)
 {
     itemImage.sprite = s.item.itemIcon;
     this.storedItem  = s;
     itemCount.text   = (s.count > 1 ? s.count.ToString() : "");
 }
Exemplo n.º 17
0
    protected override bool Check()
    {
        StoredItem i = GlobalController.inventory.items.GetItem(item.name);

        return((i != null) && i.count >= count);
    }
Exemplo n.º 18
0
 public override void Update()
 {
     if (this.hitWait > 0f)
     {
         this.hitWait -= 0.1f;
     }
     else
     {
         this.hitWait = 0f;
     }
     this._alternate                = !this._alternate;
     this._scanner.alpha            = 0.4f + this._wave.normalized * 0.6f;
     this._projector.alpha          = (0.4f + this._wave.normalized * 0.6f) * this._projectorAlpha;
     this._currentProjection.alpha  = 0.4f + this._projectionFlashWave.normalized * 0.6f;
     this._currentProjection.alpha -= this._glitch * 3f;
     this._currentProjection.alpha *= this._projectorAlpha;
     this._double = Maths.CountDown(this._double, 0.15f, 0f);
     this._glitch = Maths.CountDown(this._glitch, 0.1f, 0f);
     if (Rando.Float(1f) < 0.01f)
     {
         this._glitch = 0.3f;
         this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
         this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
         this._projectorGlitch.flipH  = (Rando.Float(1f) > 0.5f);
     }
     if (Rando.Float(1f) < 0.005f)
     {
         this._glitch = 0.3f;
         this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
         this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
         this._projectorGlitch.flipH  = (Rando.Float(1f) > 0.5f);
         this._useWave = !this._useWave;
     }
     if (Rando.Float(1f) < 0.008f)
     {
         this._glitch = 0.3f;
         this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
         this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
         this._projectorGlitch.flipH  = (Rando.Float(1f) > 0.5f);
         this._useWave = !this._useWave;
         this._double  = 0.6f + Rando.Float(0.6f);
     }
     this._close.Clear();
     if (this._hoverItem != null && this._hoverItem.owner != null)
     {
         this.BreakHoverBond();
     }
     if (this._hoverItem == null)
     {
         Holdable g = Level.Nearest <Holdable>(base.x, base.y, null, null);
         if (g != null && g.owner == null && g != null && g.canPickUp && g.bottom <= this.top && System.Math.Abs(g.hSpeed) + System.Math.Abs(g.vSpeed) < 2f)
         {
             float dist = 999f;
             if (g != null)
             {
                 dist = (this.position - g.position).length;
             }
             if (dist < 24f)
             {
                 this._hoverItem = g;
             }
         }
     }
     else if (System.Math.Abs(this._hoverItem.hSpeed) + System.Math.Abs(this._hoverItem.vSpeed) > 2f || (this._hoverItem.position - this.position).length > 25f)
     {
         this.BreakHoverBond();
     }
     else
     {
         this._hoverItem.position       = Lerp.Vec2Smooth(this._hoverItem.position, this.position + new Vec2(0f, -12f - this._hoverItem.collisionSize.y / 2f + this._projectionWave * 2f), 0.2f);
         this._hoverItem.vSpeed         = 0f;
         this._hoverItem.gravMultiplier = 0f;
     }
     using (System.Collections.Generic.IEnumerator <Thing> enumerator = this._level.things[typeof(Duck)].GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             Duck d = (Duck)enumerator.Current;
             if (!d.dead && (d.position - this.position).length < 64f)
             {
                 this._close.Add(d.profile);
                 this._closeGlitch = false;
             }
         }
     }
     this._closeWait = Maths.CountDown(this._closeWait, 0.05f, 0f);
     for (int i = 0; i < this._close.Count; i++)
     {
         if (this._close.Count == 1)
         {
             this._closeIndex = 0;
         }
         else if (this._close.Count > 1 && i == this._closeIndex && this._closeWait <= 0f)
         {
             this._closeIndex             = (this._closeIndex + 1) % this._close.Count;
             this._closeWait              = 1f;
             this._glitch                 = 0.3f;
             this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
             this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
             this._projectorGlitch.flipH  = (Rando.Float(1f) > 0.5f);
             this._useWave                = !this._useWave;
             this._double                 = 0.6f + Rando.Float(0.6f);
             break;
         }
     }
     if (this._closeIndex >= this._close.Count)
     {
         this._closeIndex = 0;
     }
     if (this._close.Count == 0)
     {
         if (!this._closeGlitch)
         {
             this._closeWait = 1f;
             this._glitch    = 0.3f;
             this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
             this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
             this._projectorGlitch.flipH  = (Rando.Float(1f) > 0.5f);
             this._useWave     = !this._useWave;
             this._double      = 0.6f + Rando.Float(0.6f);
             this._closeGlitch = true;
         }
         this._projectorAlpha    = Maths.CountDown(this._projectorAlpha, 0.1f, 0f);
         this._currentProjection = this._none;
     }
     else
     {
         StoredItem item = GetStoredItem(this._close[this._closeIndex]);
         if (item.sprite == null)
         {
             this._currentProjection = this._none;
         }
         else
         {
             this._currentProjection = item.sprite;
         }
         this._projectorAlpha = Maths.CountUp(this._projectorAlpha, 0.1f, 1f);
     }
     this._projectorGlitch.alpha = this._glitch * this._projectorAlpha;
     base.Update();
 }
        public void IsWebRequestValid(dynamic requestResponse)
        {
            //var requestResponseCode = requestResponse.code;
            if (requestResponse.code == "INVALID_UPC")//TODO Handle all the codes
            {
                //Console.WriteLine("Not found on UPCItemDB. Set item aside, you'll have to manually enter data later.\n");
                requestsRemaining.Text = "Invalid UPC. If this persists, please add item manually.";
            }
            else if (requestResponse.code == "TOO_FAST")
            {
                requestsRemaining.Text = "Scanning too fast. Try again in ~30sec.";

                StoredItem storedItem = new StoredItem(CURRENT_ITEM_UPC);
                StoredItemsList.Add(storedItem);
            }
            else if (requestResponse.code == "OK" && requestResponse.total == 0)
            {
                //Console.WriteLine("Not found on UPCItemDB. Set item aside, you'll have to manually enter data later.\n");
                requestsRemaining.Text = "Item not found. Item must be added manually.";
            }
            else
            {
                long   webEan      = requestResponse.items[0].ean;
                string webTitle    = requestResponse.items[0].title;
                long   webUpc      = requestResponse.items[0].upc;
                string webDesc     = requestResponse.items[0].description;
                string webBrand    = requestResponse.items[0].brand;
                string webModel    = requestResponse.items[0].model;
                string webWeight   = requestResponse.items[0].weight;
                string webCategory = requestResponse.items[0].category; //TODO #1 go through this string and pull out the category


                string imageURL = requestResponse.items[0].images[0]; //TODO Some items do not have an image. (returns null?) Need to handle this
                                                                      //TEST WITH 20LB BAG OF SAFEWAY RICE

                // FORMATTING ALL THE TEXT TO HAVE DOUBLE SINGLE QUOTE SO SQL QUERY IS NOT ENDED IN THE WRONG PLACE
                string formattedPurchaseGroup = SQLArguementFormatter(recieptbarcodeInput.Text);
                string formattedTitle         = SQLArguementFormatter(webTitle);
                itemName.Text = formattedTitle;
                string formattedDesc = SQLArguementFormatter(webDesc);
                descriptionTextbox.Text = formattedDesc;
                string formattedBrand = SQLArguementFormatter(webBrand);
                itemBrand.Text = formattedBrand;
                string formattedModel = SQLArguementFormatter(webModel);
                itemModel.Text = formattedModel;
                string formattedWeight = SQLArguementFormatter(webWeight);
                itemWeight.Text = formattedWeight;
                string formattedCategory = SQLArguementFormatter(webCategory);
                itemCategory.Text = formattedCategory; //TODO Refer to #1
                itemImageURL.Text = imageURL;

                //NUMBER OF SCANS REMAINING FROM UPCITEMDB API 100/day
                //MUST SCAN ITEM BEFORE IT WILL DISPLAY. COUNT COMES FROM HEADER.
                Globals.API_CALL_COUNT = int.Parse(XRateLimitRemaining.ToString());
                requestsRemaining.Text = "Number of scans remaining: " + XRateLimitRemaining.ToString();

                DateTime scannedDate = DateTime.Today;
                int      quanNeeded  = 1;

                //THIS IS TRULY PEAK GARBAGE CODE AND CODE PLACEMENT. YOU GOTTA MOVE THIS IF YOU EVER WANT THIS TO BE READABLE TO FUTURE YOU.

                /*
                 * @userId VARCHAR(11),
                 *                 @purchaseGroup NVARCHAR(255),
                 *                 @ean bigint,
                 *                 @title NVARCHAR(255),
                 *                 @upc bigint,
                 *             @description nvarchar(max),
                 *                 @brand nvarchar(255),
                 *                 @model nvarchar(255),
                 *                 @weight nvarchar(255),
                 *                 @category nvarchar(255),
                 *                 @quantity int,
                 *                 @scandate date,
                 *                 @imageurl nvarchar(max)
                 *
                 */
                if (auto_switch.IsOn)
                {
                    using (SqlConnection myConnection = new SqlConnection(Globals.SQL_DATA_CONNECTION))
                    {
                        SqlCommand cmd = new SqlCommand("insertData", myConnection)
                        {
                            CommandType = CommandType.StoredProcedure
                        };
                        cmd.Parameters.Add(new SqlParameter("@userId", Globals.uid));
                        cmd.Parameters.Add(new SqlParameter("@purchaseGroup", formattedPurchaseGroup));
                        cmd.Parameters.Add(new SqlParameter("@ean", webEan));
                        cmd.Parameters.Add(new SqlParameter("@title", formattedTitle));
                        cmd.Parameters.Add(new SqlParameter("@upc", webUpc));
                        cmd.Parameters.Add(new SqlParameter("@description", formattedDesc));
                        cmd.Parameters.Add(new SqlParameter("@brand", formattedBrand));
                        cmd.Parameters.Add(new SqlParameter("@model", formattedModel));
                        cmd.Parameters.Add(new SqlParameter("@weight", webWeight));
                        cmd.Parameters.Add(new SqlParameter("@category", formattedCategory));
                        cmd.Parameters.Add(new SqlParameter("@quantity", quanNeeded));
                        cmd.Parameters.Add(new SqlParameter("@scandate", scannedDate));
                        cmd.Parameters.Add(new SqlParameter("@imageurl", imageURL));

                        myConnection.Open();
                        int rowAffected = cmd.ExecuteNonQuery();
                        if (rowAffected == 1)
                        {
                            myConnection.Close();
                        }
                        else
                        {
                            myConnection.Close();
                        }
                    }
                    barcodeInput.SelectAll();
                }
                if (!auto_switch.IsOn)
                {
                    //DO NOTHING?
                    //I MEAN ALL THE TEXT BOXES HAVE THE TEXT IF ITS FOUND, IF NOT ENTER IT YOURSELF.
                }
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Returns a deep copy of the item to avoid pass by reference errors with GetItemList
 /// </summary>
 /// <param name="item">What item to copy</param>
 /// <returns>A deep copy of the given item</returns>
 private static StoredItem Copy(StoredItem item)
 {
     return(item is Equippable ? new Equippable((Equippable)item) : new StoredItem(item));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Adds a stored item without checking any validity
 /// <param name="storedItem">The item to store</param>
 /// </summary>
 public void AddItemUnchecked(StoredItem storedItem)
 {
     AddItemUnchecked(storedItem.Item, storedItem.Position);
 }
Exemplo n.º 22
0
    [SyncVar] private bool inUse; // clients cannot use a storage if it is already in use

    public void AddItem(StoredItem i)
    {
        items.Add(i);
    }
Exemplo n.º 23
0
        /// <summary>
        /// Ensures this container has the same state as the one given, using the least amount of operations
        /// </summary>
        /// <param name="otherContainer">The container to match</param>
        public void Reconcile(Container otherContainer)
        {
            Size = otherContainer.Size;

            if (Empty)
            {
                items.AddRange(otherContainer.items);
                OnContainerChanged(otherContainer.Items, ContainerChangeType.Add);
                return;
            }

            if (otherContainer.Empty)
            {
                Dump();
                return;
            }

            // Loop through all items to find the first index of divergence
            // We can assume that all items after that point have been changed, as items are always inserted at the end
            List <Item> movedItems   = new List <Item>();
            int         changedIndex = -1;

            for (var i = 0; i < items.Count; i++)
            {
                StoredItem storedItem         = items[i];
                StoredItem otherContainerItem = otherContainer.items[i];
                if (storedItem.Item != otherContainerItem.Item)
                {
                    changedIndex = i;
                    break;
                }

                if (storedItem.Position != otherContainerItem.Position)
                {
                    movedItems.Add(storedItem.Item);
                }
            }

            // Invoke move logic if any element has moved
            if (movedItems.Count > 0)
            {
                OnContainerChanged(movedItems, ContainerChangeType.Move);
            }

            // Nothing actually changed
            if (changedIndex == -1)
            {
                return;
            }

            // Remove all items after first divergence
            Item[] removedItems = new Item[items.Count - changedIndex];
            for (var i = changedIndex; i < items.Count;)
            {
                items.RemoveAt(i);
            }
            OnContainerChanged(removedItems.AsEnumerable(), ContainerChangeType.Remove);

            // Add all remaining items
            for (int i = changedIndex; i < otherContainer.ItemCount; i++)
            {
                items.Add(otherContainer.items[i]);
            }
            OnContainerChanged(otherContainer.Items.Skip(changedIndex + 1), ContainerChangeType.Add);
        }
Exemplo n.º 24
0
 public bool UseItem()
 {
     return(StoredItem != null?StoredItem.Use() : false);
 }