示例#1
0
        /// <summary>
        /// 使用物品
        /// </summary>
        /// <param name="Id">Identifier.</param>
        public void UseItem(int id)
        {
            db = OpenDb();
            string           itemId   = "";
            ItemType         type     = ItemType.None;
            int              num      = 0;
            SqliteDataReader sqReader = db.ExecuteQuery("select ItemId, Type, Num from BagTable where Id = " + id);

            if (sqReader.Read())
            {
                itemId = sqReader.GetString(sqReader.GetOrdinal("ItemId"));
                type   = (ItemType)sqReader.GetInt32(sqReader.GetOrdinal("Type"));
                num    = sqReader.GetInt32(sqReader.GetOrdinal("Num"));
            }
            db.CloseSqlConnection();
            if (type != ItemType.None && num > 0)
            {
                ItemData item;
                switch (type)
                {
                case ItemType.Food:
                    if (UserModel.CurrentUserData.PositionStatu == UserPositionStatusType.InArea)
                    {
                        Eat(id, num);
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show("野外闯荡江湖时才能吃干粮");
                    }
                    break;

                case ItemType.Weapon:
                    item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId);
                    if (AddNewWeapon(item.StringValue, ""))
                    {
                        WeaponData weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", item.StringValue);
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(weapon.Quality), weapon.Name), Color.white, 30);

                        //删除兵器盒
                        db = OpenDb();
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                        db.CloseSqlConnection();
                        //重新加载背包数据
                        GetBagPanelData();
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show("兵器匣已满,请先整理兵器匣");
                    }
                    break;

                case ItemType.Book:
                    item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId);
                    BookData book = JsonManager.GetInstance().GetMapping <BookData>("Books", item.StringValue);
                    if (AddNewBook(item.StringValue, ""))
                    {
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(book.Quality), book.Name), Color.white, 30);

                        //删除秘籍盒
                        db = OpenDb();
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                        db.CloseSqlConnection();
                        //重新加载背包数据
                        GetBagPanelData();
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show(string.Format("你已经习得<color=\"{0}\">{1}</color>, 无需再研读", Statics.GetQualityColorString(book.Quality), book.Name));
                    }
                    break;

                case ItemType.RandomSecre:     //打开随机诀要锦囊
                    item     = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId);
                    db       = OpenDb();
                    sqReader = db.ExecuteQuery("select count(*) as num from BookSecretsTable where BelongToRoleId = '" + currentRoleId + "'");
                    bool isSecretsFull = false;
                    if (sqReader.Read())
                    {
                        isSecretsFull = sqReader.GetInt32(sqReader.GetOrdinal("num")) >= MaxSecretNumOfBag;
                    }
                    if (!isSecretsFull)
                    {
                        //添加新的诀要
                        SecretData secret = Statics.CreateNewSecret(Statics.GetRandomSecretType(item.StringValue), QualityType.White);
                        db.ExecuteQuery("insert into BookSecretsTable (SecretData, T, Q, BelongToBookId, BelongToRoleId) values('" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(secret)) + "', " + ((short)secret.Type) + ", " + ((short)secret.Quality) + ", '', '" + currentRoleId + "')");
                        PlayerPrefs.SetString("AddedNewBookFlag", "true");
                        PlayerPrefs.SetString("AddedNewSecretFlag", "true");
                        Messenger.Broadcast(NotifyTypes.MakeRoleInfoPanelRedPointRefresh);
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(secret.Quality), secret.Name), Color.white, 30);
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                        db.CloseSqlConnection();
                        //重新加载背包数据
                        GetBagPanelData();
                        SoundManager.GetInstance().PushSound("ui0004");
                    }
                    else
                    {
                        AlertCtrl.Show(string.Format("诀要背包上限为{0},请先清理背包", MaxSecretNumOfBag));
                    }
                    break;

                default:
                    AlertCtrl.Show("该物品不可使用!");
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// 添加掉落物到背包
        /// </summary>
        /// <returns>The item to bag.</returns>
        /// <param name="drops">Drops.</param>
        public List <DropData> PushItemToBag(List <DropData> drops, bool withoutNumLimit = false, float makeAFortuneRate = 0)
        {
            int             bagNumLeft  = GetItemNumLeftInBag();
            List <DropData> resultDrops = new List <DropData>();

            db = OpenDb();
            SqliteDataReader sqReader;
            DropData         drop;
            int  num;
            int  maxNum;
            int  addNum;
            bool isSecretsFull;

            for (int i = 0; i < drops.Count; i++)
            {
                drop = drops[i];
                if (drop.Item == null)
                {
                    drop.MakeJsonToModel();
                }
                if (drop.Item.Type == ItemType.Task)
                {
                    //判断是否为任务物品,任务物品在使用过后就不再掉落
                    sqReader = db.ExecuteQuery("select * from UsedItemRecordsTable where ItemId = '" + drop.Item.Id + "' and BelongToRoleId = '" + currentRoleId + "'");
                    if (sqReader.HasRows)
                    {
                        continue;
                    }
                }
                //背包位子如果不足则除了任务物品之外,其他的物品都不能添加进背包
                //诀要也不受背包满限制
                if (!withoutNumLimit && bagNumLeft <= 0)
                {
                    if (drop.Item.Type != ItemType.Task && drop.Item.Type != ItemType.Book && drop.Item.Type < ItemType.SecretIncreaseMaxHP)
                    {
                        Statics.CreatePopMsg(Vector3.zero, string.Format("背包满了,{0}不能拾取", drop.Item.Name), Color.red, 30);
                        continue;
                    }
                }
                //判断是否掉落
                if (!drop.IsTrigger(makeAFortuneRate))
                {
                    continue;
                }
                if (drop.Item.Type < ItemType.SecretIncreaseMaxHP)
                {
                    //查询背包里是否有物品以及物品的数量是否达到上限
                    sqReader = db.ExecuteQuery("select * from BagTable where ItemId = '" + drop.Item.Id + "' and Num < MaxNum and BelongToRoleId = '" + currentRoleId + "'");
                    if (!sqReader.HasRows)
                    {
                        //添加新的物品
                        db.ExecuteQuery("insert into BagTable (ItemId, Type, Num, MaxNum, Lv, BelongToRoleId) values('" + drop.Item.Id + "', " + ((int)drop.Item.Type) + ", " + drop.Item.Num + ", " + drop.Item.MaxNum + ", " + drop.Item.Lv + ", '" + currentRoleId + "')");
                    }
                    else
                    {
                        int itemNum = drop.Item.Num;
                        //修改物品的数量
                        while (sqReader.Read())
                        {
                            num      = sqReader.GetInt32(sqReader.GetOrdinal("Num"));
                            maxNum   = sqReader.GetInt32(sqReader.GetOrdinal("MaxNum"));
                            addNum   = (maxNum - num) <= itemNum ? (maxNum - num) : itemNum;
                            itemNum -= addNum;
                            db.ExecuteQuery("update BagTable set Num = " + (num + addNum) +
                                            " where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                            //如果掉落物的数量还有则下个循环继续处理添加物品
                            if (itemNum > 0)
                            {
                                i--;
                            }
                        }
                    }
                    resultDrops.Add(drop);
                    //任务物品不算入背包占位数
                    if (!withoutNumLimit && drop.Item.Type != ItemType.Task)
                    {
                        bagNumLeft--;
                    }
                }
                else
                {
                    //处理诀要
                    sqReader      = db.ExecuteQuery("select count(*) as num from BookSecretsTable where BelongToRoleId = '" + currentRoleId + "'");
                    isSecretsFull = false;
                    if (sqReader.Read())
                    {
                        isSecretsFull = sqReader.GetInt32(sqReader.GetOrdinal("num")) >= MaxSecretNumOfBag;
                    }
                    if (!isSecretsFull)
                    {
                        //添加新的诀要
                        SecretData secret = Statics.CreateNewSecret(Statics.ChangeItemTypeToSecretType(drop.Item.Type), QualityType.White);
                        db.ExecuteQuery("insert into BookSecretsTable (SecretData, T, Q, BelongToBookId, BelongToRoleId) values('" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(secret)) + "', " + ((short)secret.Type) + ", " + ((short)secret.Quality) + ", '', '" + currentRoleId + "')");
                        resultDrops.Add(drop);
                        PlayerPrefs.SetString("AddedNewBookFlag", "true");
                        PlayerPrefs.SetString("AddedNewSecretFlag", "true");
                    }
                    else
                    {
                        Statics.CreatePopMsg(Vector3.zero, string.Format("诀要背包上限为{0},请先清理背包", MaxSecretNumOfBag), Color.red, 30);
                    }
                }
            }
            db.CloseSqlConnection();
            if (resultDrops.Count > 0)
            {
                PlayerPrefs.SetString("AddedNewItemFlag", "true");
            }
            return(resultDrops);
        }