public RoleData(string id, string name, Vector3 startPosition, string spriteSrc, WeaponData weaponData, bool isHost = false, float speed = 1.5f, int attack = 100, int defense = 100) { _id = id; _name = name; IsHost = isHost; StartPosition = startPosition; SpriteSrc = spriteSrc; WeaponData = weaponData; Speed = speed; Attack = attack; Defense = defense; }
/// <summary> /// 将索引映射成实体类 /// </summary> public void MakeJsonToModel() { Books.Clear(); BookData book; for (int i = 0; i < ResourceBookDataIds.Count; i++) { book = JsonManager.GetInstance().GetMapping <BookData>("Books", ResourceBookDataIds[i]); book.MakeJsonToModel(); Books.Add(book); } if (ResourceWeaponDataId != "") { Weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", ResourceWeaponDataId); } else { Weapon = null; } //处理伤势对全属性的影响 switch (Injury) { case InjuryType.None: default: injuryRate = 1; break; case InjuryType.White: injuryRate = 0.9f; break; case InjuryType.Yellow: injuryRate = 0.8f; break; case InjuryType.Purple: injuryRate = 0.6f; break; case InjuryType.Red: injuryRate = 0.2f; break; case InjuryType.Moribund: injuryRate = 0.1f; break; } InitAttribute(); }
/// <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")); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(sqReader.GetString(sqReader.GetOrdinal("ResourcesData"))); } 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 = '" + JsonManager.GetInstance().SerializeObject(resources) + "' where Id = " + id); resultId = primaryKeyId; } } db.CloseSqlConnection(); if (primaryKeyId > 0) { Messenger.Broadcast <int>(NotifyTypes.BreakWeaponEcho, primaryKeyId); } }
public void UpdateData(WeaponData weapon) { weaponData = weapon; info = ""; if (weaponData.Rates[3] > 0) { info += string.Format("<color=\"#FF0000\">追加100%伤害概率:{0}%</color>", (int)(weaponData.Rates[3] * 100)); } if (weaponData.Rates[2] > 0) { info += info == "" ? "" : "\n"; info += string.Format("<color=\"#FFA300\">追加50%伤害概率:{0}%</color>", (int)(weaponData.Rates[2] * 100)); } if (weaponData.Rates[1] > 0) { info += info == "" ? "" : "\n"; info += string.Format("<color=\"#DBFF00\">追加25%伤害概率:{0}%</color>", (int)(weaponData.Rates[1] * 100)); } if (weaponData.FixedDamagePlus != 0) { info += info == "" ? "" : "\n"; info += string.Format("固定伤害:{0}", (weaponData.FixedDamagePlus > 0 ? "+" : "") + weaponData.FixedDamagePlus.ToString()); } if (weaponData.DamageRatePlus != 0) { info += info == "" ? "" : "\n"; info += string.Format("最终伤害:{0}%", (weaponData.DamageRatePlus > 0 ? "+" : "") + (weaponData.DamageRatePlus * 100).ToString()); } if (weaponData.PhysicsAttackPlus != 0) { info += info == "" ? "" : "\n"; info += string.Format("外功:{0}", (weaponData.PhysicsAttackPlus > 0 ? "+" : "") + weaponData.PhysicsAttackPlus.ToString()); } if (weaponData.AttackSpeedPlus != 0) { info += info == "" ? "" : "\n"; info += string.Format("攻速:{0}", (weaponData.AttackSpeedPlus > 0 ? "+" : "") + weaponData.AttackSpeedPlus.ToString()); } info = info == "" ? "无任何附加属性" : info; }
/// <summary> /// 销毁多余的数据 /// </summary> public void Disposed() { Books.Clear(); Weapon = null; }
public void UpdateData(RoleData role) { roleData = role; roleData.MakeJsonToModel(); weapon = roleData.Weapon; }
/// <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: Eat(id, num); 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(); } 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(); } else { AlertCtrl.Show(string.Format("你已经习得<color=\"{0}\">{1}</color>, 无需再研读", Statics.GetQualityColorString(book.Quality), book.Name)); } break; default: AlertCtrl.Show("该物品不可使用!"); break; } } }
/// <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(); } } }
/// <summary> /// 将索引映射成实体类 /// </summary> public void MakeJsonToModel() { Books.Clear(); //防止没有秘籍,设置一本默认秘籍 if (ResourceBookDataIds.Count == 0) { ResourceBookDataIds.Add("10000"); } DrugResistance = 0; DisarmResistance = 0; VertigoResistance = 0; CanNotMoveResistance = 0; SlowResistance = 0; ChaosResistance = 0; BookData book; for (int i = 0; i < ResourceBookDataIds.Count; i++) { book = JsonManager.GetInstance().GetMapping <BookData>("Books", ResourceBookDataIds[i]); book.MakeJsonToModel(); DrugResistance += book.DrugResistance; DisarmResistance += book.DisarmResistance; VertigoResistance += book.VertigoResistance; CanNotMoveResistance += book.CanNotMoveResistance; SlowResistance += book.SlowResistance; ChaosResistance += book.ChaosResistance; Books.Add(book); } //将秘籍放在前面 // Books.Sort((a, b) => { return a.IsMindBook && !b.IsMindBook ? 1 : 0; }); if (ResourceWeaponDataId != "") { Weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", ResourceWeaponDataId); Weapon.Init(CurrentWeaponLV); } else { Weapon = null; } //处理伤势对全属性的影响 switch (Injury) { case InjuryType.None: default: injuryRate = 1; break; case InjuryType.White: injuryRate = 0.9f; break; case InjuryType.Yellow: injuryRate = 0.8f; break; case InjuryType.Purple: injuryRate = 0.6f; break; case InjuryType.Red: injuryRate = 0.2f; break; case InjuryType.Moribund: injuryRate = 0.1f; break; } //饥饿判定 全能力下降20% if (IsHungry) { injuryRate = Mathf.Clamp(injuryRate - 0.2f, 0.1f, 1); } InitAttribute(); }
/// <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="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="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; } } }
public void UpdateData(WeaponData weapon) { weaponData = weapon; PrimaryKeyId = weaponData.PrimaryKeyId; }
public void UpdateData(WeaponData weapon) { weaponData = weapon; }
/// <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); } } }
public void UpdateData(WeaponData weapon, WeaponData hostWeapon, RoleData host) { weaponData = weapon; hostWeaponData = hostWeapon; hostRoleData = host; }
public void UpdateData(WeaponData weapon, WeaponLVData lvData) { weaponData = weapon; UpdateData(lvData); }
/// <summary> /// 直接用工坊资源结交侠客 /// </summary> /// <param name="id">Identifier.</param> public void InviteRoleWithResources(int id) { 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")); resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(sqReader.GetString(sqReader.GetOrdinal("ResourcesData"))); } 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 = '" + 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); } }