/// <summary> /// Gets the next skill ID from the skill to update, returns 0 if none is found. /// </summary> public static uint GetNextSkillID(SRSkill skill) { List <NameValueCollection> result = Database.GetResultFromQuery("SELECT id FROM skills WHERE group_id='" + skill.GroupID + "' AND level>" + skill.Level + " ORDER BY level LIMIT 1"); if (result.Count > 0) { return(uint.Parse(result[0]["id"])); } return(0); }
private void AttackLoop() { Window w = Window.Get; SRCoord myPosition, trainingPosition; int trainingRadius; bool doMovement = true; while (true) { // Check attacking params trainingPosition = w.TrainingArea_GetPosition(); if (trainingPosition == null) { w.Log("Training area it's not activated"); Stop(); return; } myPosition = InfoManager.Character.GetRealtimePosition(); trainingRadius = w.TrainingArea_GetRadius(); // Check movement if (doMovement) { // Avoid getting far away from training area if (myPosition.DistanceTo(trainingPosition) - trainingRadius < 50) { // Default time walking int timeTraveling = 3000; // Try to make a training movement if (w.Training_cbxWalkToCenter.Checked) { if (!myPosition.Equals(trainingPosition)) { // Move and wait timeTraveling = myPosition.TimeTo(trainingPosition, InfoManager.Character.GetMovementSpeed()); MoveTo(trainingPosition); w.LogProcess("Walking to center (" + timeTraveling + "ms)..."); WaitHandle.WaitAny(new WaitHandle[] { InfoManager.MonitorMobSpawnChanged, InfoManager.MonitorBuffRemoved }, timeTraveling); } } else { // Random walk int random = rand.Next(-trainingRadius, trainingRadius); // Take care about where am I SRCoord newPosition; if (trainingPosition.inDungeon()) { newPosition = new SRCoord(trainingPosition.PosX + random, trainingPosition.PosY + random, trainingPosition.Region, trainingPosition.Z); } else { newPosition = new SRCoord(trainingPosition.PosX + random, trainingPosition.PosY + random); } // Move and wait timeTraveling = myPosition.TimeTo(trainingPosition, InfoManager.Character.GetMovementSpeed()); MoveTo(newPosition); w.LogProcess("Walking randomly (" + timeTraveling + "ms)..."); WaitHandle.WaitAny(new WaitHandle[] { InfoManager.MonitorMobSpawnChanged, InfoManager.MonitorBuffRemoved }, timeTraveling); } doMovement = false; } else { // Too far away from training area w.Log("Attacking stopped, too far away from training area"); w.LogProcess("Far away from training area"); return; } } // Check buffs BuffLoop(); if (trainingRadius > 0) { // Attacking List <SRMob> mobs = InfoManager.Mobs.FindAll(m => trainingPosition.DistanceTo(m.GetRealtimePosition()) <= trainingRadius); SRMob mob = GetMobFiltered(mobs); if (mob == null) { // No mob to attack w.LogProcess("No mobs around to attack"); doMovement = true; continue; } else { // Load skills and iterate it SRSkill[] skillshots = w.Skills_GetSkillShots(mob.MobType); if (skillshots != null && skillshots.Length != 0) { // Try to select mob if (WaitSelectEntity(mob.UniqueID, 2, 250, "Selecting " + mob.Name + " (" + mob.MobType + ")...")) { // Iterate skills for (int k = 0; k <= skillshots.Length; k++) { // loop control if (k == skillshots.Length) { k = 0; } SRSkill skillshot = skillshots[k]; // Check if skill is enabled if (!skillshot.isCastingEnabled) { continue; } // Check and fix the weapon used for this skillshot SRTypes.Weapon myWeapon = GetWeaponUsed(); if (skillshot.ID == 1) { // Common attack, fix the basic skill if (myWeapon != SRTypes.Weapon.None) { skillshot = new SRSkill(DataManager.GetCommonAttack(myWeapon)); skillshot.Name = "Common Attack"; } } else { // Check the required weapon SRTypes.Weapon weaponRequired = skillshot.RequiredWeaponPrimary; w.LogProcess("Checking weapon required (" + weaponRequired + ")..."); while (myWeapon != weaponRequired) { // Check the first 4 slots from inventory int slotInventory = InfoManager.Character.Inventory.FindIndex(item => item.ID2 == 1 && item.ID3 == 6 && item.ID3 == (byte)weaponRequired, 13, 16); if (slotInventory != -1) { w.LogProcess("Changing weapon (" + myWeapon + ")..."); // Try to change it byte maxWeaponChangeAttempts = 5; // Check max. 4 times to skip the mob (max. 1 seconds actually) while (myWeapon != weaponRequired && maxWeaponChangeAttempts > 0) { PacketBuilder.MoveItem((byte)slotInventory, 6, SRTypes.InventoryItemMovement.InventoryToInventory); maxWeaponChangeAttempts--; InfoManager.MonitorWeaponChanged.WaitOne(250); myWeapon = GetWeaponUsed(); } if (maxWeaponChangeAttempts == 0) { w.LogProcess("Weapon changing failed!"); continue; } } else { w.LogProcess("Weapon required not found (" + myWeapon + ")..."); continue; } InfoManager.MonitorWeaponChanged.WaitOne(250); myWeapon = GetWeaponUsed(); } } // Check if mob is alive if (InfoManager.Mobs.ContainsKey(mob.UniqueID)) { w.LogProcess("Casting skill " + skillshot.Name + " (" + skillshot.CastingTime + "ms)..."); PacketBuilder.AttackTarget(mob.UniqueID, skillshot.ID); if (InfoManager.MonitorSkillCast.WaitOne(500)) { // Skill casted, create character cooldown Thread.Sleep(skillshot.CastingTime); } else { // Timeout: Skill not casted if (!InfoManager.Mobs.ContainsKey(mob.UniqueID)) { // Mob it's dead? break; } else { // Recast skillshot k--; continue; } } } else { // mob selection failed break; } } } } else { w.LogProcess("Skillshots not found"); } } } } }
private static void LoadCharacterSettings(string path) { lock (CharacterSettingsLock) { LoadingCharacterSettings = true; JObject root; // Load or create config root = path == "" ? new JObject() : JObject.Parse(File.ReadAllText(path)); Window w = Window.Get; #region (Character Tab) JObject Character = root.ContainsKey("Character") ? (JObject)root["Character"] : new JObject(); { JObject Inf = Character.ContainsKey("Info") ? (JObject)Character["Info"] : new JObject(); w.Character_cbxMessageExp.Checked = Inf.ContainsKey("ShowExp") ? (bool)Inf["ShowExp"] : false; w.Character_cbxMessageUniques.Checked = Inf.ContainsKey("ShowUniques") ? (bool)Inf["ShowUniques"] : false; w.Character_cbxMessageEvents.Checked = Inf.ContainsKey("ShowEvents") ? (bool)Inf["ShowEvents"] : false; w.Character_cbxMessagePicks.Checked = Inf.ContainsKey("ShowPicks") ? (bool)Inf["ShowPicks"] : false; JObject Potions = Character.ContainsKey("Potions") ? (JObject)Character["Potions"] : new JObject(); w.Character_cbxUseHP.Checked = Potions.ContainsKey("UseHP") ? (bool)Potions["UseHP"] : false; w.Character_tbxUseHP.Text = Potions.ContainsKey("UseHPPercent") ? (string)Potions["UseHPPercent"] : "50"; w.Character_cbxUseHPGrain.Checked = Potions.ContainsKey("UseHPGrain") ? (bool)Potions["UseHPGrain"] : false; w.Character_cbxUseHPVigor.Checked = Potions.ContainsKey("UseHPVigor") ? (bool)Potions["UseHPVigor"] : false; w.Character_cbxUseMP.Checked = Potions.ContainsKey("UseMP") ? (bool)Potions["UseMP"] : false; w.Character_tbxUseMP.Text = Potions.ContainsKey("UseMPPercent") ? (string)Potions["UseMPPercent"] : "50"; w.Character_cbxUseMPGrain.Checked = Potions.ContainsKey("UseMPGrain") ? (bool)Potions["UseMPGrain"] : false; w.Character_cbxUseMPVigor.Checked = Potions.ContainsKey("UseMPVigor") ? (bool)Potions["UseMPVigor"] : false; w.Character_cbxUsePillUniversal.Checked = Potions.ContainsKey("UseUniversalPills") ? (bool)Potions["UseUniversalPills"] : false; w.Character_cbxUsePillPurification.Checked = Potions.ContainsKey("UsePurificationPills") ? (bool)Potions["UsePurificationPills"] : false; w.Character_cbxUsePetHP.Checked = Potions.ContainsKey("UsePetHP") ? (bool)Potions["UsePetHP"] : false; w.Character_tbxUsePetHP.Text = Potions.ContainsKey("UsePetHPPercent") ? (string)Potions["UsePetHPPercent"] : "50"; w.Character_cbxUseTransportHP.Checked = Potions.ContainsKey("UseTransportHP") ? (bool)Potions["UseTransportHP"] : false; w.Character_tbxUseTransportHP.Text = Potions.ContainsKey("UseTransportHPPercent") ? (string)Potions["UseTransportHPPercent"] : "50"; w.Character_cbxUsePetsPill.Checked = Potions.ContainsKey("UsePetsPill") ? (bool)Potions["UsePetsPill"] : false; w.Character_cbxUsePetHGP.Checked = Potions.ContainsKey("UsePetHGP") ? (bool)Potions["UsePetHGP"] : false; w.Character_tbxUsePetHGP.Text = Potions.ContainsKey("UsePetHGPPercent") ? (string)Potions["UsePetHGPPercent"] : "50"; JObject Misc = Character.ContainsKey("Misc") ? (JObject)Character["Misc"] : new JObject(); w.Character_cbxAcceptRess.Checked = Misc.ContainsKey("AcceptRess") ? (bool)Misc["AcceptRess"] : false; w.Character_cbxAcceptRessPartyOnly.Checked = Misc.ContainsKey("AcceptRessPartyOnly") ? (bool)Misc["AcceptRessPartyOnly"] : false; w.Character_cbxRefuseExchange.Checked = Misc.ContainsKey("RefuseExchange") ? (bool)Misc["RefuseExchange"] : false; w.Character_cbxAcceptExchange.Checked = Misc.ContainsKey("AcceptExchange") ? (bool)Misc["AcceptExchange"] : false; w.Character_cbxAcceptExchangeLeaderOnly.Checked = Misc.ContainsKey("AcceptExchangePartyOnly") ? (bool)Misc["AcceptExchangePartyOnly"] : false; w.Character_cbxConfirmExchange.Checked = Misc.ContainsKey("ConfirmExchange") ? (bool)Misc["ConfirmExchange"] : false; w.Character_cbxApproveExchange.Checked = Misc.ContainsKey("ApproveExchange") ? (bool)Misc["ApproveExchange"] : false; } #endregion #region (Party Tab) JObject Party = root.ContainsKey("Party") ? (JObject)root["Party"] : new JObject(); { JObject Options = Party.ContainsKey("Options") ? (JObject)Party["Options"] : new JObject(); w.Party_rbnSetupExpFree.Checked = Options.ContainsKey("ExpFree") ? (bool)Options["ExpFree"] : true; w.Party_rbnSetupExpShared.Checked = !w.Party_rbnSetupExpFree.Checked; w.Party_rbnSetupItemFree.Checked = Options.ContainsKey("ItemFree") ? (bool)Options["ItemFree"] : true; w.Party_rbnSetupItemShared.Checked = !w.Party_rbnSetupItemFree.Checked; w.Party_cbxSetupMasterInvite.Checked = Options.ContainsKey("OnlyMasterInvite") ? (bool)Options["OnlyMasterInvite"] : false; w.Party_cbxAcceptOnlyPartySetup.Checked = Options.ContainsKey("AcceptOnlyPartySetup") ? (bool)Options["AcceptOnlyPartySetup"] : false; w.Party_cbxAcceptAll.Checked = Options.ContainsKey("AcceptAll") ? (bool)Options["AcceptAll"] : false; w.Party_cbxAcceptPartyList.Checked = Options.ContainsKey("AcceptPartyList") ? (bool)Options["AcceptPartyList"] : false; w.Party_cbxAcceptLeaderList.Checked = Options.ContainsKey("AcceptLeaderList") ? (bool)Options["AcceptLeaderList"] : false; w.Party_cbxLeavePartyNoneLeader.Checked = Options.ContainsKey("LeavePartyLeaderNotFound") ? (bool)Options["LeavePartyLeaderNotFound"] : false; w.Party_cbxRefuseInvitations.Checked = Options.ContainsKey("RefuseInvitations") ? (bool)Options["RefuseInvitations"] : false; w.Party_cbxActivateLeaderCommands.Checked = Options.ContainsKey("ActivateLeaderCommands") ? (bool)Options["ActivateLeaderCommands"] : false; w.Party_cbxInviteOnlyPartySetup.Checked = Options.ContainsKey("InviteOnlyPartySetup") ? (bool)Options["InviteOnlyPartySetup"] : false; w.Party_cbxInviteAll.Checked = Options.ContainsKey("InviteAll") ? (bool)Options["InviteAll"] : false; w.Party_cbxInvitePartyList.Checked = Options.ContainsKey("InvitePartyList") ? (bool)Options["InvitePartyList"] : false; w.Party_lstvPartyList.Items.Clear(); if (Options.ContainsKey("PartyList")) { foreach (JToken player in (JArray)Options["PartyList"]) { ListViewItem item = new ListViewItem((string)player); item.Name = item.Text.ToUpper(); w.Party_lstvPartyList.Items.Add(item); } } w.Party_lstvLeaderList.Items.Clear(); if (Options.ContainsKey("LeaderList")) { foreach (JToken leader in (JArray)Options["LeaderList"]) { ListViewItem item = new ListViewItem((string)leader); item.Name = item.Text.ToUpper(); w.Party_lstvLeaderList.Items.Add(item); } } JObject Match = Party.ContainsKey("Match") ? (JObject)Party["Match"] : new JObject(); w.Party_tbxMatchTitle.Text = Match.ContainsKey("Title") ? (string)Match["Title"] : "[xBot] When you play Silkroad you win or you die.."; w.Party_tbxMatchFrom.Text = Match.ContainsKey("From") ? (string)Match["From"] : "0"; w.Party_tbxMatchTo.Text = Match.ContainsKey("To") ? (string)Match["To"] : "255"; w.Party_cbxMatchAutoReform.Checked = Match.ContainsKey("AutoReform") ? (bool)Match["AutoReform"] : false; w.Party_cbxMatchAcceptAll.Checked = Match.ContainsKey("AcceptAll") ? (bool)Match["AcceptAll"] : true; w.Party_cbxMatchAcceptPartyList.Checked = Match.ContainsKey("AcceptPartyList") ? (bool)Match["AcceptPartyList"] : false; w.Party_cbxMatchAcceptLeaderList.Checked = Match.ContainsKey("AcceptLeaderList") ? (bool)Match["AcceptLeaderList"] : false; w.Party_cbxMatchRefuse.Checked = Match.ContainsKey("Refuse") ? (bool)Match["Refuse"] : false; } #endregion #region (Skills Tab) JObject Skills = root.ContainsKey("Skills") ? (JObject)root["Skills"] : new JObject(); { xDictionary <uint, SRSkill> mySkills = InfoManager.Character.Skills; JObject Attack = Skills.ContainsKey("Attack") ? (JObject)Skills["Attack"] : new JObject(); w.Skills_lstvAttackMobType_General.Items.Clear(); if (Attack.ContainsKey("General")) { foreach (JToken token in (JArray)Attack["General"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_General.Items.Add(item); } } } w.Skills_lstvAttackMobType_Champion.Items.Clear(); if (Attack.ContainsKey("Champion")) { foreach (JToken token in (JArray)Attack["Champion"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_Champion.Items.Add(item); } } } w.Skills_lstvAttackMobType_Giant.Items.Clear(); if (Attack.ContainsKey("Giant")) { foreach (JToken token in (JArray)Attack["Giant"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_Giant.Items.Add(item); } } } w.Skills_lstvAttackMobType_PartyGeneral.Items.Clear(); if (Attack.ContainsKey("PartyGeneral")) { foreach (JToken token in (JArray)Attack["PartyGeneral"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_PartyGeneral.Items.Add(item); } } } w.Skills_lstvAttackMobType_PartyChampion.Items.Clear(); if (Attack.ContainsKey("PartyChampion")) { foreach (JToken token in (JArray)Attack["PartyChampion"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_PartyChampion.Items.Add(item); } } } w.Skills_lstvAttackMobType_PartyGiant.Items.Clear(); if (Attack.ContainsKey("PartyGiant")) { foreach (JToken token in (JArray)Attack["PartyGiant"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_PartyGiant.Items.Add(item); } } } w.Skills_lstvAttackMobType_Unique.Items.Clear(); if (Attack.ContainsKey("Unique")) { foreach (JToken token in (JArray)Attack["Unique"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_Unique.Items.Add(item); } } } w.Skills_lstvAttackMobType_Elite.Items.Clear(); if (Attack.ContainsKey("Elite")) { foreach (JToken token in (JArray)Attack["Elite"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_Elite.Items.Add(item); } } } w.Skills_lstvAttackMobType_Event.Items.Clear(); if (Attack.ContainsKey("Event")) { foreach (JToken token in (JArray)Attack["Event"]) { string skillName = (string)token; SRSkill skill = mySkills.Find(s => s.Name == skillName); if (skill != null) { ListViewItem item = new ListViewItem(skillName); item.Name = skill.ID.ToString(); item.Tag = skill; w.Skills_lstvAttackMobType_Event.Items.Add(item); } } } w.Training_cbxWalkToCenter.Checked = Attack.ContainsKey("WalkToCenter") ? (bool)Attack["WalkToCenter"] : false; } #endregion #region (Training Tab) JObject Training = root.ContainsKey("Training") ? (JObject)root["Training"] : new JObject(); { JObject Area = Training.ContainsKey("Area") ? (JObject)Training["Area"] : new JObject(); string AreaActivated = Training.ContainsKey("AreaActivated") ? (string)Training["AreaActivated"] : ""; foreach (JProperty key in Area.Properties()) { JObject area = (JObject)Area[key.Name]; ListViewItem item = new ListViewItem(key.Name); item.Name = key.Name; ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem(); subitem.Tag = area.ContainsKey("Region") ? (ushort)area["Region"] : (ushort)0; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Tag = area.ContainsKey("X") ? (int)area["X"] : 0; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Tag = area.ContainsKey("Y") ? (int)area["Y"] : 0; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Tag = area.ContainsKey("Z") ? (int)area["Z"] : 0; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Tag = area.ContainsKey("Radius") ? (int)area["Radius"] : 0; item.SubItems.Add(subitem); item.SubItems.Add(area.ContainsKey("Path") ? (string)area["Path"] : ""); // Check if this area is activated if (AreaActivated != "" && AreaActivated == item.Name) { item.ForeColor = System.Drawing.Color.FromArgb(0, 180, 255); w.Training_lstvAreas.Tag = item; AreaActivated = ""; } w.Training_lstvAreas.Items.Add(item); } JObject Trace = Training.ContainsKey("Trace") ? (JObject)Training["Trace"] : new JObject(); w.Training_cbxTraceMaster.Checked = Trace.ContainsKey("TracePartyMaster") ? (bool)Trace["TracePartyMaster"] : false; w.Training_cbxTraceDistance.Checked = Trace.ContainsKey("UseTraceDistance") ? (bool)Trace["UseTraceDistance"] : false; w.Training_tbxTraceDistance.Text = Trace.ContainsKey("TraceDistance") ? (string)Trace["TraceDistance"] : "5"; } #endregion #region (Stall Tab) JObject Stall = root.ContainsKey("Stall") ? (JObject)root["Stall"] : new JObject(); { JObject Options = Stall.ContainsKey("Options") ? (JObject)Stall["Options"] : new JObject(); w.Stall_tbxStallTitle.Text = Options.ContainsKey("Title") ? (string)Options["Title"] : "[xBot] The things I do for love.."; w.Stall_tbxStallNote.Text = Options.ContainsKey("Note") ? (string)Options["Note"] : "[xBot] Fear cuts deeper than swords.."; } #endregion LoadingCharacterSettings = false; } }