/// <summary>
    /// 1 数据从哪来
    /// 2 数据信息
    /// </summary>
    public void SetData(BackPackItem item)
    {
        if (item == null)
        {
            Debug.LogError("Item is null,Please check it");
            return;
        }
        this.mItem = item;

        this.BgIcon.sprite = Resources.Load <Sprite>("Textures/Item/" + this.mItem.ItemBgIcon);
        this.BgIcon.sprite = Resources.Load <Sprite>("Textures/Item/" + this.mItem.ItemIcon);
        this.Count.text    = mItem.ItemCount.ToString();
        this.IsChip.SetActive(mItem.mItemType == BackPackItem.ItemType.Chips);

        switch (this.mItem.ItemQuality)
        {
        case 1:
            this.BgIcon.color = Color.white;
            break;

        case 2:
            this.BgIcon.color = Color.blue;
            break;

        case 3:
            this.BgIcon.color = Color.red;
            break;

        default:
            break;
        }
    }
Exemple #2
0
    public void DecodeJson()
    {
        //    for(int i = 0; i < this.ItemConfig.Count; i++)
        //    {
        //        int itemID = (int)ItemConfig[i]["ItemID"]
        //    }
        foreach (JsonData data in ItemConfig)
        {
            var itemID        = (int)data["ItemID"];
            var itemName      = data["ItemName"].ToString();
            var itemDesc      = data["ItemDesc"].ToString();
            var itemType      = (int)data["ItemType"];
            var itemIcon      = data["ItemIcon"].ToString();
            var itemBgIcon    = data["ItemBgIcon"].ToString();
            var itemCount     = (int)data["ItemCount"];
            var itemQuality   = (int)data["ItemQuality"];
            var itemOpreation = (int)data["ItemOpreation"];

            Debug.LogError(itemID + " " + itemName + " " + itemDesc + " " + itemType + " "
                           + itemIcon + " " + itemBgIcon + " " + itemCount + " " + itemQuality + " " + itemOpreation + " ");
            BackPackItem backPackItem = new BackPackItem(itemID, itemName, itemDesc, itemType,
                                                         itemIcon, itemBgIcon, itemCount, itemQuality, itemOpreation);
            BackPackItemList.Add(backPackItem);
        }
    }
    public void SaveItemData(BackPackItem item)
    {
        if (item == null)
        {
            return;
        }

        int itemID = -1;

        for (int i = 0; i < BackPackItemList.Count; i++)
        {
            if (BackPackItemList[i].ItemID == item.ItemID)
            {
                BackPackItemList[i].ItemCount++;
                itemID = i;
                break;
            }
        }

        if (itemID == -1)
        {
            BackPackItemList.Add(item);
        }

        SaveBackPackData();
    }
Exemple #4
0
    ///<summary>
    ///1 数据 从哪里来?
    ///2 什么样的数据传过来?
    ///</summary>

    public void SetData(BackPackItem item)
    {
        if (item == null)
        {
            Debug.LogError("item is null ,please check it");
            return;
        }
        this.item = item;

        this.BgIcon.sprite = Resources.Load <Sprite>("Art/" + this.item.ItemBgIcon);
        this.Icon.sprite   = Resources.Load <Sprite>("Art/" + this.item.ItemName);
        this.Count.text    = this.item.ItemCount.ToString();

        /*
         * //this.IsChip.SetActive(this.item.ItemType == BackPackItem.BackPackItemType.Chips);
         * switch (item.ItemQuality)
         * {
         *  case 1:
         *      this.BgIcon.color = Color.white;
         *      break;
         *  case 2:
         *      this.BgIcon.color = Color.blue;
         *      break;
         *  case 3:
         *      this.BgIcon.color = Color.red;
         *      break;
         *  default:
         *      break;
         * }
         */
    }
Exemple #5
0
        /// <summary>
        /// Extends the base version with a check for weight capacity
        /// </summary>
        public override void AddItem(BackPackItem item)
        {
            if (item.Weight > WeightCapacityLeft)
            {
                throw new ArgumentException("Oops, you over-stuffed the BackPack!!");
            }

            base.AddItem(item);
        }
        /// <summary>
        /// Adds the given item to the container. An exception is thrown if
        /// an item with the same description is already in the container.
        /// </summary>
        public virtual void AddItem(BackPackItem item)
        {
            if (_items.ContainsKey(item.Description))
            {
                throw new ArgumentException(item.Description + " is already in the " + _containerDescription + "!");
            }

            _items.Add(item.Description, item);
        }
