コード例 #1
0
ファイル: ShopUI.cs プロジェクト: AlayaElla/sangharama
    //购买物品
    public void BuyedGoods(MyCharacterController.ShopGood goods)
    {
        //如果货架上有商品则移除
        if (goodslist[goods.slotID - 1].Name != null && goodslist[goods.slotID - 1].ID != 0)
        {
            goodslist[goods.slotID - 1] = new CharBag.Goods();

            string path = goods.slotID.ToString() + "/itemIcon";
            transform.Find(path).GetComponent <SpriteRenderer>().sprite = null;

            //取消显示价格
            string priceiconpath = goods.slotID.ToString() + "/price/icon";
            string pricepath     = goods.slotID.ToString() + "/price/text";
            transform.Find(priceiconpath).gameObject.SetActive(false);
            transform.Find(pricepath).gameObject.SetActive(false);

            questManager.CheckQuestListWithGoods(QuestManager.QuestTypeList.SellGoods, goods.goods, 0);

            PlayerData.ShopGoodsData.SaveShopGoods(goodslist);
            //更新物品信息
            PlayerInfo.AddGoodsInfo(goods.goods.MateriralType, goods.goods.ID, PlayerInfo.GoodsInfoType.SellCount);
        }
        else
        {
            Debug.Log("can't remove good:" + goods.goods.Name + " ,because don't have!");
        }
    }
コード例 #2
0
    CharBag.Goods CreateGoods()
    {
        CharBag.Goods goods = new CharBag.Goods();
        goods.Property = new int[4];

        for (int i = 0; i < PropertyBox.Count; i++)
        {
            //如果大于最大个数则忽略
            if (i >= 4)
            {
                break;
            }
            PropertyElementBase p = (PropertyElementBase)PropertyBox[i];
            goods.Property[i] = p.Property.ID;
        }

        goods.Quality = Quality;
        goods.Number  = 1;
        goods.Name    = recipe.Name;

        string target = recipe.Target;

        if (target[0] == char.Parse("0"))
        {
            string mat_str = target.Substring(target.IndexOf(",") + 1);
            goods.MateriralType = 0;
            goods.ID            = int.Parse(mat_str);
        }
        else if (target[0] == char.Parse("1"))
        {
            string mat_str = target.Substring(target.IndexOf(",") + 1);
            goods.MateriralType = 1;
            goods.ID            = int.Parse(mat_str);
        }

        goods.Type          = Materiral.GetTypeByMaterialID(goods.MateriralType, goods.ID);
        goods.MaterialEffet = QualityEffectID;

        //计算价格
        goods.Price = Materiral.GetMaterialPrice(goods.MateriralType, goods.ID);
        goods       = CharBag.SetPrice(goods);

        //添加道具
        goods.UID = CharBag.AddGoods(goods);

        questManager.CheckQuestListWithGoods(QuestManager.QuestTypeList.ComposeGoods, goods, 0);
        //更新物品信息
        PlayerInfo.AddGoodsInfo(goods.MateriralType, goods.ID, PlayerInfo.GoodsInfoType.RecipeCount);

        //删除道具
        foreach (SlotBox slot in SlotList.Values)
        {
            CharBag.RemoveGoods(slot.slot.UID);
        }

        return(goods);
    }
コード例 #3
0
ファイル: ShopUI.cs プロジェクト: AlayaElla/sangharama
    //上架商品
    void ClickInBag(GameObject go, object parameter)
    {
        Parameter.Box p     = (Parameter.Box)parameter;
        CharBag.Goods goods = (CharBag.Goods)p.obj;

        //如果货架上有商品,则添加道具到背包
        if (goodslist[p.ID - 1].Name != null && goodslist[p.ID - 1].ID != 0)
        {
            CharBag.AddGoods(goodslist[p.ID - 1]);
        }

        //添加选中的商品到商品列
        goodslist[p.ID - 1] = goods;
        string path = p.ID.ToString() + "/itemIcon";

        transform.Find(path).GetComponent <SpriteRenderer>().sprite = Materiral.GetMaterialIcon(goods.MateriralType, goods.ID);

        //显示商品价格
        string priceiconpath = p.ID.ToString() + "/price/icon";
        string pricepath     = p.ID.ToString() + "/price/text";

        transform.Find(priceiconpath).gameObject.SetActive(true);
        transform.Find(pricepath).gameObject.SetActive(true);
        transform.Find(pricepath).GetComponent <TextMesh>().text = goods.Price.ToString();


        //移除背包中的商品
        CharBag.RemoveGoods(goods.UID);

        _bagInstance.CloseBagMenu(gameObject);
        ChangeRecipeUiState();

        PlayerData.ShopGoodsData.SaveShopGoods(goodslist);
        CharBag.SaveBagGoods();

        questManager.CheckQuestListWithGoods(QuestManager.QuestTypeList.PutGoods, goods, 0);

        //更新物品信息
        PlayerInfo.AddGoodsInfo(goods.MateriralType, goods.ID, PlayerInfo.GoodsInfoType.PutCount);
    }
