/// <summary> /// 将背包里的辎重箱放入工坊资源中 /// </summary> public void BringResourcesToWorkshop() { db = OpenDb(); //查询背包 SqliteDataReader sqReader = db.ExecuteQuery("select * from BagTable where BelongToRoleId = '" + currentRoleId + "' and Type >= " + (int)ItemType.Wheat + " and Type <= " + (int)ItemType.DarksteelIngot); if (sqReader.HasRows) { List <ResourceType> types = new List <ResourceType>(); List <int> nums = new List <int>(); ResourceType type; while (sqReader.Read()) { type = Statics.ChangeItemTypeToResourctType((ItemType)sqReader.GetInt32(sqReader.GetOrdinal("Type"))); types.Add(type); nums.Add(sqReader.GetInt32(sqReader.GetOrdinal("Num")) * sqReader.GetInt32(sqReader.GetOrdinal("Lv"))); } if (types.Count > 0) { //查询出资源 sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { int resourceId = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); List <ResourceData> resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); ResourceData findResource; int num; string msg = ""; for (int i = 0; i < types.Count; i++) { findResource = resources.Find(re => re.Type == types[i]); if (findResource != null) { num = nums[i]; findResource.Num += num; msg += string.Format("\n{0}+{1}", Statics.GetResourceName(types[i]), num); } else { msg += string.Format("\n<color=\"#FF0000\">工坊产力不够无力储存{0}只好丢弃</color>", Statics.GetResourceName(types[i])); } } //清空背包里的辎重箱 db.ExecuteQuery("delete from BagTable where BelongToRoleId = '" + currentRoleId + "' and Type >= " + (int)ItemType.Wheat + " and Type <= " + (int)ItemType.DarksteelIngot); //更新资源数据 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + resourceId); if (msg != "") { msg = "这次游历江湖带回了" + msg; Statics.CreatePopMsg(Vector3.zero, msg, Color.green, 30); } } } } db.CloseSqlConnection(); }