Example #1
0
    public void LeaveShop()
    {
        _nowShop = null;
        int sumPrice = 0;

        List <Item.ItemSuper> buyable_items = new List <Item.ItemSuper>();

        foreach (var i in _basket)
        {
            //代金以上のお金が財布に残っていたら
            if (_wallet.IsBuyable(sumPrice + Item.ItemSuper.GetPriceSum(i)))
            {
                sumPrice += Item.ItemSuper.GetPriceSum(i);
                buyable_items.Add(i);

                //プレイヤー全体の総所持数に追加
                i.AddPlayerDistribution(i.GetNum());
                //総在庫数からマイナス
                i.SubShopDistribution(i.GetNum());
            }
            else
            {
                break;
            }
        }
        _wallet.Pay(sumPrice);
        foreach (var i in buyable_items)
        {
            Item.ItemSuper tmp_item = _inventry.AddItem(i, 0);

            //アイテムがインベントリに収まらずあふれた時
            if (tmp_item != Item.ItemSuper.Null)
            {
                //超過分のお金の払い戻し
                _wallet.Receipt(Item.ItemSuper.GetPriceSum(tmp_item));


                //プレイヤー全体の総所持数からマイナス
                tmp_item.SubPlayerDistribution(tmp_item.GetNum());
                //総在庫数に追加
                _nowShop.ReturnItem(tmp_item);

                break;
            }
        }
        _basket.Clear();
    }
Example #2
0
    //Update内で実行 アクションを起こして最近接アイテムをカゴに入れる
    private void Shopping()
    {
        //入店時のみ処理
        if (_nowShop != null)
        {
            // A(仮) が押されたら ボタンは後で変更     キーボードは「 Z 」
            if (Key.A.Down)
            {
                //プレイヤーがアイテムを買う処理 ---------------------------------------------------------------
                if (_nowShop._IsSalesShop)
                {
                    Debug.Log(_nowShop.gameObject.name);
                    Item.ItemSuper item = _nowShop.NearestItem(transform.position);

                    //アイテムを取得したときお金が足りなくなるなら買えない
                    if (!_wallet.IsBuyable(GetBasketSum() + Item.ItemSuper.GetPriceSum(item)))
                    {
                        Debug.Log("お金足りないぞ");
                        return;
                    }
                    if (item == Item.ItemSuper.Null)
                    {
                        Debug.Log("近くにないよ");
                        return;
                    }

                    //Debug.Log( item.GetName() +" : " + item._object.transform.position.ToString());

                    //取得可能な距離にいたら
                    if (GettableDis > Vector3.Distance(item._object.transform.position, gameObject.transform.position))
                    {
                        Debug.Log("gettableItem is : " + item._object.name);
                        _basket.Add(item);
                        _nowShop.RemoveItem(item._object.name);
                    }
                }
                else  //プレイヤーがアイテムを売る処理 ------------------------------------------------------------
                {
                }
            }
        }
    }
Example #3
0
 //アイテムの購入金額    買値 * 個数
 public static int GetPriceSum(ItemSuper item)
 {
     return(item.GetBuyPrice() * item.GetNum());
 }