コード例 #4
0
    //通过进入地图的id筛选出道具,然后通过权重选出拾取的东西。
    //如果以后会有专门进入地图的设定的话,则可以吧判断地图id筛选道具列表的方法单独移出。
    public void CollectionAction(int ap, RectTransform rect)
    {
        Debug.Log("mine:" + ap);

        //筛选出可以掉落的道具
        int       mapid = ap;
        ArrayList List  = new ArrayList();

        int max = 0;

        foreach (CollectionMap materiral in CollectionList)
        {
            if (materiral.Map == mapid)
            {
                List.Add(materiral);
                //获取随机范围
                max += materiral.Weight;
            }
        }

        //随机权重,选出拾取哪个道具
        CharBag.Goods dropMa = new CharBag.Goods();
        dropMa.Property = new int[4];

        int point = Random.Range(1, max);
        int check = 0;

        foreach (CollectionMap materiral in List)
        {
            check += materiral.Weight;

            if (check >= point)
            {
                //指定掉落的材料
                dropMa.MateriralType = materiral.MateriralType;

                dropMa.ID = materiral.ID;
                //指定数量,后期会修改为需要指定数量
                dropMa.Number = 1;

                //随机品质
                dropMa.Quality = Random.Range(materiral.RandomQuality[0], materiral.RandomQuality[1]);

                //随机属性;随机4个属性
                int random_max = 0;
                int propcount  = 0;
                for (int i = 0; i < materiral.RandomProperty.Length / 2; i++)
                {
                    random_max += materiral.RandomProperty[i, 1];
                }

                for (int index = 0; index < 4; index++)
                {
                    if (materiral.PropertyProbability < Random.Range(1, 100))
                    {
                        continue;
                    }

                    int _point = Random.Range(1, random_max);
                    int _check = 0;
                    //指定随机属性
                    for (int i = 0; i < materiral.RandomProperty.Length / 2; i++)
                    {
                        _check += materiral.RandomProperty[i, 1];
                        if (_check >= _point)
                        {
                            dropMa.Property[propcount] = materiral.RandomProperty[i, 0];
                            propcount++;
                            break;
                        }
                    }
                }
                break;
            } //endif
        }     //endforech

        //获取名称
        if (dropMa.MateriralType == 0)
        {
            Materiral.Items dorp_item = Materiral.FindItemByID(dropMa.ID);
            dropMa.Name = dorp_item.Name;
            //设定基础价格,之后还需要计算
            dropMa.Price = dorp_item.Price;

            //获取type
            dropMa.Type = Materiral.GetTypeByMaterialID(dropMa.MateriralType, dropMa.ID);
        }   //item
        else if (dropMa.MateriralType == 1)
        {
            Materiral.Minds drop_mind = Materiral.FindMindByID(dropMa.ID);
            dropMa.Name = drop_mind.Name;
            //设定基础价格,之后还需要计算
            dropMa.Price = drop_mind.Price;

            //获取type
            dropMa.Type = Materiral.GetTypeByMaterialID(dropMa.MateriralType, dropMa.ID);
        }   //mind

        //计算价格
        dropMa = CharBag.SetPrice(dropMa);
        //添加物品
        dropMa.UID = CharBag.AddGoods(dropMa);

        questManager.CheckQuestListWithGoods(QuestManager.QuestTypeList.CollectGoods, dropMa, ap);
        //更新物品信息
        PlayerInfo.AddGoodsInfo(dropMa.MateriralType, dropMa.ID, PlayerInfo.GoodsInfoType.CollectCount);
        eventmanager.PreCheckEventList(1);
        ShowMaterialIcon(dropMa, rect);
    }