diff --git a/bot/bot.iss b/bot/bot.iss index 2d889b0..b31344f 100644 --- a/bot/bot.iss +++ b/bot/bot.iss @@ -1,32 +1,38 @@ - - -; objectdef CombatHelper -; { -; variable collection:CastStackAbility CastStack -; variable queue:CastStackAbility PrirortyAbilityQueue - -; method Initialize(jsonvalueref jsonCastStackConfig) -; { -; CastStack:FromJSON[jsonCastStackConfig] -; } - -; member:CastStackAbility CastNextAbility() -; { -; if ${PriorityAbilityQueue.Peek(exists)} -; { - -; } -; } - -; } - - - - objectdef BotController { variable bool IsBotRunning = FALSE variable bool IsShowingSettings = FALSE + variable jsonvalue savedSettings = "{}" + variable jsonvalue currentProfile = "{}" + variable jsoniterator castStackIterator + variable jsonvalue abilities = "{}" + + method Initialize() + { + LGUI2:LoadPackageFile["bot.json"] + + savedSettings:ParseFile["${LavishScript.HomeDirectory}/scripts/mr/bot/profiles/${Me.Name}_${Me.SubClass}.json"] + if ${savedSettings.Type.NotEqual["object"]} + { + echo "Error parsing saved settings" + return + } + + abilities:ParseFile["${LavishScript.HomeDirectory}/scripts/mr/bot/ability_exports/${Me.Name}_${Me.SubClass}.json"] + if ${jo.Type.NotEqual["object"]} + { + echo "Error parsing ability list" + return + } + + currentProfile:SetValue["${savedSettings.Get[${savedSettings.Get["default"]}]}"] + currentProfile.Get["castStack"]:GetIterator[castStackIterator] + } + + method Shutdown() + { + LGUI2:UnloadPackageFile["bot.json"] + } member:string StartButtonText() { @@ -52,43 +58,6 @@ objectdef BotController } } - ; member:string GetSettingsCheckBoxes() - ; { - ; variable jsonvalue checkboxes = "[]" - ; variable jsoniterator settingKeysIterator - - ; setttingKeys:GetIterator[settingsKeyIterator] - ; if ${settingKeysIterator:First(exists)} - ; { - ; echo "items" - ; do - ; { - ; echo "looping" - ; checkboxes:Add[$$> - ; { - ; "type": "checkbox", - ; "name": "${settingKeysIterator.Value.key}", - ; "content": "${settingKeysIterator.display_name}" - ; } - ; <$$] - ; } - ; while ${settingKeysIterator:Next(exists)} - ; } - ; echo "here ${checkboxes.AsJSON~}" - - ; return ${checkboxes.AsJSON~} - ; } - - method Initialize() - { - LGUI2:LoadPackageFile["bot.json"] - } - - method Shutdown() - { - LGUI2:UnloadPackageFile["bot.json"] - } - method OnClose() { Script:End @@ -119,47 +88,104 @@ objectdef BotController IsShowingSettings:Set[${IsShowingSettings.Not}] } + member:jsonvalueref GetHighestVersionOfAbility(string abilityName) + { + if !${abilityName(exists)} + { + echo "ability name not set" + return + } + + variable jsonvalueref highestVersion = "{}" + variable jsoniterator abilityIterator + abilities.Get["${abilityName}"]:GetIterator[abilityIterator] + + if ${abilityIterator:First(exists)} + { + do + { + if !${highestVersion.Get["level"]} + { + highestVersion:SetReference[abilityIterator.Value] + } + elseif ${highestVersion.Get["level"]} < ${abilityIterator.Value.Get["level"]} + { + highestVersion:SetReference[abilityIterator.Value] + } + } + while ${abilityIterator:Next(exists)} + } + + return highestVersion + } + + member:string GetBuiltinAlias(string aliasName) + { + if ${aliasName.Equal["@Me"]} + { + return Me.Name + } + } + + member:string GetActualTarget(string givenTarget) + { + if ${givenTarget.Left[1].Equal["*"]} + { + ; look up alias + } + elseif ${givenTarget.Left[1].Equal["@"]} + { + ; built up alias + return This.GetBuiltinAlias[${givenTarget}] + } + elseif ${givenTarget.Left[4].Equal["Pet:"]} + { + ; pet + } + else + { + return givenTarget + } + } + method Pulse() { - ; if ${IsBotRunning.Not} - ; { - ; return - ; } + if ${IsBotRunning.Not} + { + return + } - ; echo "Test: ${settings.IsSettingChecked["test"]}" - ; if ${Me.InCombat} - ; { - ; variable jsoniterator CastStackIterator - ; settings.CastStack:GetIterator[CastStackIterator] + variable int64 currentAbilityId + variable string abilityTarget - ; if ${CastStackIterator:First(exists)} - ; { - ; do - ; { - ; if ${CastStackIterator.Value.Get["AbilityType"].Equal["Heal"]} && ${Me.Health} < ${CastStackIterator.Value.Get["Percentage"]} - ; { - ; echo "Casting Heal ${CastStackIterator.Value.Name}" - ; return - ; } - ; elseif ${CastStackIterator.Value.Get["AbilityType"].Equal["Combat"]} && !${AbilityUsed.Element[${CastStackIterator.Value.Get["Name"]}]} - ; { - ; AbilityUsed:Set[${CastStackIterator.Value.Get["Name"]}, TRUE] - ; echo "using Combat ${CastStackIterator.Value.Get["Name"]}" - ; return - ; } - ; elseif ${CastStackIterator.Value.Get["AbilityType"].Equal["CA"]} && !${AbilityUsed.Element[${CastStackIterator.Value.Get["Name"]}]} - ; { - ; AbilityUsed:Set[${CastStackIterator.Value.Get["Name"]}, TRUE] - ; echo "using CA ${CastStackIterator.Value.Get["Name"]}" - ; return - ; } - ; else - ; { - ; } - ; } - ; while ${CastStackIterator:Next(exists)} - ; } - ; } + if ${Me.CastingSpell} + { + return + } + if ${castStackIterator:First(exists)} + { + do + { + if ${castStackIterator.Value.Get["action"].Equal["ability"]} && ${castStackIterator.Value.Get["type"].Equal["Buff"]} + { + currentAbilityId:Set[${This.GetHighestVersionOfAbility[${castStackIterator.Key}].Get["id"]}] + + if ${currentAbilityId} > 0 + { + if ${Me.Ability[id, ${currentAbilityId}].IsReady} + { + abilityTarget:Set[] + echo "Target ${castStackIterator.Value.Get["target"]}" + echo "Casting ${castStackIterator.Key}" + Me.Ability[id, ${currentAbilityId}]:Use + return + } + } + } + + } + while ${castStackIterator:Next(exists)} + } } } diff --git a/bot/cast_stack.json b/bot/cast_stack.json index 1c1402d..75290a0 100644 --- a/bot/cast_stack.json +++ b/bot/cast_stack.json @@ -16,7 +16,7 @@ "type": "textblock", "horizontalAlignment": "stretch", "textBinding": { - "pullFormat": "${_CONTEXTITEMDATA_.Get[Name]}" + "pullFormat": "${_CONTEXTITEMDATA_.Get[name]}" } } ] @@ -193,7 +193,7 @@ }, { "type": "textbox", - "name": "castStack.targetCount", + "name": "castStack.ability.targetCount", "horizontalAlignment": "stretch", "textBinding": { "pullFormat": "${MRSettingsController.SafeGetNewCastStackItemProperty[targetCount]}", @@ -536,7 +536,7 @@ "horizontalAlignment": "stretch", "heightFactor": 0.9, "itemsBinding": { - "pullFormat": "${MRSettingsController.CastOrder}" + "pullFormat": "${MRSettingsController.profile.Get[castStack].Keys}" } }, { diff --git a/bot/settings_controller.iss b/bot/settings_controller.iss index 14879e4..dc5858a 100644 --- a/bot/settings_controller.iss +++ b/bot/settings_controller.iss @@ -4,6 +4,7 @@ objectdef SettingsController { variable jsonvalue abilityListItems = "[]" + variable jsonvalue profile = "{}" variable jsonvalue currentCastStack = "[]" variable int currentSelectedAvailableAbilityIndex = -1 variable jsonvalue newCastStackItem = "{}" @@ -13,7 +14,7 @@ objectdef SettingsController LavishScript:RegisterEvent[onNewCastStackItemChanged] variable jsonvalue jo - jo:ParseFile["${LavishScript.HomeDirectory}/scripts/mr/bot/ability_exports/Ihaihu_shadowknight.json"] + jo:ParseFile["${LavishScript.HomeDirectory}/scripts/mr/bot/ability_exports/${Me.Name}_${Me.SubClass}.json"] if ${jo.Type.NotEqual["object"]} { echo "Error parsing ability list" @@ -31,17 +32,26 @@ objectdef SettingsController if ${jo.Get["${key}"].Get[1, "spellBookType"]} < 2 { abilityItem:SetValue["$$>{ - "Name": "${key~}", - "TargetType": ${jo.Get["${key}"].Get[1, "targetType"]}, - "IsBeneficial": ${jo.Get["${key}"].Get[1, "isBeneficial"]}, - "GroupRestricted": ${jo.Get["${key}"].Get[1, "groupRestricted"]}, - "MaxAoeTargets": ${jo.Get["${key}"].Get[1, "maxAoeTargets"]} + "name": "${key~}", + "targertType": ${jo.Get["${key}"].Get[1, "targetType"]}, + "isBeneficial": ${jo.Get["${key}"].Get[1, "isBeneficial"]}, + "groupRestricted": ${jo.Get["${key}"].Get[1, "groupRestricted"]}, + "maxAoeTargets": ${jo.Get["${key}"].Get[1, "maxAoeTargets"]} }<$$"] abilityListItems:Add["${abilityItem.AsJSON}"] } - } + + jo:ParseFile["${LavishScript.HomeDirectory}/scripts/mr/bot/profiles/ihaihu_shadowknight.json"] + if ${jo.Type.NotEqual["object"]} + { + echo "Error parsing profile" + return + } + + profile:SetValue["${jo.Get[${jo.Get["default"]}].AsJSON}"] + } method Shutdown() @@ -56,26 +66,37 @@ objectdef SettingsController { if ${abilityListItems.Get[${selectedAbilityIndex}, "TargetType"]} != 1 { - echo "Hide target: ${abilityListItems.Get[${selectedAbilityIndex}, "TargetType"]}" LGUI2.Element["castStack.ability.target"].Parent:SetVisibility[Hidden] } else { - echo "Show target: ${abilityListItems.Get[${selectedAbilityIndex}, "TargetType"]}" LGUI2.Element["castStack.ability.target"].Parent:SetVisibility[Visible] } } + method ToggleNumTargetsBySelectedAbilityId(int selectedAbilityIndex) + { + if ${abilityListItems.Get[${selectedAbilityIndex}, "MaxAoeTargets"]} > 1 + { + LGUI2.Element["castStack.ability.targetCount"].Parent:SetVisibility[Visible] + } + else + { + LGUI2.Element["castStack.ability.targetCount"].Parent:SetVisibility[Hidden] + } + } + method SetCurrentAbility(int selectedIndex) { This:ToggleTargetVisibilityBySelectedAbility[${selectedIndex}] + This:ToggleNumTargetsBySelectedAbilityId[${selectedIndex}] currentSelectedAvailableAbilityIndex:Set[${selectedIndex}] LGUI2.Element[MRSettingsController.events]:FireEventHandler[onNewCastStackItemChanged] newCastStackItem:SetValue["$$>{ "action": "ability", - "name": "${abilityListItems.Get[${selectedIndex}, "Name"]}" + "name": "${abilityListItems.Get[${selectedIndex}, "name"]}" }<$$"] } @@ -121,7 +142,7 @@ objectdef SettingsController method AddAbility() { - echo "AddAbility: ${newCastStackItem.AsJSON[multiline]~}" + currentCastStack:Add["${newCastStackItem.AsJSON}"] } }