/// <summary> /// 将修为添加给秘籍 /// </summary> /// <param name="exp">Exp.</param> /// <param name="books">Books.</param> public void InsertExpIntoBooks(long exp, List <BookData> books) { db = OpenDb(); SqliteDataReader sqReader; BookData book; ExpData expData; long maxExp = Statics.GetBookMaxExp(QualityType.FlashRed); for (int i = 0, len = books.Count; i < len; i++) { book = books[i]; if (!book.IsMindBook) { sqReader = db.ExecuteQuery("select Id, ExpData from BookExpsTable where BookId = " + book.Id + " and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { expData = JsonManager.GetInstance().DeserializeObject <ExpData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("ExpData")))); // expData.Cur = (long)Mathf.Clamp(expData.Cur + exp, 0, expData.Max); expData.Cur = (long)Mathf.Clamp(expData.Cur + exp, 0, maxExp); db.ExecuteQuery("update BookExpsTable set ExpData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(expData)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } else { db.ExecuteQuery("insert into BookExpsTable (BookId, ExpData, SecretsData, BelongToRoleId) values('" + book.Id + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(new ExpData(exp, Statics.GetBookMaxExp(book.Quality)))) + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(new List <SecretData>())) + "', '" + currentRoleId + "')"); } } } db.CloseSqlConnection(); }
/// <summary> /// 是主角等级上升 /// </summary> /// <param name="toLv">To lv.</param> public void HostRoleUpgrade(int toLv) { if (HostData.Lv >= toLv) { return; } RoleData role = null; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select RoleData from RolesTable where RoleId = '" + currentRoleId + "'"); string roleDataStr; if (sqReader.Read()) { roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData")); roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr); role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr); role.Lv = toLv > role.Lv ? toLv : role.Lv; //更新主角数据 db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + currentRoleId + "'"); } db.CloseSqlConnection(); if (role != null) { HostData.MakeJsonToModel(); role.MakeJsonToModel(); Messenger.Broadcast <RoleData, RoleData>(NotifyTypes.HostRoleUpgradeEcho, HostData, role); CallRoleInfoPanelData(false); //刷新队伍数据 MaiHandler.SetAccount(role); } }
/// <summary> /// 使用道具 /// </summary> /// <param name="type">Type.</param> /// <param name="num">Number.</param> public void UseProp(PropType type, int num) { db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, Data from GiftsTable where Type = " + (int)type + " and BelongToRoleId = '" + currentRoleId + "'"); string dataStr; PropData propData; if (sqReader.Read()) { dataStr = DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("Data"))); propData = JsonManager.GetInstance().DeserializeObject <PropData>(dataStr); propData.Num = Mathf.Clamp(propData.Num - num, 0, propData.Max); if (propData.Num > 0) { //改 db.ExecuteQuery("update GiftsTable set Data = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(propData)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } else { //删 db.ExecuteQuery("delete from GiftsTable where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } } db.CloseSqlConnection(); }
/// <summary> /// 遗忘秘籍诀要 /// </summary> /// <param name="book">Book.</param> /// <param name="secret">Secret.</param> public void ForgetSecret(BookData book, SecretData secret) { List <SecretData> secrets = null; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, ExpData, SecretsData from BookExpsTable where BookId = " + book.Id + " and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { secrets = JsonManager.GetInstance().DeserializeObject <List <SecretData> >(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretsData")))); int findIndex = secrets.FindIndex(item => item.PrimaryKeyId == secret.PrimaryKeyId); if (findIndex >= 0) { secrets.RemoveAt(findIndex); } db.ExecuteQuery("update BookExpsTable set SecretsData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(secrets)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); db.ExecuteQuery("update BookSecretsTable set BelongToBookId = '' where Id = '" + secret.PrimaryKeyId + "'"); } db.CloseSqlConnection(); if (secrets != null) { Messenger.Broadcast <BookData, List <SecretData> >(NotifyTypes.DealSecretEcho, book, secrets); SoundManager.GetInstance().PushSound("ui0008"); } }
/// <summary> /// 卸下秘籍 /// </summary> /// <param name="id">Identifier.</param> public void UnuseBook(int id) { db = OpenDb(); //查询角色信息 SqliteDataReader sqReader = db.ExecuteQuery("select RoleId, RoleData from RolesTable where RoleId = '" + currentRoleId + "' and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { string roleId = sqReader.GetString(sqReader.GetOrdinal("RoleId")); //获取角色数据 string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData")); roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr); RoleData role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr); sqReader = db.ExecuteQuery("select BookId from BooksTable where Id = " + id); if (sqReader.Read()) { string bookId = sqReader.GetString(sqReader.GetOrdinal("BookId")); db.ExecuteQuery("update BooksTable set SeatNo = 888, BeUsingByRoleId = '' where Id = " + id); int index = role.ResourceBookDataIds.FindIndex(item => item == bookId); if (index >= 0) { //更新角色的秘籍信息 role.ResourceBookDataIds.RemoveAt(index); db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + roleId + "'"); } } } db.CloseSqlConnection(); GetBooksListPanelData(); CallRoleInfoPanelData(false); //刷新队伍数据 }
/// <summary> /// 领悟秘籍诀要 /// </summary> /// <param name="secret">Secret.</param> public void StudySecret(BookData book, SecretData secret) { List <SecretData> secrets = null; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, ExpData, SecretsData from BookExpsTable where BookId = " + book.Id + " and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { ExpData exp = JsonManager.GetInstance().DeserializeObject <ExpData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("ExpData")))); secrets = JsonManager.GetInstance().DeserializeObject <List <SecretData> >(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretsData")))); int bookLv = Statics.GetBookLV(exp.Cur); if (secrets.Count >= bookLv) { AlertCtrl.Show(string.Format("<color=\"{0}\">{1}</color>目前只能领悟最多{2}张诀要", Statics.GetQualityColorString(book.Quality), book.Name, bookLv)); db.CloseSqlConnection(); return; } else { if (secrets.FindIndex(item => item.Type == secret.Type) < 0) { secrets.Add(secret); db.ExecuteQuery("update BookExpsTable set SecretsData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(secrets)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); db.ExecuteQuery("update BookSecretsTable set BelongToBookId = '" + book.Id + "' where Id = '" + secret.PrimaryKeyId + "'"); } else { AlertCtrl.Show("该类型诀要不能重复领悟!"); db.CloseSqlConnection(); return; } } } else { secrets = new List <SecretData>() { secret }; //处理空数据初始化 db.ExecuteQuery("insert into BookExpsTable (BookId, ExpData, SecretsData, BelongToRoleId) values('" + book.Id + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(new ExpData(0, Statics.GetBookMaxExp(book.Quality)))) + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(secrets)) + "', '" + currentRoleId + "')"); db.ExecuteQuery("update BookSecretsTable set BelongToBookId = '" + book.Id + "' where Id = '" + secret.PrimaryKeyId + "'"); } db.CloseSqlConnection(); if (secrets != null) { Messenger.Broadcast <BookData, List <SecretData> >(NotifyTypes.DealSecretEcho, book, secrets); Statics.CreatePopMsg(Vector3.zero, string.Format("领悟<color=\"{0}\">{1}</color>后<color=\"{2}\">{3}</color>更为精进!!", Statics.GetQualityColorString(secret.Quality), secret.Name, Statics.GetQualityColorString(book.Quality), book.Name), Color.white, 30); SoundManager.GetInstance().PushSound("ui0010"); } }
/// <summary> /// 卸下兵器 /// </summary> /// <param name="id">Identifier.</param> public void TakeOffWeapon(int id) { db = OpenDb(); db.ExecuteQuery("update WeaponsTable set BeUsingByRoleId = '' where Id = " + id); SqliteDataReader sqReader = db.ExecuteQuery("select RoleId, RoleData from RolesTable where RoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { //获取角色数据 string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData")); roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr); RoleData role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr); role.ResourceWeaponDataId = ""; //更新主角关联数据 db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + currentRoleId + "'"); } db.CloseSqlConnection(); GetWeaponsListPanelData(); //刷新兵器匣列表 CallRoleInfoPanelData(false); //刷新队伍数据 }
/// <summary> /// 购买物品 /// </summary> /// <param name="itemId">Item identifier.</param> /// <param name="num">Number.</param> public void BuyItem(string itemId, int num = 1) { ModifyResources(); ItemData item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", itemId); //单次购买的数量不能超出物品叠加上限 int startNum = num <= item.MaxNum ? num : item.MaxNum; int itemNum = startNum; double silverNum = 0; db = OpenDb(); //查询背包是否已满 SqliteDataReader sqReader = db.ExecuteQuery("select count(*) as num from BagTable where BelongToRoleId = '" + currentRoleId + "'"); bool enoughBagSeat = false; bool enoughMoney = false; string msg = ""; if (sqReader.Read()) { if (sqReader.GetInt32(sqReader.GetOrdinal("num")) < MaxItemNumOfBag) { enoughBagSeat = true; } } if (enoughBagSeat) { sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; if (sqReader.Read()) { string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); //查询目前的银子余额 ResourceData resource = resources.Find(re => re.Type == ResourceType.Silver); if (resource != null) { if (resource.Num >= item.BuyPrice * itemNum) { enoughMoney = true; resource.Num -= (item.BuyPrice * itemNum); //扣钱 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); silverNum = resource.Num; } } } //背包未满 if (enoughMoney) { //银子够买 //查询背包里是否有物品以及物品的数量是否达到上限 sqReader = db.ExecuteQuery("select * from BagTable where ItemId = '" + itemId + "' and Num < MaxNum and BelongToRoleId = '" + currentRoleId + "'"); if (!sqReader.HasRows) { //添加新的物品 db.ExecuteQuery("insert into BagTable (ItemId, Type, Num, MaxNum, Lv, BelongToRoleId) values('" + itemId + "', " + ((int)item.Type) + ", " + itemNum + ", " + item.MaxNum + ", " + item.Lv + ", '" + currentRoleId + "')"); } else { int itemDataNum; int itemDataMaxNum; int addNum; //修改以后物品的数量 while (sqReader.Read() && itemNum > 0) { itemDataNum = sqReader.GetInt32(sqReader.GetOrdinal("Num")); itemDataMaxNum = sqReader.GetInt32(sqReader.GetOrdinal("MaxNum")); addNum = (itemDataMaxNum - itemDataNum) <= itemNum ? (itemDataMaxNum - itemDataNum) : itemNum; itemNum -= addNum; db.ExecuteQuery("update BagTable set Num = " + (itemDataNum + addNum) + " where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } //对已有物品进行累加后还有剩余数量,则这个数量全部新增为新物品 if (itemNum > 0) { db.ExecuteQuery("insert into BagTable (ItemId, Type, Num, MaxNum, Lv, BelongToRoleId) values('" + itemId + "', " + ((int)item.Type) + ", " + itemNum + ", " + item.MaxNum + ", " + item.Lv + ", '" + currentRoleId + "')"); } } } } db.CloseSqlConnection(); if (!enoughBagSeat) { AlertCtrl.Show("行囊已满,不能携带更多的物品!"); } else if (!enoughMoney) { AlertCtrl.Show("银子不够!\n(<color=\"#00FF00\">工坊中可以赚取银子</color>)"); } else { msg = string.Format("<color=\"#1ABDE6\">{0}</color>+{1}", item.Name, startNum); Messenger.Broadcast <string, double>(NotifyTypes.BuyItemEcho, msg, silverNum); } }
/// <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; } } }
/// <summary> /// 熔解兵器 /// </summary> /// <param name="primaryKeyId">Primary key identifier.</param> public void BreakWeapon(int primaryKeyId) { int resultId = 0; db = OpenDb(); //查询资源 SqliteDataReader sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; int id = 0; if (sqReader.Read()) { id = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); } if (resources != null) { sqReader = db.ExecuteQuery("select Id, WeaponId from WeaponsTable where Id = " + primaryKeyId); if (sqReader.Read()) { WeaponData weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", sqReader.GetString(sqReader.GetOrdinal("WeaponId"))); ResourceData findResource; ResourceData resource; float addNum; for (int i = 0; i < weapon.Needs.Count; i++) { resource = weapon.Needs[i]; findResource = resources.Find(item => item.Type == resource.Type); if (findResource != null) { addNum = Mathf.Floor((float)(resource.Num * 0.5f)); //累加资源 findResource.Num += addNum; } } //删除兵器 db.ExecuteQuery("delete from WeaponsTable where Id = " + primaryKeyId); //更新资源 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id); resultId = primaryKeyId; } } db.CloseSqlConnection(); if (primaryKeyId > 0) { Messenger.Broadcast <int>(NotifyTypes.BreakWeaponEcho, primaryKeyId); } }
/// <summary> /// 刷新资源数据 /// </summary> public void ModifyResources() { JArray data = new JArray(modifyResourceTimeout, "[]", "[]"); try { db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { long ticks = sqReader.GetInt64(sqReader.GetOrdinal("Ticks")); DateTime oldDate = new DateTime(ticks); float skipSeconds = (float)(DateTime.Now - oldDate).TotalSeconds; int n = (int)Mathf.Floor((skipSeconds / modifyResourceTimeout)); //设置最大的托管时间间隔(1小时之外的资源无效) int maxN = maxModifyResourceTimeout / modifyResourceTimeout; //记录倒计时时间 data[0] = skipSeconds < modifyResourceTimeout ? (int)(modifyResourceTimeout - skipSeconds) : modifyResourceTimeout; if (n > 0) { n = n > maxN ? maxN : n; int id = 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); List <ResourceData> resultResources = returnAllReceiveResourcesOnece(resources, n); if (resultResources.Count > 0) { ResourceData result; ResourceData find; for (int i = 0; i < resultResources.Count; i++) { result = resultResources[i]; find = resources.Find(item => item.Type == result.Type); if (find != null) { //累加拥有的资源 find.Num += result.Num; find.Num = find.Num < 0 ? 0 : find.Num; } } db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "', Ticks = " + DateTime.Now.Ticks + " where Id = " + id); } else { //没有产出也需要更新时间戳 db.ExecuteQuery("update WorkshopResourceTable set Ticks = " + DateTime.Now.Ticks + " where Id = " + id); } //添加收获的资源列表 data[1] = JsonManager.GetInstance().SerializeObject(resultResources); //计算单位产出 data[2] = JsonManager.GetInstance().SerializeObject(returnAllReceiveResourcesOnece(resources)); } } db.CloseSqlConnection(); } catch (Exception e) { db.CloseSqlConnection(); Debug.LogWarning("ModifyResources-------------------error:" + e.ToString() + " - " + e.StackTrace); return; } Messenger.Broadcast <JArray>(NotifyTypes.ModifyResourcesEcho, data); }
/// <summary> /// 替换兵器(不允许侠客不拿兵器) /// </summary> /// <param name="id">Identifier.</param> /// <param name="beUsingByRoleId">Be using by role identifier.</param> public void ReplaceWeapon(int id, string beUsingByRoleId) { db = OpenDb(); //查询角色信息 SqliteDataReader sqReader = db.ExecuteQuery("select RoleId, RoleData from RolesTable where RoleId = '" + beUsingByRoleId + "' and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { //获取角色数据 string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData")); roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr); RoleData role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr); sqReader = db.ExecuteQuery("select * from WeaponsTable where BeUsingByRoleId = '" + beUsingByRoleId + "' and BelongToRoleId ='" + currentRoleId + "'"); while (sqReader.Read()) { //将兵器先卸下 int dataId = sqReader.GetInt32(sqReader.GetOrdinal("Id")); db.ExecuteQuery("update WeaponsTable set BeUsingByRoleId = '' where Id = " + dataId); } sqReader = db.ExecuteQuery("select Id, WeaponId from WeaponsTable where Id = " + id); if (sqReader.Read()) { string weaponId = sqReader.GetString(sqReader.GetOrdinal("WeaponId")); WeaponData weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", weaponId); if (weapon.BelongToRoleId == "") { if (weapon.Occupation == OccupationType.None || weapon.Occupation == HostData.Occupation) { //装备新兵器 db.ExecuteQuery("update WeaponsTable set BeUsingByRoleId = '" + beUsingByRoleId + "' where Id = " + id); //更新角色的武器信息 role.ResourceWeaponDataId = weaponId; //查询下新武器替换上后秘籍需不需要卸下 sqReader = db.ExecuteQuery("select Id, BookId from BooksTable where BeUsingByRoleId = '" + currentRoleId + "' and BelongToRoleId = '" + currentRoleId + "'"); BookData book; string unuseBookMsg = ""; while (sqReader.Read()) { book = JsonManager.GetInstance().GetMapping <BookData>("Books", sqReader.GetString(sqReader.GetOrdinal("BookId"))); if (book.LimitWeaponType != WeaponType.None && (book.LimitWeaponType != weapon.Type)) { db.ExecuteQuery("update BooksTable set SeatNo = 888, BeUsingByRoleId = '' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); int index = role.ResourceBookDataIds.FindIndex(item => item == book.Id); if (index >= 0) { //更新角色的秘籍信息 role.ResourceBookDataIds.RemoveAt(index); } unuseBookMsg += " " + book.Name; } } //更新主角关联数据 db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + beUsingByRoleId + "'"); if (unuseBookMsg != "") { Statics.CreatePopMsg(Vector3.zero, string.Format("拿上<color=\"{0}\">{1}</color>后不可能再习练{2}", Statics.GetQualityColorString(weapon.Quality), weapon.Name, unuseBookMsg), Color.white, 30); } SoundManager.GetInstance().PushSound("ui0011"); } else { AlertCtrl.Show(string.Format("<color=\"{0}\">{1}</color>只有 {2} 才能使用!", Statics.GetQualityColorString(weapon.Quality), weapon.Name, Statics.GetOccupationDesc(weapon.Occupation))); } } else { AlertCtrl.Show(string.Format("<color=\"{0}\">{1}</color>只有 {2} 才能使用!", Statics.GetQualityColorString(weapon.Quality), weapon.Name, JsonManager.GetInstance().GetMapping <RoleData>("RoleDatas", weapon.BelongToRoleId).Name)); } } } db.CloseSqlConnection(); GetWeaponsListPanelData(); //刷新兵器匣列表 CallRoleInfoPanelData(false); //刷新队伍数据 }
/// <summary> /// 修改队伍的位子编号 /// </summary> /// <param name="ids">Identifiers.</param> public void ChangeRolesSeatNo(JArray ids) { db = OpenDb(); //将原来的角色先全部下阵 db.ExecuteQuery("update RolesTable set State = " + ((int)RoleStateType.OutTeam) + " where State = " + ((int)RoleStateType.InTeam) + " and BelongToRoleId = '" + currentRoleId + "'"); string id; for (int i = 0; i < ids.Count; i++) { id = ids[i].ToString(); db.ExecuteQuery("update RolesTable set State = " + ((int)RoleStateType.InTeam) + ", SeatNo = " + i + " where Id = " + id); } //处理干粮 SqliteDataReader sqReader = db.ExecuteQuery("select Data, AreaFoodNum from UserDatasTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { UserData user = JsonManager.GetInstance().DeserializeObject <UserData>(sqReader.GetString(sqReader.GetOrdinal("Data"))); user.AreaFood.Num = sqReader.GetInt32(sqReader.GetOrdinal("AreaFoodNum")); if (user.AreaFood.Num < user.AreaFood.MaxNum) { sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { //更新 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 resource = resources.Find(item => item.Type == ResourceType.Food); double cutNum = (double)(user.AreaFood.MaxNum - user.AreaFood.Num); cutNum = resource.Num >= cutNum ? cutNum : resource.Num; if (cutNum > 0) { resource.Num -= cutNum; user.AreaFood.Num += (int)cutNum; //扣除工坊中的干粮 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); //增加随身携带的干粮 db.ExecuteQuery("update UserDatasTable set AreaFoodNum = " + user.AreaFood.Num + " where BelongToRoleId = '" + currentRoleId + "'"); } } } } db.CloseSqlConnection(); }
/// <summary> /// 直接用工坊资源结交侠客 /// </summary> /// <param name="id">Identifier.</param> public void InviteRoleWithResources(int id) { ModifyResources(); bool invited = false; RoleData role = null; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, RoleId, State from RolesTable where Id = " + id); if (sqReader.Read()) { role = JsonManager.GetInstance().GetMapping <RoleData>("RoleDatas", sqReader.GetString(sqReader.GetOrdinal("RoleId"))); RoleStateType state = (RoleStateType)sqReader.GetInt32(sqReader.GetOrdinal("State")); if (state == RoleStateType.NotRecruited) { //兵器匣里并没有需要的兵器 WeaponData weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", role.ResourceWeaponDataId); List <ResourceData> needs = new List <ResourceData>(); ResourceData need; ResourceData find; for (int i = 0; i < weapon.Needs.Count; i++) { need = weapon.Needs[i]; find = needs.Find(item => item.Type == need.Type); if (find == null) { needs.Add(new ResourceData(need.Type, need.Num)); } else { find.Num += need.Num; } } sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; int resourceId = 0; if (sqReader.Read()) { resourceId = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); } db.CloseSqlConnection(); if (resources != null) { bool canAdd = true; string msg = ""; for (int i = 0; i < needs.Count; i++) { need = needs[i]; find = resources.Find(item => item.Type == need.Type); if (find != null && find.Num >= need.Num) { find.Num -= need.Num; } else { canAdd = false; msg = string.Format("{0}不足!", Statics.GetResourceName(need.Type)); break; } } if (canAdd) { db = OpenDb(); db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + resourceId); //结交侠客 db.ExecuteQuery("update RolesTable set State = " + ((int)RoleStateType.OutTeam) + ", SeatNo = 888 where Id = " + id); invited = true; db.CloseSqlConnection(); } else { AlertCtrl.Show(msg, null); } } } else { AlertCtrl.Show("你们已经结识!", null); } } db.CloseSqlConnection(); if (invited && role != null) { Statics.CreatePopMsg(Vector3.zero, string.Format("你与<color=\"#FFFF00\">{0}</color>撮土为香,结成八拜之交!", role.Name), Color.white, 30); GetRolesOfWinShopPanelData(role.HometownCityId); SoundManager.GetInstance().PushSound("ui0010"); } }
/// <summary> /// 添加新的角色数据 /// </summary> /// <param name="roleId">Role identifier.</param> /// <param name="roleData">Role data.</param> /// <param name="state">State.</param> /// <param name="seatNo">Seat no.</param> /// <param name="belongToRoleId">Belong to role identifier.</param> /// <param name="dateTime">Date time.</param> public bool AddNewRole(string roleId, string roleData, int state, int seatNo, string hometownCityId, string belongToRoleId, string dateTime) { bool result = false; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select RoleId from RolesTable where RoleId = '" + roleId + "' and BelongToRoleId = '" + belongToRoleId + "'"); if (!sqReader.HasRows) { db.ExecuteQuery("insert into RolesTable (RoleId, RoleData, State, SeatNo, HometownCityId, BelongToRoleId, InjuryType, Ticks, DateTime) values('" + roleId + "', '" + DESStatics.StringEncoder(roleData) + "', " + state + ", " + seatNo + ", '" + hometownCityId + "', '" + belongToRoleId + "', " + ((int)InjuryType.None) + ", " + DateTime.Now.Ticks + ", '" + dateTime + "');"); result = true; } db.CloseSqlConnection(); return(result); }
/// <summary> /// 添加一个新的侠客进酒馆 /// </summary> /// <param name="roleId">Role identifier.</param> public void PushNewRoleToWinShop(string roleId) { db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select RoleData from RolesTable where RoleId = '" + roleId + "' and BelongToRoleId = '" + currentRoleId + "'"); if (!sqReader.HasRows) { RoleData role = JsonManager.GetInstance().GetMapping <RoleData>("RoleDatas", roleId); db.ExecuteQuery("insert into RolesTable (RoleId, RoleData, State, SeatNo, HometownCityId, BelongToRoleId, InjuryType, Ticks, DateTime) values('" + roleId + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "', 0, 888, '" + role.HometownCityId + "', '" + currentRoleId + "', " + ((int)InjuryType.None) + ", " + DateTime.Now.Ticks + ", '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"); if (CitySceneModel.RoleIdOfWinShopNewFlagList.FindIndex(item => item == roleId) < 0) { CitySceneModel.RoleIdOfWinShopNewFlagList.Add(roleId); } } db.CloseSqlConnection(); }
/// <summary> /// 检测是否是否有新的侠客可以招募,有则加入到待选数据表中 /// </summary> /// <param name="cityId">City identifier.</param> public void CheckNewRoleIdsOfWinShop(string cityId) { JObject roleIdsOfWinShopDatas = JsonManager.GetInstance().GetJson("RoleIdsOfWinShopDatas"); if (roleIdsOfWinShopDatas[cityId] != null) { db = OpenDb(); JArray roleIdsData = (JArray)roleIdsOfWinShopDatas[cityId]; string roleId; SqliteDataReader sqReader; RoleData role; for (int i = 0; i < roleIdsData.Count; i++) { roleId = roleIdsData[i].ToString(); sqReader = db.ExecuteQuery("select RoleData from RolesTable where RoleId = '" + roleId + "' and BelongToRoleId = '" + currentRoleId + "'"); if (!sqReader.HasRows) { role = JsonManager.GetInstance().GetMapping <RoleData>("RoleDatas", roleId); db.ExecuteQuery("insert into RolesTable (RoleId, RoleData, State, SeatNo, HometownCityId, BelongToRoleId, InjuryType, Ticks, DateTime) values('" + roleId + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "', 0, 888, '" + role.HometownCityId + "', '" + currentRoleId + "', " + ((int)InjuryType.None) + ", " + DateTime.Now.Ticks + ", '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"); } } db.CloseSqlConnection(); } roleIdsOfWinShopDatas = null; }
/// <summary> /// 融合诀要 /// </summary> /// <param name="secret">Secret.</param> public bool MixSecrets(SecretData secret) { bool result = false; if (secret.Quality >= QualityType.FlashRed) { AlertCtrl.Show(string.Format("<color=\"{0}\">{1}</color>已经是顶级诀要无法继续融合", Statics.GetQualityColorString(secret.Quality), secret.Name)); return(result); } db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select count(*) as num from BookSecretsTable where T = " + ((short)secret.Type) + " and Q = " + ((short)secret.Quality) + " and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { if (sqReader.GetInt32(sqReader.GetOrdinal("num")) >= 2) { sqReader = db.ExecuteQuery("select Id from BookSecretsTable where T = " + ((short)secret.Type) + " and Q = " + ((short)secret.Quality) + " and BelongToRoleId = '" + currentRoleId + "' and Id != " + secret.PrimaryKeyId + " order by Id limit 0, 1"); //删除素材诀要 while (sqReader.Read()) { db.ExecuteQuery("delete from BookSecretsTable where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } //升级选中的诀要 sqReader = db.ExecuteQuery("select SecretData, Q from BookSecretsTable where Id = " + secret.PrimaryKeyId); if (sqReader.Read()) { SecretData secretData = JsonManager.GetInstance().DeserializeObject <SecretData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretData")))); short endQuality = (short)(((int)secretData.Quality) + 1); secretData.Quality = (QualityType)(endQuality); db.ExecuteQuery("update BookSecretsTable set SecretData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(secretData)) + "', Q = " + ((short)secretData.Quality) + " where Id = " + secret.PrimaryKeyId); Statics.CreatePopMsg(Vector3.zero, string.Format("融合<color=\"{0}\">{1}</color>后使你武功精进!", Statics.GetQualityColorString(secretData.Quality), secretData.Name), Color.white, 30); SoundManager.GetInstance().PushSound("ui0010"); result = true; } else { AlertCtrl.Show("需要融合的诀要不存在"); } } else { AlertCtrl.Show(string.Format("至少需要2张相同品质的<color=\"{0}\">{1}</color>才能融合成更高级的诀要", Statics.GetQualityColorString(secret.Quality), secret.Name)); } } db.CloseSqlConnection(); return(result); }
/// <summary> /// 兵器强化 /// </summary> /// <param name="weapon">Weapon.</param> public void WeaponLVUpgrade(WeaponData weapon) { db = OpenDb(); List <ResourceData> needs = new List <ResourceData>(); ResourceData need; ResourceData find; double needRate = DbManager.Instance.GetWeaponNeedRate(weapon.LV + 1); for (int i = 0; i < weapon.Needs.Count; i++) { need = weapon.Needs[i]; find = needs.Find(item => item.Type == need.Type); if (find == null) { needs.Add(new ResourceData(need.Type, need.Num * needRate)); } else { find.Num += (need.Num * needRate); } } SqliteDataReader sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; int id = 0; if (sqReader.Read()) { id = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); } db.CloseSqlConnection(); if (resources != null) { bool canAdd = true; string msg = ""; for (int i = 0; i < needs.Count; i++) { need = needs[i]; find = resources.Find(item => item.Type == need.Type); if (find != null && find.Num >= need.Num) { find.Num -= need.Num; } else { canAdd = false; msg = string.Format("{0}不足!", Statics.GetResourceName(need.Type)); break; } } if (canAdd) { db = OpenDb(); sqReader = db.ExecuteQuery("select Id, Data from WeaponLVsTable where WeaponId = '" + weapon.Id + "' and BelongToRoleId = '" + currentRoleId + "'"); WeaponLVData lvData; if (sqReader.Read()) { //获取角色数据 lvData = JsonManager.GetInstance().DeserializeObject <WeaponLVData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("Data")))); if (weapon.LV >= lvData.MaxLV) { AlertCtrl.Show("兵器强化度已满"); db.CloseSqlConnection(); return; } lvData.LV = weapon.LV + 1; db.ExecuteQuery("update WeaponLVsTable set Data = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(lvData)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } else { lvData = new WeaponLVData(weapon.LV + 1); db.ExecuteQuery("insert into WeaponLVsTable (WeaponId, Data, BelongToRoleId) values('" + weapon.Id + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(lvData)) + "', '" + currentRoleId + "')"); } db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id); db.CloseSqlConnection(); Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(weapon.Quality), weapon.Name), Color.white, 30); SoundManager.GetInstance().PushSound("ui0007"); Messenger.Broadcast <WeaponLVData>(NotifyTypes.WeaponLVUpgradeEcho, lvData); } else { AlertCtrl.Show(msg, null); } } }
/// <summary> /// 前往城镇 /// </summary> /// <param name="fromIndex">From index.</param> /// <param name="toIndex">To index.</param> public void GoToCity(int fromIndex, int toIndex) { SceneData toScene = null; ModifyResources(); db = OpenDb(); string indexToId = JsonManager.GetInstance().GetMapping <string>("SceneIndexToIds", toIndex.ToString()); SqliteDataReader sqReader = db.ExecuteQuery("select CityId from EnterCityTable where CityId == '" + indexToId + "' and BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.HasRows) { FloydResult result = floyd.GetResult(fromIndex, toIndex); //查询银子是否足够支付路费 sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; if (sqReader.Read()) { string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); //查询目前的银子余额 ResourceData resource = resources.Find(re => re.Type == ResourceType.Silver); if (resource != null) { if (resource.Num >= result.Distance) { resource.Num -= result.Distance; //扣钱 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); toScene = JsonManager.GetInstance().GetMapping <SceneData>("Scenes", GetCityIdByIndex(toIndex)); Debug.LogWarning(GetCityIdByIndex(toIndex) + "," + toScene.Id + "," + toScene.Name); } else { AlertCtrl.Show("银子不够支付路费!"); } } } } else { AlertCtrl.Show("并没有开启前方传送点!"); } db.CloseSqlConnection(); if (toScene != null) { Messenger.Broadcast <SceneData>(NotifyTypes.GoToCityEcho, toScene); } }
/// <summary> /// 检测任务对话状态(任务对话的进度在这里来更新, 每次验证任务对话类型,然后判断是否可以完成,如果可以完成则CurrentDialogIndex+1) /// </summary> /// <param name="taskId">Task identifier.</param> /// <param name="auto">If set to <c>true</c> auto.</param> /// <param name="selectedNo">If set to <c>true</c> selected no.</param> public void CheckTaskDialog(string taskId, bool auto = false, bool selectedNo = false) { TaskData data = getTask(taskId); if (data != null) { if (data.State == TaskStateType.Completed) { // db.CloseSqlConnection(); return; } string triggerNewBackTaskDataId = ""; TaskDialogType dialogType = data.GetCurrentDialog().Type; bool canModify = false; JArray pushData = new JArray(); TaskDialogData dialog = data.GetCurrentDialog(); data.State = TaskStateType.Accepted; if (data.GetCurrentDialogStatus() == TaskDialogStatusType.Initial) { if (dialogType == TaskDialogType.JustTalk || dialogType == TaskDialogType.Notice) { //交谈步骤和信息显示步骤直接变为已读状态 data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); } else { //其他状态的话需要等待下一个步骤提交时检测是否可以完成,所以先HoldOn data.SetCurrentDialogStatus(TaskDialogStatusType.HoldOn); bool loadEvents = false; //如果是动态战斗事件步骤需要在这里创建动态战斗事件 if (dialogType == TaskDialogType.EventFightWined) { // Debug.LogWarning("如果是动态战斗事件步骤需要在这里创建动态战斗事件"); //创建一个区域大地图的战斗事件 CreateNewEvent(SceneEventType.Battle, dialog.StringValue, UserModel.CurrentUserData.CurrentAreaSceneName); loadEvents = true; } //如果是区域大地图野外任务事件步骤需要在这里创建动态任务事件 if (dialogType == TaskDialogType.CreateTaskIsBindedWithEvent) { // Debug.LogWarning("如果是区域大地图野外任务事件步骤需要在这里创建动态任务事件"); //创建一个区域大地图的战斗事件 AddNewTask(dialog.StringValue); CreateNewEvent(SceneEventType.Task, dialog.StringValue, UserModel.CurrentUserData.CurrentAreaSceneName); loadEvents = true; } if (loadEvents) { //加载动态事件列表 Messenger.Broadcast <string>(NotifyTypes.GetActiveEventsInArea, UserModel.CurrentUserData.CurrentAreaSceneName); } } dialog = data.GetCurrentDialog(); pushData.Add(new JArray(dialog.Index.ToString(), dialog.Type, dialog.TalkMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } else { RoleData hostRole; switch (dialogType) { case TaskDialogType.Choice: if (!auto) { triggerNewBackTaskDataId = selectedNo ? data.GetCurrentDialog().BackNoTaskDataId : data.GetCurrentDialog().BackYesTaskDataId; data.SetCurrentDialogStatus(selectedNo ? TaskDialogStatusType.ReadNo : TaskDialogStatusType.ReadYes); //输出步骤执行结果信息 pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, data.GetCurrentDialogStatus() == TaskDialogStatusType.ReadYes ? dialog.YesMsg : dialog.NoMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.ConvoyNpc: //暂时没考虑好怎么做护送npc任务 data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; break; case TaskDialogType.FightWined: case TaskDialogType.EventFightWined: if (IsFightWined(dialog.StringValue)) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.JustTalk: case TaskDialogType.Notice: canModify = true; break; case TaskDialogType.RecruitedThePartner: if (GetRoleDataByRoleId(dialog.StringValue) != null) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.SendItem: if (CostItemFromBag(dialog.StringValue, dialog.IntValue)) { DbManager.Instance.UpdateUsedItemRecords(dialog.StringValue, dialog.IntValue); data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.UsedTheBook: hostRole = GetHostRoleData(); if (hostRole != null) { for (int i = 0; i < hostRole.ResourceBookDataIds.Count; i++) { if (hostRole.ResourceBookDataIds[i] == dialog.StringValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; break; } } } break; case TaskDialogType.UsedTheSkillOneTime: if (GetUsedTheSkillTimes(dialog.StringValue) > 0) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.UsedTheWeapon: hostRole = GetHostRoleData(); if (hostRole.ResourceWeaponDataId == dialog.StringValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.WeaponPowerPlusSuccessed: if (GetWeaponPowerPlusSuccessedTimes(dialog.IntValue) > 0) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.SendResource: // if (CostResource((ResourceType)Enum.Parse(typeof(ResourceType), dialog.StringValue), dialog.IntValue)) { if (GetResourceNum((ResourceType)Enum.Parse(typeof(ResourceType), dialog.StringValue)) >= dialog.IntValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.TheHour: if (FramePanelCtrl.CurrentTimeIndex == dialog.IntValue) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; case TaskDialogType.PushRoleToWinshop: PushNewRoleToWinShop(dialog.StringValue); data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; break; case TaskDialogType.CreateTaskIsBindedWithEvent: if (IsTaskCompleted(dialog.StringValue)) { data.SetCurrentDialogStatus(TaskDialogStatusType.ReadYes); pushData.Add(new JArray(dialog.Index.ToString() + "_0", TaskDialogType.Notice, dialog.YesMsg, (short)data.GetCurrentDialogStatus(), dialog.IconId, dialog.StringValue)); canModify = true; } break; default: break; } if (canModify && data.CheckCompleted()) { data.State = TaskStateType.Completed; } } TaskStateType currentState = data.State; if (canModify) { db = OpenDb(); //如果是可循环的任务这里需要置为可接受,否则置为已完成 if (data.State == TaskStateType.Completed && data.CanRepeat) { data.State = TaskStateType.CanAccept; for (int a = 0; a < data.ProgressData.Count; a++) { data.ProgressData[a] = (short)TaskDialogStatusType.Initial; } data.SetCurrentDialogIndex(0); } //update data db.ExecuteQuery("update TasksTable set ProgressData = '" + data.ProgressData.ToString() + "', CurrentDialogIndex = " + data.CurrentDialogIndex + ", State = " + ((int)data.State) + " where TaskId ='" + taskId + "' and BelongToRoleId = '" + currentRoleId + "'"); db.CloseSqlConnection(); int index = taskListData.FindIndex(item => item.Id == taskId); //update cache if (taskListData.Count > index) { taskListData[index] = data; } } //触发新任务 if (triggerNewBackTaskDataId != "" && triggerNewBackTaskDataId != "0") { AddNewTaskExceptType(triggerNewBackTaskDataId, TaskType.IsBindedWithEvent); //检测任务状态 checkAddedTasksStatus(); } if (currentState == TaskStateType.Completed) { //添加任务奖励物品 //查询背包是否已满 bool enoughBagSeat = false; // int hasNum = GetItemNumLeftInBag(); //还剩余的背包位子 // if (hasNum > 0) { // enoughBagSeat = true; // } //任务掉落的物品没有背包限制 List <DropData> drops = PushItemToBag(data.Rewards, true); if (drops.Count > 0) { Messenger.Broadcast <List <DropData> >(NotifyTypes.ShowDropsListPanel, drops); } //如果是就职任务则提示就职成功 if (data.IsInaugurationTask) { HostData = GetHostRoleData(); if (HostData.Occupation == OccupationType.None) { //加入门派 HostData.Occupation = data.InaugurationOccupation; HostData.Disposed(); db = OpenDb(); db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(HostData)) + "' where Id = " + HostData.PrimaryKeyId); //判断兵器是否属于本门派 WeaponData currentWeapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", HostData.ResourceWeaponDataId); if (currentWeapon.Occupation != OccupationType.None && currentWeapon.Occupation != HostData.Occupation) { SqliteDataReader sqReader = db.ExecuteQuery("select * from WeaponsTable where BeUsingByRoleId = '" + currentRoleId + "' and BelongToRoleId ='" + currentRoleId + "'"); while (sqReader.Read()) { //将兵器先卸下 int dataId = sqReader.GetInt32(sqReader.GetOrdinal("Id")); db.ExecuteQuery("update WeaponsTable set BeUsingByRoleId = '' where Id = " + dataId); } } db.CloseSqlConnection(); //检查下是否有新兵器需要 CheckNewWeaponIdsOfWorkshop(UserModel.CurrentUserData.CurrentCitySceneId); Messenger.Broadcast(NotifyTypes.MakeCheckNewFlags); //判断城镇界面的新增提示 AlertCtrl.Show(string.Format("你已成功加入{0}!", Statics.GetOccupationName(HostData.Occupation))); } else { AlertCtrl.Show("你已是有门有派之人, 不可在此另行拜师!"); } } //任务完成后出发后续任务 addChildrenTasks(data.Id); //任务完成后移除区域大地图上的任务事件 RemoveTaskEvent(data.Id); } Messenger.Broadcast <JArray>(NotifyTypes.CheckTaskDialogEcho, pushData); if (data.GetCurrentDialogStatus() == TaskDialogStatusType.ReadNo || data.GetCurrentDialogStatus() == TaskDialogStatusType.ReadYes) { data.NextDialogIndex(); } } }
int modifyResourceTimeout = 20; //刷新资源间隔时间(单位:秒) /// <summary> /// 检测是否有新的生产单元 /// </summary> /// <param name="cityId">City identifier.</param> public void CheckNewWorkshopItems(string cityId) { db = OpenDb(); List <ResourceRelationshipData> resourcesRelationshipsInCity = WorkshopModel.Relationships.FindAll(item => item.BelongToCityId == cityId); if (resourcesRelationshipsInCity.Count > 0) { List <ResourceData> resources; SqliteDataReader sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { //更新 string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); for (int i = 0; i < resourcesRelationshipsInCity.Count; i++) { if (resources.FindIndex(item => item.Type == resourcesRelationshipsInCity[i].Type) < 0) { resources.Add(new ResourceData(resourcesRelationshipsInCity[i].Type, 0)); } } db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } else { //新增 resources = new List <ResourceData>(); for (int i = 0; i < resourcesRelationshipsInCity.Count; i++) { resources.Add(new ResourceData(resourcesRelationshipsInCity[i].Type, 0)); } db.ExecuteQuery("insert into WorkshopResourceTable (ResourcesData, Ticks, WorkerNum, MaxWorkerNum, BelongToRoleId) values('" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "', " + DateTime.Now.Ticks + ", 0, 0, '" + currentRoleId + "')"); } //记录当前所有的工坊资源类型列表 CitySceneModel.ResourceTypeStrOfWorkShopNewFlagList = new List <string>(); for (int i = resources.Count - 1; i >= 0; i--) { CitySceneModel.ResourceTypeStrOfWorkShopNewFlagList.Add(resources[i].Type.ToString()); } } db.CloseSqlConnection(); }
/// <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); }
/// <summary> /// 出售背包中的物品 /// </summary> /// <param name="ids">Identifiers.</param> public void SellItems(JArray ids) { List <ItemData> items = new List <ItemData>(); db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, ItemId, Num from BagTable where BelongToRoleId = '" + currentRoleId + "'"); ItemData item; //查询出背包中所有的可出售物品 while (sqReader.Read()) { item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", sqReader.GetString(sqReader.GetOrdinal("ItemId"))); if (item.SellPrice >= 0) { item.PrimaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id")); item.Num = sqReader.GetInt32(sqReader.GetOrdinal("Num")); items.Add(item); } } //检查前端传递过来的选中的物品id是否合法 int id; ItemData findItem; double addSilverNum = 0; double silverNum = 0; string queryStr = ""; for (int i = 0; i < ids.Count; i++) { id = (int)ids[i]; findItem = items.Find(find => find.PrimaryKeyId == id); if (findItem != null) { addSilverNum += findItem.SellPrice * findItem.Num; if (i > 0) { queryStr += " or "; } queryStr += ("Id = " + id); // queryStr += (i > 0 ? " or " : "" + ("Id = " + id)); } } //删除选中的物品 if (queryStr != "") { db.ExecuteQuery("delete from BagTable where " + queryStr); } //添加银子到资源 sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; if (sqReader.Read()) { string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); //查询目前的银子余额 ResourceData resource = resources.Find(re => re.Type == ResourceType.Silver); if (resource != null) { resource.Num += addSilverNum; silverNum = resource.Num; //加钱 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } } db.CloseSqlConnection(); Messenger.Broadcast <double>(NotifyTypes.SellItemsEcho, silverNum); Statics.CreatePopMsg(Vector3.zero, string.Format("{0} {1}", Statics.GetResourceName(ResourceType.Silver), "+" + addSilverNum.ToString()), Color.green, 30); }
/// <summary> /// 增减资源的工作家丁数 /// </summary> /// <param name="type">Type.</param> /// <param name="addNum">Add number.</param> public void ChangeResourceWorkerNum(ResourceType type, int addNum) { if (addNum == 0) { return; } addNum = Mathf.Clamp(addNum, -1, 1); JArray data = new JArray(); try { db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { // int workerNum = sqReader.GetInt32(sqReader.GetOrdinal("WorkerNum")); // int maxWorkerNum = sqReader.GetInt32(sqReader.GetOrdinal("MaxWorkerNum")); int workerNum = GetWorkerNum(); int maxWorkerNum = GetMaxWorkerNum(); if (addNum > 0 && workerNum == 0) { db.CloseSqlConnection(); return; } int id = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); string resourceDataStr = resourcesStr; List <ResourceData> resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourceDataStr); ResourceData findResource = resources.Find(item => item.Type == type); if (findResource != null) { if (addNum < 0 && findResource.WorkersNum == 0) { db.CloseSqlConnection(); return; } findResource.WorkersNum += addNum; findResource.WorkersNum = findResource.WorkersNum < 0 ? 0 : findResource.WorkersNum; workerNum -= addNum; workerNum = workerNum < 0 ? 0 : (workerNum > maxWorkerNum ? maxWorkerNum : workerNum); List <ResourceData> resultResources = returnAllReceiveResourcesOnece(resources); data.Add((short)type); data.Add(findResource.WorkersNum); data.Add(workerNum); data.Add(maxWorkerNum); data.Add(JsonManager.GetInstance().SerializeObject(resultResources)); //更新数据 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "', WorkerNum = " + workerNum + " where Id = " + id); SetWorkerNum(workerNum); } } db.CloseSqlConnection(); } catch (Exception e) { db.CloseSqlConnection(); Debug.LogWarning("ChangeResourceWorkerNum-------------------error:" + e.ToString() + " - " + e.StackTrace); return; } if (data.Count > 0) { Messenger.Broadcast <JArray>(NotifyTypes.ChangeResourceWorkerNumEcho, data); } }
/// <summary> /// 花费银子 /// </summary> /// <returns><c>true</c>, if silver was cost, <c>false</c> otherwise.</returns> /// <param name="num">Number.</param> public bool CostSilver(double num) { if (num <= 0) { return(false); } bool hasEnoughSilver = false; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); if (sqReader.Read()) { 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 resource = resources.Find(re => re.Type == ResourceType.Silver); if (resource != null) { if (resource.Num >= num) { hasEnoughSilver = true; resource.Num -= num; //扣钱 db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id"))); } } } db.CloseSqlConnection(); return(hasEnoughSilver); }
/// <summary> /// 打造兵器 /// </summary> /// <param name="weaponId">Weapon identifier.</param> public void CreateNewWeaponOfWorkshop(string weaponId) { db = OpenDb(); WeaponData weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", weaponId); List <ResourceData> needs = new List <ResourceData>(); ResourceData need; ResourceData find; for (int i = 0; i < weapon.Needs.Count; i++) { need = weapon.Needs[i]; find = needs.Find(item => item.Type == need.Type); if (find == null) { needs.Add(new ResourceData(need.Type, need.Num)); } else { find.Num += need.Num; } } SqliteDataReader sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; int id = 0; if (sqReader.Read()) { id = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); } db.CloseSqlConnection(); if (resources != null) { bool canAdd = true; string msg = ""; for (int i = 0; i < needs.Count; i++) { need = needs[i]; find = resources.Find(item => item.Type == need.Type); if (find != null && find.Num >= need.Num) { find.Num -= need.Num; } else { canAdd = false; msg = string.Format("{0}不足!", Statics.GetResourceName(need.Type)); break; } } if (canAdd) { //检测添加武器 if (AddNewWeapon(weapon.Id)) { db = OpenDb(); db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id); db.CloseSqlConnection(); Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(weapon.Quality), weapon.Name), Color.white, 30); SoundManager.GetInstance().PushSound("ui0007"); } else { AlertCtrl.Show("兵器匣已满!", null); } } else { AlertCtrl.Show(msg, null); } } }
/// <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(); }
/// <summary> /// 消耗资源 /// </summary> /// <returns><c>true</c>, if resource was cost, <c>false</c> otherwise.</returns> /// <param name="type">Type.</param> /// <param name="num">Number.</param> public bool CostResource(ResourceType type, int num) { ModifyResources(); bool result = false; db = OpenDb(); SqliteDataReader sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'"); List <ResourceData> resources = null; int id = 0; if (sqReader.Read()) { id = sqReader.GetInt32(sqReader.GetOrdinal("Id")); string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData")); resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr); } if (resources != null) { ResourceData find = resources.Find(item => item.Type == type); if (find != null && find.Num >= num) { find.Num -= num; db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id); result = true; } } db.CloseSqlConnection(); return(result); }
/// <summary> /// 装备秘籍 /// </summary> /// <param name="id">Identifier.</param> public void UseBook(int id) { //查询主角当前的兵器类型 WeaponType hostWeaponType = GetHostWeaponType(); db = OpenDb(); //查询角色信息 SqliteDataReader sqReader = db.ExecuteQuery("select RoleId, RoleData from RolesTable where RoleId = '" + currentRoleId + "' and BelongToRoleId = '" + currentRoleId + "'"); int addIndex = -1; if (sqReader.Read()) { string roleId = sqReader.GetString(sqReader.GetOrdinal("RoleId")); //获取角色数据 string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData")); roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr); RoleData role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr); sqReader = db.ExecuteQuery("select BookId, SeatNo from BooksTable where SeatNo >= 0 and State = " + ((int)BookStateType.Read) + " and BelongToRoleId = '" + currentRoleId + "'"); List <string> resourceBookDataIds = new List <string>(); List <int> seatNos = new List <int>() { -1, -1, -1 }; int seatNo; while (sqReader.Read()) { seatNo = sqReader.GetInt32(sqReader.GetOrdinal("SeatNo")); if (seatNos.Count > seatNo) { seatNos[seatNo] = seatNo; resourceBookDataIds.Add(sqReader.GetString(sqReader.GetOrdinal("BookId"))); } } addIndex = seatNos.FindIndex(item => item == -1); if (addIndex >= 0) { sqReader = db.ExecuteQuery("select BookId from BooksTable where Id = " + id); if (sqReader.Read()) { string bookId = sqReader.GetString(sqReader.GetOrdinal("BookId")); BookData bookData = JsonManager.GetInstance().GetMapping <BookData>("Books", bookId); if (bookData.LimitWeaponType == WeaponType.None || hostWeaponType == WeaponType.None || bookData.LimitWeaponType == hostWeaponType) { resourceBookDataIds.Add(bookId); db.ExecuteQuery("update BooksTable set SeatNo = " + addIndex + ", BeUsingByRoleId = '" + currentRoleId + "' where Id = " + id); //更新角色的秘籍信息 role.ResourceBookDataIds = resourceBookDataIds; db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + roleId + "'"); SoundManager.GetInstance().PushSound("ui0011"); } else { AlertCtrl.Show(string.Format("装备上[{0}]才能习练\n<color=\"{1}\">{2}</color>\n{3}", Statics.GetEnmuDesc <WeaponType>(bookData.LimitWeaponType), Statics.GetQualityColorString(bookData.Quality), bookData.Name, hostWeaponType != WeaponType.None ? ("你现在拿的是[" + Statics.GetEnmuDesc <WeaponType>(hostWeaponType) + "]") : "你现在手里没有任何兵器"), null); } } } } db.CloseSqlConnection(); if (addIndex >= 0) { GetBooksListPanelData(); CallRoleInfoPanelData(false); //刷新队伍数据 } else { AlertCtrl.Show("最多只能同时携带三本书!", null); } }