Exemple #7
0
 public void SetData(BackPackItem item)
 {
     itemID           = item.ItemID;
     this.Icon.sprite = Resources.Load <Sprite>("Art/" + item.ItemName);
     //this.Name.text = item.ItemName;
     this.Description.text = item.ItemDesc;
     this.UseButton.gameObject.SetActive(true);
     SetInfoState(true);
 }
        /// <summary>
        /// The solver follows these steps:
        /// 1) Select the "best" item from the Vault (see PickBestItemFromVault).
        ///    If (a description of) an item is returned, then
        ///    2) Remove the item from the Vault.
        ///    3) Add the item to the Backpack.
        ///    4) Call Solve again (the weight capacity will now be reduced).
        /// </summary>
        public override void Solve(ItemVault theItemVault, BackPack theBackPack)
        {
            string description = PickNextItemFromVault(theItemVault, theBackPack.WeightCapacityLeft);

            if (description != string.Empty)
            {
                BackPackItem item = theItemVault.RemoveItem(description);
                theBackPack.AddItem(item);
                Solve(theItemVault, theBackPack);
            }
        }
Exemple #9
0
 /// <summary>
 /// Naive solver implementation (but it's recursive!)
 /// </summary>
 public override void Solve(double capacityLeft)
 {
     // Keep adding the first element from the vault, until
     // the first element cannot fit into the backpack...
     if (TheVault.Items[0].Weight <= capacityLeft)
     {
         BackPackItem item = TheVault.RemoveItem(TheVault.Items[0].Description);
         TheBackPack.AddItem(item);
         Solve(TheBackPack.WeightCapacityLeft);
     }
 }
Exemple #10
0
        /// <summary>
        /// The solver follows these steps:
        /// 1) Select the "best" item from the Vault (see PickBestItemFromVault).
        ///    If (a description of) an item is returned, then
        ///    2) Remove the item from the Vault.
        ///    3) Add the item to the Backpack.
        ///    4) Call Solve again (the weight capacity will now be reduced).
        /// </summary>
        public override void Solve(double capacityLeft)
        {
            string description = PickBestItemFromVault(capacityLeft);

            if (description != string.Empty)
            {
                BackPackItem item = TheVault.RemoveItem(description);
                TheBackPack.AddItem(item);
                Solve(TheBackPack.WeightCapacityLeft);
            }
        }
Exemple #11
0
    public void SetData(BackPackItem item)
    {
        this.Name.text = item.ItemName;
        this.Desc.text = item.ItemDesc;

        //装备显示出售和装备按钮,碎片显示分解和合成按钮
        this.SellBtn.gameObject.SetActive(item.mItemType == BackPackItem.ItemType.Equip);
        this.EquipBtn.gameObject.SetActive(item.mItemType == BackPackItem.ItemType.Equip);
        this.ConpoundBtn.gameObject.SetActive(item.mItemType == BackPackItem.ItemType.Chips);
        this.SynthesisBtn.gameObject.SetActive(item.mItemType == BackPackItem.ItemType.Chips);
    }
        /// <summary>
        /// Removes and returns the item corresponding to the given description.
        /// An exception is thrown if no matching item is found.
        /// </summary>
        public virtual BackPackItem RemoveItem(string description)
        {
            if (!_items.ContainsKey(description))
            {
                throw new ArgumentException(description + " is not in the " + _containerDescription + "!");
            }

            BackPackItem removedItem = _items[description];

            _items.Remove(description);

            return(removedItem);
        }
    private void DecodeJson()
    {
        BackPackItemList.Clear();
        for (int i = 0; i < this.ItemConfig.Count; i++)
        {
            int    itemID        = (int)this.ItemConfig[i]["ItemID"];
            int    itemType      = (int)this.ItemConfig[i]["ItemType"];
            string itemName      = this.ItemConfig[i]["ItemName"].ToString();
            string itemDesc      = this.ItemConfig[i]["ItemDesc"].ToString();
            string itemIcon      = this.ItemConfig[i]["ItemIcon"].ToString();
            string itemBgIcon    = this.ItemConfig[i]["ItemBgIcon"].ToString();
            int    itemCount     = (int)this.ItemConfig[i]["ItemCount"];
            int    itemQuality   = (int)this.ItemConfig[i]["ItemQuality"];
            int    itemOperation = (int)this.ItemConfig[i]["ItemOpreation"];

            BackPackItem item = new BackPackItem(itemID, itemName, itemDesc, itemType, itemIcon, itemBgIcon, itemCount, itemQuality, itemOperation);
            this.BackPackItemList.Add(item);
        }
    }
        public override void Solve(double capacityLeft)
        {
            //sort by weight
            List <BackPackItem> items = new List <BackPackItem>();

            foreach (BackPackItem item in TheVault.Items)
            {
                items.Add(item);
            }
            items = items.OrderBy(o => o.Weight).ToList();
            items.Reverse();


            if (items[0].Weight <= capacityLeft)
            {
                BackPackItem item = TheVault.RemoveItem(items[0].Description); //vault remove item
                TheBackPack.AddItem(items[0]);                                 //backpack add item
                Solve(TheBackPack.WeightCapacityLeft);                         //recursive
            }
        }
