/// <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); }