-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerLevelingUI.ps1
278 lines (228 loc) · 8.52 KB
/
PowerLevelingUI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
Param(
[switch]$save_cache,
[int]$num_slots=12
)
$cache_file="$PSScriptRoot\gbData.json"
$cache_file2="$PSScriptRoot\gbShort.json"
if ($save_cache.IsPresent -or ! (test-path $cache_file) -or ! (test-path $cache_file2)) {
Retrieve-GbData
$gbData|ConvertTo-Json -Depth 99 -Compress | sc $cache_file
Retrieve-GbShortNames
$shortnames|ConvertTo-Json -Compress | sc $cache_file2
} else {
$gbData = gc $cache_file | ConvertFrom-Json
$shortnames = gc $cache_file2 | ConvertFrom-Json
}
function CycleNames{
$tName = $script:names[0]
$script:names = $script:names[1..($script:names.Count - 1)]
$script:names += $tName
}
function CycleSlots{
$script:names = @()
$script:sourceIDs=@()
$slot=1
while ($slot -le $num_slots) {
$tCkb=$grpNames.controls["ckbKeep$slot"]
$tTxt=$grpNames.controls["txtName$slot"]
if (! $tckb.Checked -and -not $tTxt.Text) {
$nextCkb = $grpNames.controls["ckbKeep$($slot+1)"]
$nextTxt = $grpNames.controls["txtName$($slot+1)"]
if (! $nextCkb.Checked -and $nextTxt.text) {
$tTxt.text = $nextTxt.text
$nextTxt.text = ''
}
}
$slot++
}
1..$num_slots|%{
$tCkb = $grpNames.controls["ckbKeep$_"]
if (! $tCkb.Checked) {
$tName = $grpNames.controls["txtName$_"].text
if ($tName) {
$script:names += $tName
$sourceIDs += $_
}
}
}
CycleNames
foreach ($sourceID in $sourceIDs){
$grpNames.controls["txtName$sourceID"].text = $script:names[$sourceIDs.indexof($sourceID)]
}
$numGBLvl.Value++
}
function Retrieve-GbShortNames{
Param([string]$url='https://foe.tools/_nuxt/42abc78.js')
Write-Information "Downloading GB Short Names from $url" -InformationAction Continue
try {
$jsShort = (IWR $url).content
$prefix='foe_data.gb_short'
$terminator='foe_data.goods'
$script:shortnames=@{}
$start_loc=$jsShort.IndexOf("`"$prefix")
$end_loc = $jsShort.IndexOf("`"$terminator") - $start_loc - 1
($jsShort.Substring($start_loc, $end_loc)) -split(',') -replace("$prefix\.|`"")|%{$gbname,$short = $_ -split(':'); $script:shortnames.$gbname = $short}
} catch {
write-warning 'error downloading'
}
}
function Retrieve-GbData{
Param([string]$url='https://foe.tools/foe-data/gbs-a85cea4.json')
Write-Information "Downloading updated GB data from $url" -InformationAction Continue
$script:gbData = IRM $url
}
Function Add-FormObject {
Param(
[alias('f')]$frm,
[alias('t')]$objType,
[alias('n')]$objName,
[alias('l','left')]$x,
[alias('top')]$y,
[alias('w')]$width,
[alias('h')]$height,
[alias('a')][switch]$autoSize,
[alias('am')]$autoSizeMode,
[alias('tx')]$text,
$tag,
[alias('i')][float]$increment,
[alias('d')][int]$decimals,
$padding,
$margin
)
if (!($frm -is "system.windows.forms.form" -or $frm -is "System.Windows.Forms.Control")) {
if ($frm -is "string" -and (Get-Variable $frm -ValueOnly) -is "System.Windows.Forms.Control") {
$frm = Get-Variable $frm -ValueOnly
}
}
$tObj = New-Object "$swf.$objType"
$tObj.Name = $objName
if ($text){
$tObj.text = $text
}
if ($x) {
$tObj.left = $x
}
if ($y){
$tObj.top = $y
}
if ($width){
$tObj.width = $width
}
if ($height){
$tObj.height = $height
}
if ($autoSize.IsPresent){
$tObj.autosize = $true
}
if ($autoSizeMode){
$tObj.autosizemode = $autoSizeMode
}
if ($tag){
$tObj.tag = $tag
}
if ($increment) {
$tObj.increment = $increment
}
if ($decimals) {
$tObj.decimalPlaces = $decimals
}
if ($padding){
if ($padding -is "hashtable") {
$tObj.padding = $padding
} else {
$tObj.padding.all = $padding
}
}
if ($margin){
if ($margin -is "hashtable") {
$tObj.margin = $margin
} else {
$tObj.margin.all = $margin
}
}
$frm.controls.add($tObj)
return $tObj
}
function Update-Slots{
$gbName = $cmbGB.selectedItem
$gbLvl = $numGBLvl.value
#$mult = $numMult.value
if (! $gbName -or ! $gbLvl <#-or ! $mult#>) {return}
$lvlData = $gbData.gbsData.$($gbName -replace(" |'", '_')).levels[$gbLvl - 1]
1..5|%{
$tMult = $grpNames.controls["numMult$_"].value
$tInvestAmt=[math]::Ceiling($lvlData.reward[$_-1].fp * $tMult)
if ($tInvestAmt -eq 0) {$tInvestAmt = 1}
$grpNames.controls["txtInvest$_"].text = $tInvestAmt
}
$ownerCost = $lvlData.cost - ((1..5|%{$grpNames.controls["txtInvest$_"].text})|Measure-Object -Sum).sum
$txtOwnerCost.text = $ownerCost
}
function Copy-NamesToClipboard{
$gbName = $cmbGB.selectedItem
$gbLvl = $numGBLvl.value
$mult = $numMult.value
$lvlData = $gbData.gbsData.$($gbName -replace(" |'", '_')).levels[$gbLvl - 1]
$owner = $txtOwner.text
$ownerCost = $lvlData.cost - ((1..5|%{$grpNames.controls["txtInvest$_"].text})|Measure-Object -Sum).sum
$header="$owner $($shortnames.($gbName -replace(" |'", '_'))) $($gbLvl -1) → $gbLvl"
$investors=[string]::Join("`n", $grpNames.controls.where({$_.name -match "txtInvest" -and $_.text}).foreach({"$($_.tag): $($grpNames.controls["txtName$($_.tag)"].Text) - $($_.text)" }))
$footer="(self: $ownerCost)"
"$header`n$investors`n$footer" | Set-Clipboard
}
function Show-ToolTip {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
[System.Windows.Forms.Control]$control,
[string]$text = $null,
[int]$duration = 1000
)
if ([string]::IsNullOrWhiteSpace($text)) { $text = $control.Tag }
$pos = @{x=$control.Right; y=$control.Top}
$obj_tt.Show($text,$this.parent, $pos, $duration)
}
$swf = "System.Windows.Forms"
$pad = 10
Add-Type -AssemblyName $swf
$form = New-Object "$swf.form"
$form.Text = "Power-Leveling Slot Cycling"
$form.Name = "PowerLeveling"
$form.AutoSize = $true
$form.AutoSizeMode = 'GrowAndShrink'
$form.Padding.Right = $pad
$grpNames = Add-FormObject $form -objType "GroupBox" -objName "grpNames" -x $pad -y $pad -autoSize -text "Lock Name Invest Mult" -margin $pad -padding $pad
1..$num_slots|%{
$tCkb=Add-FormObject $grpNames -objType checkbox -objName "ckbKeep$_" -x $pad -y (($pad *($_+1)) + (20*($_-1))) -text $_ -autoSize -tag "Keep slot $_ during cycle"
$tCkb.Add_MouseEnter({Show-ToolTip $this -text $this.tag})
$tCkb.Add_MouseLeave({$obj_tt.Hide($this.parent)})
$tTxt=Add-FormObject $grpNames -objType textbox -objName "txtName$_" -x ($tCkb.right + $pad) -y $tCkb.top -width 170 -tag $_
if ($_ -le 5) {
$tInv=Add-FormObject $grpNames -objType textbox -objName "txtInvest$_" -x ($tTxt.Right + $Pad *2) -y $tTxt.top -width 40 -margin @{right=10} -tag $_
$tInv.TabStop = $false
$tInv.Enabled = $false
$tMult=Add-FormObject $grpNames -objType numericUpDown -objName "numMult$_" -increment 0.01 -decimals 2 -text 1.90 -x ($tInv.Right + $Pad) -y $tInv.top -w 50 -margin $pad -tag $_
$tMult.Add_ValueChanged({Update-Slots})
}
}
$grpGB = Add-FormObject $form -objType GroupBox -objName grpGB -x ($grpNames.Right + $Pad*2) -y $grpNames.top -text "Victim:" -autosize -margin $pad -padding $pad
$lblOwner = Add-FormObject $grpGB -objType Label -objName lblOwner -x $pad -y ($pad * 2) -text "Name:" -autoSize
$txtOwner = Add-FormObject $grpGB -objType TextBox -objName txtOwner -x ($lblOwner.Right + $pad) -y ($lblOwner.top - 2) -width 175
$lblGB = Add-FormObject $grpGB -objType Label -objName lblGB -x ($pad) -y ($txtOwner.bottom + $pad ) -autoSize -text "GB:"
$cmbGB = Add-FormObject $grpGB -objType ComboBox -objName cmbGB -x ($lblGB.Right + $Pad) -y ($lblGB.top - 2) -width 150
$cmbGb.AutoCompleteMode = 'Append'
$cmbGB.AutoCompleteSource = 'ListItems'
$cmbGB.add_SelectedValueChanged({Update-Slots})
$gbData.gbs.PSObject.Properties.Name|sort|%{[void]($cmbGB.items.add($_ -replace('_', ' ') -replace(' s ', "'s ")))}
$lblGBLvl = Add-FormObject $grpGB -objType Label -objName lblGBLvl -x ($cmbGB.Right + $pad * 2) -y ($lblGB.top) -autoSize -text "→Lvl:"
$numGBLvl = Add-FormObject $grpGB -objType NumericUpDown -objName numGBLvl -x ($lblGBLvl.Right + $pad) -y $cmbGB.top -text 40 -w 40
$numGBLvl.Add_ValueChanged({Update-Slots})
$numGBLvl.Maximum=250
$lblOwnerCost = Add-FormObject $grpGB -objType Label -objName lblOwnerCost -x $pad -y ($cmbGB.bottom + $Pad) -autoSize -text "Owner cost:"
$txtOwnerCost = Add-FormObject $grpGB -objType TextBox -objName txtOwnerCost -x ($lblOwnerCost.right + $pad) -y ($lblOwnerCost.top - 2) -width 75
$btnCycle = Add-FormObject $form -objType button -objName btnCycle -text "Cycle Slots" -x $pad -y ($grpNames.Bottom + $pad*5) -autoSize
$btnCycle.add_Click({CycleSlots })
$btnCopy=(Add-FormObject $form -objType button -objName btnCopy -text "Copy to Clipboard" -x ($btnCycle.right + $Pad * 2) -y $btnCycle.top -autoSize)
$btnCopy.add_Click({Copy-NamesToClipboard})
$obj_tt = New-Object System.Windows.Forms.ToolTip $form.Container
$form.showdialog()