* Restructured the code and moved the report creation to an independent module. Moved the IV sorting to the report module. The main module is now only doing IV finding.

* Changed the reported estimated CPs from values to formulas.
* Moved the localized Pokémon names from the DialogStrings to AddonConfiguration, so that they can also be used in the report, too.
* Changed the report logic to report the estimated maximum CPs of the last evolution forms, instead of several special rules.
* Localized the report headers.
This commit is contained in:
2017-06-08 17:13:28 +08:00
parent 4a663f7449
commit 1e9835372f
17 changed files with 2743 additions and 1824 deletions

View File

@ -25,6 +25,7 @@ Type aStats
nAttack As Integer
nDefense As Integer
mEvolved () As String
bIsLastForm As Boolean
End Type
' The individual values of a Pokémon.
@ -33,15 +34,10 @@ Type aIV
nStamina As Integer
nAttack As Integer
nDefense As Integer
' For sorting
nTotal As Integer
nMaxCP As Integer
maEvolved () As aEvolvedStats
End Type
' The calculated evolved stats of a Pokémon.
Type aEvolvedStats
nCP As Integer
nMaxCP As Integer
nMaxMaxCP As Integer
End Type
' The parameters to find the individual values.
@ -76,49 +72,30 @@ Sub subMain
If UBound (maIVs) = -1 Then
MsgBox fnGetResString ("ErrorNotFound")
Else
subSaveIV (aBaseStats, aQuery, maIVs)
subCreateReport (aBaseStats, aQuery, maIVs)
End If
End Sub
' fnFindIV: Finds the possible individual values of the Pokémon
Function fnFindIV ( _
aBaseStats As aStats, aQuery As aFindIVParam) As Variant
Dim nEvolved As Integer
Dim maEvBaseStats () As New aStats, aTempStats As New aStats
Dim maIV () As New aIV, aTempIV As New aIV
Dim maIV () As New aIV, nN As Integer
Dim fLevel As Double, nStamina As Integer
Dim nAttack As Integer, nDefense As integer
Dim nI As Integer, nJ As Integer
Dim fStep As Double, nN As Integer, fMaxLevel As Double
Dim nI As Integer, nJ As Integer, fLevelStep As Double
If aQuery.sPokemonId = "" Then
fnFindIV = maIV
Exit Function
End If
If aQuery.bIsNew Then
fStep = 1
fLevelStep = 1
Else
fStep = 0.5
fLevelStep = 0.5
End If
subReadStardust
nEvolved = UBound (aBaseStats.mEvolved)
If nEvolved > -1 Then
ReDim Preserve maEvBaseStats (nEvolved) As New aStats
For nI = 0 To nEvolved
aTempStats = fnGetBaseStats (aBaseStats.mEvolved (nI))
With maEvBaseStats (nI)
.nAttack = aTempStats.nAttack
.nDefense = aTempStats.nDefense
.nStamina = aTempStats.nStamina
End With
Next nI
End If
nN = -1
fMaxLevel = aQuery.nPlayerLevel + 1.5
If fMaxLevel > 40 Then
fMaxLevel = 40
End If
For fLevel = 1 To UBound (mStardust) Step fStep
For fLevel = 1 To UBound (mStardust) Step fLevelStep
If mStardust (CInt (fLevel - 0.5)) = aQuery.nStardust Then
For nStamina = 0 To 15
If fnCalcHP (aBaseStats, fLevel, nStamina) = aQuery.nHP Then
@ -133,30 +110,7 @@ Function fnFindIV ( _
.nAttack = nAttack
.nDefense = nDefense
.nStamina = nStamina
.nTotal = nAttack _
+ nDefense + nStamina
End With
If aQuery.nPlayerLevel <> 0 Then
maIV (nN).nMaxCP = fnCalcCP ( _
aBaseStats, fMaxLevel, _
nAttack, nDefense, nStamina)
End If
maIV (nN).maEvolved _
= fnGetEvolvedArray (nEvolved)
For nI = 0 To nEvolved
maIV (nN).maEvolved (nI).nCP _
= fnCalcCP ( _
maEvBaseStats (nI), _
fLevel, nAttack, _
nDefense, nStamina)
If aQuery.nPlayerLevel <> 0 Then
maIV (nN).maEvolved (nI).nMaxCP _
= fnCalcCP ( _
maEvBaseStats (nI), _
fMaxLevel, nAttack, _
nDefense, nStamina)
End If
Next nI
End If
Next nDefense
Next nAttack
@ -164,309 +118,9 @@ Function fnFindIV ( _
Next nStamina
End If
Next fLevel
' Sorts the IVs
For nI = 0 To UBound (maIV) - 1
For nJ = nI + 1 To UBound (maIV)
If fnCompareIV (maIV (nI), maIV (nJ)) > 0 Then
' This is an array of data. The data are actually
' allocated in sequences. maIV (nI) is not a
' reference. They cannot simply be assigned.
subCopyIV (maIV (nI), aTempIV)
subCopyIV (maIV (nJ), maIV (nI))
subCopyIV (aTempIV, maIV (nJ))
End If
Next nJ
Next nI
fnFindIV = maIV
End Function
' fnCompareIV: Compare two IVs for sorting
Function fnCompareIV (aIVa As aIV, aIVb As aIV) As Double
Dim nCPa As Integer, nCPb As Integer, nI As Integer
nCPa = aIVa.nMaxCP
For nI = 0 To UBound (aIVa.maEvolved)
If nCPa < aIVa.maEvolved (nI).nMaxCP Then
nCPa = aIVa.maEvolved (nI).nMaxCP
End If
Next nI
nCPb = aIVb.nMaxCP
For nI = 0 To UBound (aIVb.maEvolved)
If nCPb < aIVb.maEvolved (nI).nMaxCP Then
nCPb = aIVb.maEvolved (nI).nMaxCP
End If
Next nI
fnCompareIV = nCPb - nCPa
If fnCompareIV <> 0 Then
Exit Function
End If
nCPa = 0
For nI = 0 To UBound (aIVa.maEvolved)
If nCPa < aIVa.maEvolved (nI).nCP Then
nCPa = aIVa.maEvolved (nI).nCP
End If
Next nI
nCPb = 0
For nI = 0 To UBound (aIVb.maEvolved)
If nCPb < aIVb.maEvolved (nI).nCP Then
nCPb = aIVb.maEvolved (nI).nCP
End If
Next nI
fnCompareIV = nCPb - nCPa
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nTotal - aIVa.nTotal
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.fLevel - aIVa.fLevel
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nStamina - aIVa.nStamina
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nAttack - aIVa.nAttack
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nDefense - aIVa.nDefense
If fnCompareIV <> 0 Then
Exit Function
End If
End Function
' subCopyIV: Copies one IV to another
Function subCopyIV (aFrom As aIV, aTo As aIV) As Double
Dim nI As Integer
With aTo
.nAttack = aFrom.nAttack
.nDefense = aFrom.nDefense
.nStamina = aFrom.nStamina
.nTotal = aFrom.nTotal
.nMaxCP = aFrom.nMaxCP
End With
aTo.maEvolved = fnGetEvolvedArray (UBound (aFrom.maEvolved))
For nI = 0 To UBound (aFrom.maEvolved)
With aTo.maEvolved (nI)
.nCP = aFrom.maEvolved (nI).nCP
.nMaxCP = aFrom.maEvolved (nI).nMaxCP
End With
Next nI
End Function
' subSaveIV: Saves the found IV
Sub subSaveIV ( _
aBaseStats As aStats, aQuery As aFindIVParam, maIVs () As aIV)
Dim oDoc As Object, oSheet As Object
Dim oRange As Object, oColumns As Object, oRows As Object
Dim nI As Integer, nJ As Integer, nFront As Integer
Dim nEvolved As Integer
Dim mData (Ubound (maIVs) + 1) As Variant, mRow () As Variant
Dim mProps () As New com.sun.star.beans.PropertyValue
oDoc = StarDesktop.loadComponentFromURL ( _
"private:factory/scalc", "_default", 0, mProps)
oSheet = oDoc.getSheets.getByIndex (0)
nEvolved = UBound (maIVs (0).maEvolved) + 1
mRow = Array ( _
"No", "Pokemon", "CP", "HP", "Stardust", _
"Lv", "Atk", "Def", "Sta", "IV")
nFront = UBound (mRow)
If aQuery.sPokemonId = "Eevee" Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFront + 6) As Variant
mRow (nFront + 1) = "CP as " _
& aBaseStats.mEvolved (0)
mRow (nFront + 2) = "Powered-up as " _
& aBaseStats.mEvolved (0)
mRow (nFront + 3) = "CP as " _
& aBaseStats.mEvolved (1)
mRow (nFront + 4) = "Powered-up as " _
& aBaseStats.mEvolved (1)
mRow (nFront + 5) = "CP as " _
& aBaseStats.mEvolved (2)
mRow (nFront + 6) = "Powered-up as " _
& aBaseStats.mEvolved (2)
Else
ReDim Preserve mRow (nFront + 3) As Variant
mRow (nFront + 1) = "CP as " _
& aBaseStats.mEvolved (0)
mRow (nFront + 2) = "CP as " _
& aBaseStats.mEvolved (1)
mRow (nFront + 3) = "CP as " _
& aBaseStats.mEvolved (2)
End If
Else
If nEvolved = 0 Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFront + 1) As Variant
mRow (nFront + 1) = "Powered-up"
End If
Else
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFront + nEvolved + 1) As Variant
For nJ = 0 To nEvolved - 1
mRow (nFront + nJ + 1) = "CP as " _
& aBaseStats.mEvolved (nJ)
Next nJ
mRow (UBound (mRow)) = "Powered-up as " _
& aBaseStats.mEvolved (nEvolved - 1)
Else
ReDim Preserve mRow (nFront + nEvolved) As Variant
For nJ = 0 To nEvolved - 1
mRow (nFront + nJ + 1) = "CP as " _
& aBaseStats.mEvolved (nJ)
Next nJ
End If
End If
End If
mData (0) = mRow
For nI = 0 To UBound (maIVs)
mRow = Array ( _
"", "", "", "", "", _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina, _
maIVs (nI).nTotal / 45)
If aQuery.sPokemonId = "Eevee" Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFront + 6) As Variant
mRow (nFront + 1) = maIVs (nI).maEvolved (0).nCP
mRow (nFront + 2) = maIVs (nI).maEvolved (0).nMaxCP
mRow (nFront + 3) = maIVs (nI).maEvolved (1).nCP
mRow (nFront + 4) = maIVs (nI).maEvolved (1).nMaxCP
mRow (nFront + 5) = maIVs (nI).maEvolved (2).nCP
mRow (nFront + 6) = maIVs (nI).maEvolved (2).nMaxCP
Else
ReDim Preserve mRow (nFront + 3) As Variant
mRow (nFront + 1) = maIVs (nI).maEvolved (0).nCP
mRow (nFront + 2) = maIVs (nI).maEvolved (1).nCP
mRow (nFront + 3) = maIVs (nI).maEvolved (2).nCP
End If
Else
If nEvolved = 0 Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFront + 1) As Variant
mRow (nFront + 1) = maIVs (nI).nMaxCP
End If
Else
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFront + nEvolved + 1) As Variant
For nJ = 0 To nEvolved - 1
mRow (nFront + nJ + 1) = maIVs (nI).maEvolved (nJ).nCP
Next nJ
mRow (UBound (mRow)) = maIVs (nI).maEvolved (nEvolved - 1).nMaxCP
Else
ReDim Preserve mRow (nFront + nEvolved) As Variant
For nJ = 0 To nEvolved - 1
mRow (nFront + nJ + 1) = maIVs (nI).maEvolved (nJ).nCP
Next nJ
End If
End If
End If
mData (nI + 1) = mRow
Next nI
' Fills the query information at the first row
mData (1) (0) = aBaseStats.sNo
mData (1) (1) = aQuery.sPokemonName
mData (1) (2) = aQuery.nCP
mData (1) (3) = aQuery.nHP
mData (1) (4) = aQuery.nStardust
oRange = oSheet.getCellRangeByPosition ( _
0, 0, UBound (mData (0)), UBound (mData))
oRange.setDataArray (mData)
oRange.setPropertyValue ("VertJustify", _
com.sun.star.table.CellVertJustify.TOP)
oRange = oSheet.getCellRangeByPosition ( _
0, 1, 0, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
1, 1, 1, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
2, 1, 2, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
3, 1, 3, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
4, 1, 4, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, 1, 9, UBound (mData))
oRange.setPropertyValue ("NumberFormat", 10)
If aQuery.sPokemonId = "Eevee" Then
oRange = oSheet.getCellRangeByPosition ( _
10, 0, 15, 0)
Else
If nEvolved = 0 Then
oRange = oSheet.getCellRangeByPosition ( _
10, 0, 10, 0)
Else
oRange = oSheet.getCellRangeByPosition ( _
10, 0, 10 + nEvolved + 1, 0)
End If
End If
oRange.setPropertyValue ("IsTextWrapped", True)
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue ("Height", 840)
oColumns = oSheet.getColumns
oColumns.getByIndex (0).setPropertyValue ("Width", 890)
oColumns.getByIndex (1).setPropertyValue ("Width", 2310)
oColumns.getByIndex (2).setPropertyValue ("Width", 890)
oColumns.getByIndex (3).setPropertyValue ("Width", 890)
oColumns.getByIndex (4).setPropertyValue ("Width", 1780)
oColumns.getByIndex (5).setPropertyValue ("Width", 860)
oColumns.getByIndex (6).setPropertyValue ("Width", 860)
oColumns.getByIndex (7).setPropertyValue ("Width", 860)
oColumns.getByIndex (8).setPropertyValue ("Width", 860)
oColumns.getByIndex (9).setPropertyValue ("Width", 1030)
If aQuery.sPokemonId = "Eevee" Then
If aQuery.nPlayerLevel <> 0 Then
For nI = 0 To 5 Step 2
oColumns.getByIndex (10 + nI).setPropertyValue ( _
"Width", 2310)
oColumns.getByIndex (10 + nI + 1).setPropertyValue ( _
"Width", 2810)
Next nI
Else
For nI = 0 To 2
oColumns.getByIndex (10 + nI).setPropertyValue ( _
"Width", 2310)
Next nI
End If
Else
If nEvolved = 0 Then
If aQuery.nPlayerLevel <> 0 Then
oColumns.getByIndex (10).setPropertyValue ( _
"Width", 2200)
End If
Else
For nI = 0 To nEvolved - 1
oColumns.getByIndex (10 + nI).setPropertyValue ( _
"Width", 2310)
Next nI
If aQuery.nPlayerLevel <> 0 Then
oColumns.getByIndex ( _
10 + nEvolved).setPropertyValue ( _
"Width", 2810)
End If
End If
End If
End Sub
' fnFilterAppraisals: Filters the IV by the appraisals.
Function fnFilterAppraisals (aQuery As aFindIVParam, _
nAttack As Integer, nDefense As Integer, _
@ -585,8 +239,8 @@ Function fnGetCPM (fLevel As Double) As Double
If CInt (fLevel) = fLevel Then
fnGetCPM = mCPM (fLevel)
Else
fnGetCPM = ((mCpm (fLevel - 0.5) ^ 2 _
+ mCpm (fLevel + 0.5) ^ 2) / 2) ^ 0.5
fnGetCPM = ((mCPM (fLevel - 0.5) ^ 2 _
+ mCPM (fLevel + 0.5) ^ 2) / 2) ^ 0.5
End If
End Function
@ -595,56 +249,6 @@ Function fnFloor (fNumber As Double) As Integer
fnFloor = CInt (fNumber - 0.5)
End Function
' fnMapPokemonIdToName: Maps the Pokémon IDs to their localized names.
Function fnMapPokemonIdToName (sId As String) As String
fnMapPokemonIdToName = fnGetResString ("Pokemon" & sId)
End Function
' subReadBaseStats: Reads the base stats table.
Sub subReadBaseStats
Dim mData As Variant, nI As Integer, nJ As Integer
DIm nEvolved As Integer
If UBound (maBaseStats) = -1 Then
mData = fnGetBaseStatsData
ReDim Preserve maBaseStats (UBound (mData)) As New aStats
For nI = 0 To UBound (mData)
With maBaseStats (nI)
.sNo = mData (nI) (1)
.sPokemonId = mData (nI) (0)
.nStamina = mData (nI) (2)
.nAttack = mData (nI) (3)
.nDefense = mData (nI) (4)
End With
nEvolved = UBound (mData (nI) (5))
maBaseStats (nI).mEvolved = fnGetStringArray (nEvolved)
For nJ = 0 To nEvolved
maBaseStats (nI).mEvolved (nJ) = mData (nI) (5) (nJ)
Next nJ
Next nI
End If
End Sub
' fnGetStringArray: Obtains a blank string array
Function fnGetStringArray (nUBound As Integer) As Variant
Dim mData () As String
If nUBound >= 0 Then
ReDim Preserve mData (nUBound) As String
End If
fnGetStringArray = mData
End Function
' fnGetEvolvedArray: Obtains a blank aEvolvedStats array
Function fnGetEvolvedArray (nUBound As Integer) As Variant
Dim mData () As New aEvolvedStats
If nUBound >= 0 Then
ReDim Preserve mData (nUBound) As New aEvolvedStats
End If
fnGetEvolvedArray = mData
End Function
' fnReplace: Replaces all occurrances of a term to another.
Function fnReplace ( _
sText As String, sFrom As String, sTo As String) As String
@ -660,6 +264,37 @@ Function fnReplace ( _
fnReplace = sResult
End Function
' subReadBaseStats: Reads the base stats table.
Sub subReadBaseStats
Dim mData As Variant, nI As Integer, nJ As Integer, nK As Integer
Dim nEvolved As Integer, mEvolved () As Variant
If UBound (maBaseStats) = -1 Then
mData = fnGetBaseStatsData
ReDim Preserve maBaseStats (UBound (mData)) As New aStats
For nI = 0 To UBound (mData)
With maBaseStats (nI)
.sNo = mData (nI) (1)
.sPokemonId = mData (nI) (0)
.nStamina = mData (nI) (2)
.nAttack = mData (nI) (3)
.nDefense = mData (nI) (4)
End With
nEvolved = UBound (mData (nI) (5)) + 1
mEvolved = Array ()
maBaseStats (nI).bIsLastForm = True
If nEvolved > 0 Then
ReDim mEvolved (nEvolved - 1) As Variant
For nJ = 0 To nEvolved - 1
mEvolved (nJ) = mData (nI) (5) (nJ)
Next nJ
maBaseStats (nI).mEvolved = mEvolved
maBaseStats (nI).bIsLastForm = False
End If
Next nI
End If
End Sub
' subReadCPM: Reads the CPM table.
Sub subReadCPM
If UBound (mCPM) = -1 Then

View File

@ -50,6 +50,19 @@ Function fnAskParam As aFindIVParam
oDialog.getControl ("cbxBest3").setVisible (False)
oDialog.getControl ("lstMax").setVisible (False)
' Adds the Pokémons by their localized names.
subReadBaseStats
ReDim mPokemons (UBound (maBaseStats)) As String
For nI = 0 To UBound (maBaseStats)
mPokemons (nI) = fnGetResString ( _
"Pokemon" & maBaseStats (nI).sPokemonId)
Next nI
oList = oDialog.getControl ("lstPokemon")
If oList.getItemCount > 0 Then
getItemCount.removeItems (0, oList.getItemCount)
End If
oList.addItems (mPokemons, 0)
oDialog.getControl ("imgPokemon").getModel.setPropertyValue ( _
"ImageURL", fnGetImageUrl ("Unknown"))
oDialog.getControl ("imgTeamLogo").getModel.setPropertyValue ( _

379
PokemonGoIV/2Report.vb Normal file
View File

@ -0,0 +1,379 @@
' Copyright (c) 2017 imacat.
'
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.
' 2Report: The Pokémon GO IV report generator.
' by imacat <imacat@mail.imacat.idv.tw>, 2017-06-07
Option Explicit
' The base stats of a Pokémon.
Type aStats
sNo As String
sPokemonId As String
nStamina As Integer
nAttack As Integer
nDefense As Integer
mEvolved () As String
End Type
' The individual values of a Pokémon.
Type aIV
fLevel As Double
nStamina As Integer
nAttack As Integer
nDefense As Integer
' For sorting
nTotal As Integer
nMaxCP As Integer
nMaxMaxCP As Integer
End Type
' The parameters to find the individual values.
Type aFindIVParam
sPokemonId As String
sPokemonName As String
nCP As Integer
nHP As Integer
nStardust As Integer
nPlayerLevel As Integer
bIsNew As Boolean
nTotal As Integer
sBest As String
nMax As Integer
bIsCancelled As Boolean
End Type
' subCreateReport: Creates the Pokémon GO IV report.
Sub subCreateReport ( _
aBaseStats As aStats, aQuery As aFindIVParam, maIVs () As aIV)
Dim oDoc As Object, oSheet As Object
Dim oRange As Object, oColumns As Object, oRows As Object
Dim oCell As Object, sFormula As String
Dim nI As Integer, nJ As Integer, nCol As Integer
Dim nLeadCols As Integer, nTotalCols As Integer
Dim nEvolved As Integer, fMaxLevel As Double
Dim sCPM As String, sMaxCPM As String
Dim sColIVAttack As String, sColIVDefense As String
Dim sColIVStamina As String
Dim sPokemonName As String
Dim mData (Ubound (maIVs) + 1) As Variant, mRow () As Variant
Dim maEvBaseStats () As Variant
Dim mProps () As New com.sun.star.beans.PropertyValue
oDoc = StarDesktop.loadComponentFromURL ( _
"private:factory/scalc", "_default", 0, mProps)
oSheet = oDoc.getSheets.getByIndex (0)
nEvolved = UBound (aBaseStats.mEvolved) + 1
If nEvolved > 0 Then
ReDim maEvBaseStats (nEvolved - 1) As Variant
For nJ = 0 To nEvolved - 1
maEvBaseStats (nJ) = fnGetBaseStats (aBaseStats.mEvolved (nJ))
Next nJ
End If
If aQuery.nPlayerLevel <> 0 Then
fMaxLevel = aQuery.nPlayerLevel + 1.5
If fMaxLevel > 40 Then
fMaxLevel = 40
End If
Else
fMaxLevel = 40
End If
sMaxCPM = fnGetCPMFormula (fMaxLevel)
' Sorts the IVs
subSortIVs (aBaseStats, maEvBaseStats, maIVs, fMaxLevel)
' Fills in the report data.
mRow = Array ( _
fnGetResString ("ReportNo"), _
fnGetResString ("ReportPokemon"), _
fnGetResString ("ReportCP"), _
fnGetResString ("ReportHP"), _
fnGetResString ("ReportStardust"), _
fnGetResString ("ReportLevel"), _
fnGetResString ("ReportAttack"), _
fnGetResString ("ReportDefense"), _
fnGetResString ("ReportStamina"), _
fnGetResString ("ReportIVPercent"))
nLeadCols = UBound (mRow) + 1
nTotalCols = nLeadCols
If aBaseStats.bIsLastForm Then
nTotalCols = nTotalCols + 1
End If
For nJ = 0 To nEvolved - 1
nTotalCols = nTotalCols + 1
If maEvBaseStats (nJ).bIsLastForm Then
nTotalCols = nTotalCols + 1
End If
Next nJ
ReDim Preserve mRow (nTotalCols - 1) As Variant
nCol = nLeadCols
If aBaseStats.bIsLastForm Then
mRow (nCol) = fnReplace (fnGetResString ("ReportCPPowerUp"), _
"[Level]", fMaxLevel)
nCol = nCol + 1
End If
For nJ = 0 To nEvolved - 1
sPokemonName = fnGetResString ( _
"Pokemon" & aBaseStats.mEvolved (nJ))
mRow (nCol) = fnReplace (fnGetResString ("ReportCPEvolve"), _
"[Pokémon]", sPokemonName)
nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then
mRow (nCol) = fnReplace (fnReplace ( _
fnGetResString ("ReportCPEvolvePowerUp"), _
"[Pokémon]", sPokemonName), _
"[Level]", fMaxLevel)
End If
Next nJ
mData (0) = mRow
For nI = 0 To UBound (maIVs)
mRow = Array ( _
"", "", "", "", "", _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina, "")
ReDim Preserve mRow (nTotalCols - 1) As Variant
For nJ = nLeadCols To nEvolved - 1
mRow (nJ) = ""
Next nJ
mData (nI + 1) = mRow
Next nI
' Fills the query information at the first row
mData (1) (0) = aBaseStats.sNo
mData (1) (1) = aQuery.sPokemonName
mData (1) (2) = aQuery.nCP
mData (1) (3) = aQuery.nHP
mData (1) (4) = aQuery.nStardust
oRange = oSheet.getCellRangeByPosition ( _
0, 0, UBound (mData (0)), UBound (mData))
oRange.setDataArray (mData)
oRange.setPropertyValue ("VertJustify", _
com.sun.star.table.CellVertJustify.TOP)
' Fills in the CP calculation.
For nI = 0 To UBound (maIVs)
sCPM = fnGetCPMFormula (maIVs (nI).fLevel)
sColIVAttack = "G" & (nI + 2)
sColIVDefense = "H" & (nI + 2)
sColIVStamina = "I" & (nI + 2)
oCell = oSheet.getCellByPosition (nLeadCols - 1, nI + 1)
sFormula = "=(" & sColIVAttack & "+" & sColIVDefense _
& "+" & sColIVStamina & ")/45"
oCell.setFormula (sFormula)
nCol = nLeadCols
If aBaseStats.bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (aBaseStats, _
sColIVAttack, sColIVDefense, sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
nCol = nCol + 1
End If
For nJ = 0 To nEvolved - 1
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, sColIVStamina, sCPM)
oCell.setFormula (sFormula)
nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
nCol = nCol + 1
End If
Next nJ
Next nI
oRange = oSheet.getCellRangeByPosition ( _
0, 1, 0, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
1, 1, 1, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
2, 1, 2, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
3, 1, 3, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
4, 1, 4, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, 1, 9, UBound (mData))
oRange.setPropertyValue ("NumberFormat", 10)
oRange = oSheet.getCellRangeByPosition ( _
nLeadCols, 0, nTotalCols - 1, 0)
oRange.setPropertyValue ("IsTextWrapped", True)
oColumns = oSheet.getColumns
oColumns.getByIndex (0).setPropertyValue ("Width", 890)
oColumns.getByIndex (1).setPropertyValue ("Width", 2310)
oColumns.getByIndex (2).setPropertyValue ("Width", 890)
oColumns.getByIndex (3).setPropertyValue ("Width", 890)
oColumns.getByIndex (4).setPropertyValue ("Width", 1780)
oColumns.getByIndex (5).setPropertyValue ("Width", 860)
oColumns.getByIndex (6).setPropertyValue ("Width", 860)
oColumns.getByIndex (7).setPropertyValue ("Width", 860)
oColumns.getByIndex (8).setPropertyValue ("Width", 860)
oColumns.getByIndex (9).setPropertyValue ("Width", 1030)
For nJ = nLeadCols To nTotalCols - 1
oColumns.getByIndex (nJ).setPropertyValue ( _
"Width", 2810)
Next nJ
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue ("OptimalHeight", True)
End Sub
' subSortIVs: Sorts the IVs
Sub subSortIVs ( _
aBaseStats As aStats, maEvBaseStats () As aIV, _
maIVs () As aIV, fMaxLevel As Double)
Dim nI As Integer, nJ As Integer
Dim nCP As Integer
' Calculate the sorting keys.
For nI = 0 To UBound (maIVs) - 1
maIVs (nI).nTotal = maIVs (nI).nAttack + maIVs (nI).nDefense _
+ maIVs (nI).nStamina
maIVs (nI).nMaxCP = fnCalcCP (aBaseStats, _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina)
maIVs (nI).nMaxMaxCP = fnCalcCP (aBaseStats, _
fMaxLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina)
For nJ = 0 To UBound (aBaseStats.mEvolved)
nCP = fnCalcCP (maEvBaseStats (nJ), _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina)
If maIVs (nI).nMaxCP < nCP Then
maIVs (nI).nMaxCP = nCP
End If
nCP = fnCalcCP (maEvBaseStats (nJ), _
fMaxLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina)
If maIVs (nI).nMaxMaxCP < nCP Then
maIVs (nI).nMaxMaxCP = nCP
End If
Next nJ
Next nI
' Sort the IVs.
For nI = 0 To UBound (maIVs) - 1
For nJ = nI + 1 To UBound (maIVs)
If fnCompareIV (maIVs (nI), maIVs (nJ)) > 0 Then
' This is an array of data. The data are actually
' allocated in sequences. maIVs (nI) is not a
' reference. They cannot simply be assigned.
subSwapIV (maIVs (nI), maIVs (nJ))
End If
Next nJ
Next nI
End Sub
' fnCompareIV: Compare two IVs for sorting
Function fnCompareIV (aIVa As aIV, aIVb As aIV) As Double
Dim nCPa As Integer, nCPb As Integer, nI As Integer
fnCompareIV = aIVb.nMaxMaxCP - aIVa.nMaxMaxCP
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nMaxCP - aIVa.nMaxCP
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nTotal - aIVa.nTotal
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.fLevel - aIVa.fLevel
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nStamina - aIVa.nStamina
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nAttack - aIVa.nAttack
If fnCompareIV <> 0 Then
Exit Function
End If
fnCompareIV = aIVb.nDefense - aIVa.nDefense
If fnCompareIV <> 0 Then
Exit Function
End If
End Function
' subSwapIV: Swaps two IVs
Function subSwapIV (aIVa As aIV, aIVb As aIV) As Double
Dim aTempIV As New aIV
With aTempIV
.nAttack = aIVa.nAttack
.nDefense = aIVa.nDefense
.nStamina = aIVa.nStamina
.nTotal = aIVa.nTotal
.nMaxCP = aIVa.nMaxCP
.nMaxMaxCP = aIVa.nMaxMaxCP
End With
With aIVa
.nAttack = aIVb.nAttack
.nDefense = aIVb.nDefense
.nStamina = aIVb.nStamina
.nTotal = aIVb.nTotal
.nMaxCP = aIVb.nMaxCP
.nMaxMaxCP = aIVb.nMaxMaxCP
End With
With aIVb
.nAttack = aTempIV.nAttack
.nDefense = aTempIV.nDefense
.nStamina = aTempIV.nStamina
.nTotal = aTempIV.nTotal
.nMaxCP = aTempIV.nMaxCP
.nMaxMaxCP = aTempIV.nMaxMaxCP
End With
End Function
' fnGetCPFormula: Obtains the CP formula
Function fnGetCPFormula ( _
aBaseStats As aStats, sColIVAttack As String, _
sColIVDefense As String, sColIVStamina As String, _
sCPM As String) As String
fnGetCPFormula = "=FLOOR(" _
& "(" & aBaseStats.nAttack & "+" & sColIVAttack & ")" _
& "*SQRT(" & aBaseStats.nDefense & "+" & sColIVDefense & ")" _
& "*SQRT(" & aBaseStats.nStamina & "+" & sColIVStamina & ")" _
& "*POWER(" & sCPM & ";2)/10;1)"
End Function
' fnGetCPMFormula: Obtains the CPM
Function fnGetCPMFormula (fLevel As Double) As String
If fLevel = CInt (fLevel) Then
fnGetCPMFormula = "" & mCPM (fLevel)
Else
fnGetCPMFormula = "SQRT((" _
& "POWER(" & mCPM (fLevel - 0.5) & ";2)" _
& "+POWER(" & mCPM (fLevel + 0.5) & ";2))/2)"
End If
End Function

View File

@ -12,7 +12,7 @@
' See the License for the specific language governing permissions and
' limitations under the License.
' 2Data: The Pokémon GO data for IV calculation
' 3Data: The Pokémon GO data for IV calculation
' by imacat <imacat@mail.imacat.idv.tw>, 2017-03-01
' Generated with 9Load.subReadDataSheets ()

View File

@ -37,7 +37,7 @@ Sub subReadDataSheets
& "' See the License for the specific language governing permissions and" & Chr (10) _
& "' limitations under the License." & Chr (10) _
& Chr (10) _
& "' 2Data: The Pokémon GO data for IV calculation" & Chr (10) _
& "' 3Data: The Pokémon GO data for IV calculation" & Chr (10) _
& "' by imacat <imacat@mail.imacat.idv.tw>, " & Format (Date (), "yyyy-mm-dd") & Chr (10) _
& "' Generated with 9Load.subReadDataSheets ()" & Chr (10) _
& Chr (10) _