Exemple #15
0
        public override void Solve(double capacityLeft)
        {
            BackPackItem currentItem = TheVault.Items[0];

            foreach (BackPackItem item in TheVault.Items)
            {
                if ((item.Value / item.Weight) > (currentItem.Value / currentItem.Weight))
                {
                    currentItem = item;
                }
            }

            if (currentItem.Weight <= capacityLeft)
            {
                TheVault.RemoveItem(currentItem.Description);
                TheBackPack.AddItem(currentItem);
                Solve(TheBackPack.WeightCapacityLeft);
            }
            else     //most valuable item (by ratio) weighs more than we have room for
            {
                List <BackPackItem> lowWeightItems = new List <BackPackItem>();
                foreach (BackPackItem item in TheVault.Items)
                {
                    if (item.Weight < capacityLeft)
                    {
                        lowWeightItems.Add(item);
                    }
                }
                lowWeightItems = lowWeightItems.OrderBy(o => o.Value).ToList();

                if (lowWeightItems.Count > 0)
                {
                    if (lowWeightItems[0].Weight <= capacityLeft)
                    {
                        TheVault.RemoveItem(lowWeightItems[0].Description);
                        TheBackPack.AddItem(lowWeightItems[0]);
                        Solve(TheBackPack.WeightCapacityLeft);
                    }
                }
            }
        }
        /// <summary>
        /// This method picks the "best" item currently in the Vault.
        /// "Best" is defined as the item for which it holds that:
        ///   1) The weight of the item does not exceed the given limit.
        ///   2) No other item (for which 1) holds) has a higher
        ///      "actual item value". The calculation of "actual item value"
        ///      is deferred to derived classes.
        /// </summary>
        /// <returns>
        /// Identifier for the "best" item (String.Empty if no item found)
        /// </returns>
        private string PickNextItemFromVault(ItemVault theItemVault, double weightLimit)
        {
            double       bestValue = 0;
            BackPackItem bestItem  = null;

            foreach (var item in theItemVault.Items)
            {
                if (item.Weight <= weightLimit)
                {
                    double candidateValue = ActualItemValue(item);

                    if (candidateValue > bestValue)
                    {
                        bestValue = candidateValue;
                        bestItem  = item;
                    }
                }
            }

            return((bestItem != null) ? bestItem.Description : string.Empty);
        }
Exemple #17
0
        /// <summary>
        /// This method picks the "best" item currently in the Vault.
        /// "Best" is defined as the item for which it holds that:
        ///   1) The weight of the item does not exceed the capacity.
        ///   2) No other item (for which 1) holds) has a higher
        ///      "actual item value". The calculation of "actual item value"
        ///      is deferred to derived classes.
        /// </summary>
        private string PickBestItemFromVault(double capacityLeft)
        {
            double       bestActualItemValue = 0;
            BackPackItem bestItem            = null;

            foreach (var item in TheVault.Items)
            {
                if (item.Weight <= capacityLeft)
                {
                    double candidateActualItemValue = ActualItemValue(item);

                    if (candidateActualItemValue > bestActualItemValue)
                    {
                        bestActualItemValue = candidateActualItemValue;
                        bestItem            = item;
                    }
                }
            }

            return((bestItem != null) ? bestItem.Description : string.Empty);
        }
 /// <summary>
 /// A derived class can implement this method, to provide a
 /// specific definition of "actual item value"
 /// </summary>
 protected abstract double ActualItemValue(BackPackItem item);
 protected override double ActualItemValue(BackPackItem item)
 {
     return(item.Value);
 }
Exemple #20
0
 protected override double ActualItemValue(BackPackItem item)
 {
     return((item.Value + 5) / item.Weight);
 }