2016-11-29 14:23:00 +08:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
2016-12-05 16:44:04 +08:00
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="0Main" script:language="StarBasic">' 0Main: The main module for the Pokémon GO IV calculator
2016-11-29 14:23:00 +08:00
' by imacat <imacat@mail.imacat.idv.tw>, 2016-11-27
2016-11-28 00:18:16 +08:00
Option Explicit
2016-11-29 14:23:00 +08:00
' The stats of a Pokémon.
2016-11-28 00:18:16 +08:00
Type aStats
sNo As String
sPokemon As String
fLevel As Double
nStamina As Integer
nAttack As Integer
nDefense As Integer
nTotal As Integer
nMaxCP As Integer
2016-12-06 16:18:00 +08:00
maEvolvedForms () As aEvolveForm
2016-11-28 00:18:16 +08:00
End Type
2016-11-29 14:23:00 +08:00
' The amount of star dust to power-up.
2016-11-28 00:18:16 +08:00
Type aStarDust
fLevel As Double
nStarDust As Integer
End Type
2016-11-29 14:23:00 +08:00
' The parameters to find the individual values.
2016-11-28 00:18:16 +08:00
Type aFindIVParam
sPokemon As String
nCP As Integer
nHP As Integer
nStarDust As Integer
nPlayerLevel As Integer
bIsNew As Boolean
nAppraisal1 As Integer
sBest As String
nAppraisal2 As Integer
2016-11-29 10:41:36 +08:00
bIsCancelled As Boolean
2016-11-28 00:18:16 +08:00
End Type
2016-12-06 16:18:00 +08:00
Type aEvolveForm
sPokemon As String
nCP As Integer
nMaxCP As Integer
End Type
2016-11-28 23:00:20 +08:00
Private maBaseStats () As New aStats
Private mCPM () As Double, mStarDust () As Integer
2016-11-28 00:18:16 +08:00
2016-11-29 14:23:00 +08:00
' subMain: The main program
2016-11-28 00:18:16 +08:00
Sub subMain
2016-12-06 16:18:00 +08:00
Dim maIVs As Variant, nI As Integer
2016-11-28 00:18:16 +08:00
Dim aQuery As New aFindIVParam, aBaseStats As New aStats
2016-12-06 00:33:01 +08:00
aQuery = fnAskParam
2016-11-29 10:41:36 +08:00
If aQuery.bIsCancelled Then
Exit Sub
End If
2016-11-28 00:18:16 +08:00
maIVs = fnFindIV (aQuery)
2016-12-06 16:18:00 +08:00
If UBound (maIVs) = -1 Then
2016-11-29 14:23:00 +08:00
MsgBox "Found no matching IV."
2016-11-28 00:18:16 +08:00
Else
subSaveIV (aQuery, maIVs)
End If
End Sub
2016-11-29 15:02:15 +08:00
' fnAskParam: Asks the users for the parameters for the Pokémon.
Function fnAskParam As aFindIVParam
2016-12-06 00:33:01 +08:00
Dim oDialog As Object, oDialogModel As Object
Dim bIsBestAttack As Boolean, bIsBestDefense As Boolean
Dim bIsBestHP As Boolean
Dim aQuery As New aFindIVParam
2016-12-05 16:44:04 +08:00
2016-12-06 07:34:41 +08:00
DialogLibraries.loadLibrary "PokemonGoIV"
2016-12-05 16:44:04 +08:00
oDialog = CreateUnoDialog (DialogLibraries.PokemonGoIV.DlgMain)
2016-12-06 00:33:01 +08:00
oDialog.getControl ("lstApprasal1").setVisible (False)
oDialog.getControl ("txtBestBefore").setVisible (False)
oDialog.getControl ("lstBest").setVisible (False)
oDialog.getControl ("txtBestAfter").setVisible (False)
oDialog.getControl ("cbxBest2").setVisible (False)
oDialog.getControl ("cbxBest3").setVisible (False)
oDialog.getControl ("lstApprasal2").setVisible (False)
2016-12-05 16:44:04 +08:00
If oDialog.execute = 0 Then
aQuery.bIsCancelled = True
fnAskParam = aQuery
Exit Function
End If
With aQuery
.sPokemon = oDialog.getControl ("lstPokemon").getSelectedItem
.nCP = oDialog.getControl ("numCP").getValue
.nHP = oDialog.getControl ("numHP").getValue
.nStarDust = CInt (oDialog.getControl ("lstStarDust").getSelectedItem)
.nPlayerLevel = CInt (oDialog.getControl ("lstPlayerLevel").getSelectedItem)
.nAppraisal1 = oDialog.getControl ("lstApprasal1").getSelectedItemPos + 1
.nAppraisal2 = oDialog.getControl ("lstApprasal2").getSelectedItemPos + 1
.bIsCancelled = False
End With
If oDialog.getControl ("cbxIsNew").getState = 1 Then
aQuery.bIsNew = True
Else
aQuery.bIsNew = False
End If
2016-12-06 07:34:41 +08:00
2016-12-06 00:33:01 +08:00
' The best stats
bIsBestAttack = False
bIsBestDefense = False
bIsBestHP = False
If oDialog.getControl ("lstBest").getSelectedItem = "Attack" Then
bIsBestAttack = True
If oDialog.getControl ("cbxBest2").getState = 1 Then
bIsBestDefense = True
End If
If oDialog.getControl ("cbxBest3").getState = 1 Then
bIsBestHP = True
End If
End If
If oDialog.getControl ("lstBest").getSelectedItem = "Defense" Then
bIsBestDefense = True
If oDialog.getControl ("cbxBest2").getState = 1 Then
bIsBestAttack = True
End If
If oDialog.getControl ("cbxBest3").getState = 1 Then
bIsBestHP = True
End If
End If
If oDialog.getControl ("lstBest").getSelectedItem = "HP" Then
bIsBestHP = True
If oDialog.getControl ("cbxBest2").getState = 1 Then
bIsBestAttack = True
End If
If oDialog.getControl ("cbxBest3").getState = 1 Then
bIsBestDefense = True
End If
End If
2016-12-05 16:44:04 +08:00
aQuery.sBest = ""
2016-12-06 00:33:01 +08:00
If bIsBestAttack Then
2016-12-05 16:44:04 +08:00
aQuery.sBest = aQuery.sBest & "Atk "
End If
2016-12-06 00:33:01 +08:00
If bIsBestDefense Then
2016-12-05 16:44:04 +08:00
aQuery.sBest = aQuery.sBest & "Def "
End If
2016-12-06 00:33:01 +08:00
If bIsBestHP Then
2016-12-05 16:44:04 +08:00
aQuery.sBest = aQuery.sBest & "Sta "
End If
2016-12-06 07:34:41 +08:00
2016-12-05 16:44:04 +08:00
fnAskParam = aQuery
End Function
' fnAskParam: Asks the users for the parameters for the Pokémon.
Function fnAskParam0 As aFindIVParam
2016-11-29 15:02:15 +08:00
Dim oDialog As Object, oDialogModel As Object
Dim oTextModel As Object, oListModel As Object
Dim oNumericModel As Object, oCheckBoxModel As Object
2016-12-05 16:44:04 +08:00
Dim oGroupModel As Object, oRadioModel As Object
Dim oButtonModel As Object, oListener As Object
2016-11-29 15:02:15 +08:00
Dim mListItems () As String, sTemp As String
Dim nI As Integer, nCount As Integer
2016-12-05 16:44:04 +08:00
Dim bIsBestAttack As Boolean, bIsBestDefense As Boolean
Dim bIsBestHP As Boolean
2016-11-29 15:02:15 +08:00
Dim aQuery As New aFindIVParam
' Creates a dialog
oDialogModel = CreateUnoService ( _
"com.sun.star.awt.UnoControlDialogModel")
oDialogModel.setPropertyValue ("PositionX", 100)
oDialogModel.setPropertyValue ("PositionY", 100)
2016-12-05 16:44:04 +08:00
oDialogModel.setPropertyValue ("Height", 185)
2016-11-29 15:02:15 +08:00
oDialogModel.setPropertyValue ("Width", 220)
2016-12-05 16:44:04 +08:00
oDialogModel.setPropertyValue ("Title", "Pokémon GO IV Calculator")
2016-11-29 15:02:15 +08:00
' Adds a text label for the Pokémon list.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 6)
oTextModel.setPropertyValue ("Height", 8)
2016-11-29 15:02:15 +08:00
oTextModel.setPropertyValue ("Width", 30)
oTextModel.setPropertyValue ("Label", "~Pokémon:")
oDialogModel.insertByName ("txtPokemon", oTextModel)
' Adds the Pokémon list.
subReadBaseStats
ReDim mListItems (UBound (maBaseStats)) As String
For nI = 0 To UBound (maBaseStats)
mListItems (nI) = maBaseStats (nI).sPokemon
Next nI
oListModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel.setPropertyValue ("PositionX", 35)
oListModel.setPropertyValue ("PositionY", 4)
oListModel.setPropertyValue ("Height", 12)
oListModel.setPropertyValue ("Width", 50)
oListModel.setPropertyValue ("TabIndex", 0)
oListModel.setPropertyValue ("Dropdown", True)
oListModel.setPropertyValue ("StringItemList", mListItems)
oDialogModel.insertByName ("lstPokemon", oListModel)
' Adds a text label for the CP field.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 5)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 21)
oTextModel.setPropertyValue ("Height", 8)
2016-11-29 15:02:15 +08:00
oTextModel.setPropertyValue ("Width", 15)
oTextModel.setPropertyValue ("Label", "~CP:")
oDialogModel.insertByName ("txtCP", oTextModel)
' Adds the CP field.
oNumericModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlNumericFieldModel")
oNumericModel.setPropertyValue ("PositionX", 20)
oNumericModel.setPropertyValue ("PositionY", 19)
oNumericModel.setPropertyValue ("Height", 12)
oNumericModel.setPropertyValue ("Width", 20)
oNumericModel.setPropertyValue ("DecimalAccuracy", 0)
oDialogModel.insertByName ("numCP", oNumericModel)
' Adds a text label for the HP field.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 50)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 21)
oTextModel.setPropertyValue ("Height", 8)
2016-11-29 15:02:15 +08:00
oTextModel.setPropertyValue ("Width", 15)
oTextModel.setPropertyValue ("Label", "~HP:")
oDialogModel.insertByName ("txtHP", oTextModel)
' Adds the HP field.
oNumericModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlNumericFieldModel")
oNumericModel.setPropertyValue ("PositionX", 65)
oNumericModel.setPropertyValue ("PositionY", 19)
oNumericModel.setPropertyValue ("Height", 12)
oNumericModel.setPropertyValue ("Width", 15)
oNumericModel.setPropertyValue ("DecimalAccuracy", 0)
oDialogModel.insertByName ("numHP", oNumericModel)
' Adds a text label for the star dust field.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 90)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 21)
oTextModel.setPropertyValue ("Height", 8)
2016-11-29 15:02:15 +08:00
oTextModel.setPropertyValue ("Width", 30)
oTextModel.setPropertyValue ("Label", "S~tar dust:")
oDialogModel.insertByName ("txtStarDust", oTextModel)
' Adds the star dust field.
subReadStarDust
sTemp = " "
ReDim mListItems () As String
nCount = -1
For nI = 1 To UBound (mStarDust)
If InStr (sTemp, " " & CStr (mStarDust (nI)) & " ") = 0 Then
nCount = nCount + 1
ReDim Preserve mListItems (nCount) As String
mListItems (nCount) = CStr (mStarDust (nI))
sTemp = sTemp & CStr (mStarDust (nI)) & " "
End If
Next nI
oListModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel.setPropertyValue ("PositionX", 120)
oListModel.setPropertyValue ("PositionY", 19)
oListModel.setPropertyValue ("Height", 12)
oListModel.setPropertyValue ("Width", 30)
oListModel.setPropertyValue ("Dropdown", True)
oListModel.setPropertyValue ("StringItemList", mListItems)
oDialogModel.insertByName ("lstStarDust", oListModel)
' Adds a text label for the player level field.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 160)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 21)
oTextModel.setPropertyValue ("Height", 8)
2016-11-29 15:02:15 +08:00
oTextModel.setPropertyValue ("Width", 35)
oTextModel.setPropertyValue ("Label", "Player ~level:")
oDialogModel.insertByName ("txtPlayerLevel", oTextModel)
' Adds the player level field.
ReDim mListItems (39) As String
For nI = 0 To UBound (mListItems)
mListItems (nI) = CStr (nI + 1)
Next nI
oListModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel.setPropertyValue ("PositionX", 195)
oListModel.setPropertyValue ("PositionY", 19)
oListModel.setPropertyValue ("Height", 12)
oListModel.setPropertyValue ("Width", 20)
oListModel.setPropertyValue ("Dropdown", True)
oListModel.setPropertyValue ("StringItemList", mListItems)
oDialogModel.insertByName ("lstPlayerLevel", oListModel)
' Adds the whether powered-up check box.
oCheckBoxModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlCheckBoxModel")
oCheckBoxModel.setPropertyValue ("PositionX", 5)
2016-12-05 16:44:04 +08:00
oCheckBoxModel.setPropertyValue ("PositionY", 36)
oCheckBoxModel.setPropertyValue ("Height", 8)
2016-11-29 15:02:15 +08:00
oCheckBoxModel.setPropertyValue ("Width", 210)
oCheckBoxModel.setPropertyValue ("Label", _
"This Pokémon is ~newly-caught and was not powered-up yet.")
oCheckBoxModel.setPropertyValue ("State", 1)
oDialogModel.insertByName ("cbxIsNew", oCheckBoxModel)
' Adds a group for the appraisals
oGroupModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlGroupBoxModel")
oGroupModel.setPropertyValue ("PositionX", 5)
oGroupModel.setPropertyValue ("PositionY", 50)
2016-12-05 16:44:04 +08:00
oGroupModel.setPropertyValue ("Height", 110)
2016-11-29 15:02:15 +08:00
oGroupModel.setPropertyValue ("Width", 210)
2016-12-05 16:44:04 +08:00
oGroupModel.setPropertyValue ("Label", "Team Leader Apprasal")
2016-11-29 15:02:15 +08:00
oDialogModel.insertByName ("grpApprasals", oGroupModel)
2016-12-05 16:44:04 +08:00
' Adds a text label for the team.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 10)
oTextModel.setPropertyValue ("PositionY", 66)
oTextModel.setPropertyValue ("Height", 8)
oTextModel.setPropertyValue ("Width", 20)
oTextModel.setPropertyValue ("Label", "Team:")
oDialogModel.insertByName ("txtTeam", oTextModel)
' Adds the red team radio button.
oRadioModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlRadioButtonModel")
oRadioModel.setPropertyValue ("PositionX", 30)
oRadioModel.setPropertyValue ("PositionY", 66)
oRadioModel.setPropertyValue ("Height", 8)
oRadioModel.setPropertyValue ("Width", 25)
oRadioModel.setPropertyValue ("Label", "~Valor")
oRadioModel.setPropertyValue ("TextColor", RGB (255, 255, 255))
oRadioModel.setPropertyValue ("BackgroundColor", RGB (255, 0, 0))
oDialogModel.insertByName ("rdoTeamRed", oRadioModel)
' Adds the blue team radio button.
oRadioModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlRadioButtonModel")
2016-12-06 00:33:01 +08:00
oRadioModel.setPropertyValue ("PositionX", 60)
2016-12-05 16:44:04 +08:00
oRadioModel.setPropertyValue ("PositionY", 66)
oRadioModel.setPropertyValue ("Height", 8)
oRadioModel.setPropertyValue ("Width", 30)
oRadioModel.setPropertyValue ("Label", "~Mystic")
oRadioModel.setPropertyValue ("TextColor", RGB (255, 255, 255))
oRadioModel.setPropertyValue ("BackgroundColor", RGB (0, 0, 255))
oDialogModel.insertByName ("rdoTeamBlue", oRadioModel)
' Adds the yellow team radio button.
oRadioModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlRadioButtonModel")
2016-12-06 00:33:01 +08:00
oRadioModel.setPropertyValue ("PositionX", 95)
2016-12-05 16:44:04 +08:00
oRadioModel.setPropertyValue ("PositionY", 66)
oRadioModel.setPropertyValue ("Height", 8)
oRadioModel.setPropertyValue ("Width", 30)
oRadioModel.setPropertyValue ("Label", "~Instinct")
oRadioModel.setPropertyValue ("BackgroundColor", RGB (255, 255, 0))
oDialogModel.insertByName ("rdoTeamYellow", oRadioModel)
2016-11-29 15:02:15 +08:00
' Adds the first appraisal list.
oListModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel.setPropertyValue ("PositionX", 10)
2016-12-05 16:44:04 +08:00
oListModel.setPropertyValue ("PositionY", 79)
2016-11-29 15:02:15 +08:00
oListModel.setPropertyValue ("Height", 12)
oListModel.setPropertyValue ("Width", 200)
oListModel.setPropertyValue ("Dropdown", True)
oDialogModel.insertByName ("lstApprasal1", oListModel)
2016-12-05 16:44:04 +08:00
' Adds a text label before the best stat.
2016-11-29 15:02:15 +08:00
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
oTextModel.setPropertyValue ("PositionX", 10)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 96)
oTextModel.setPropertyValue ("Height", 8)
2016-12-06 00:33:01 +08:00
oTextModel.setPropertyValue ("Width", 20)
2016-12-05 16:44:04 +08:00
oDialogModel.insertByName ("txtBestBefore", oTextModel)
2016-11-29 15:02:15 +08:00
2016-12-05 16:44:04 +08:00
' Adds the best stat field.
oListModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
2016-12-06 00:33:01 +08:00
oListModel.setPropertyValue ("PositionX", 30)
2016-12-05 16:44:04 +08:00
oListModel.setPropertyValue ("PositionY", 94)
oListModel.setPropertyValue ("Height", 12)
oListModel.setPropertyValue ("Width", 35)
oListModel.setPropertyValue ("Dropdown", True)
oDialogModel.insertByName ("lstBest", oListModel)
' Adds a text label after the best stat.
oTextModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlFixedTextModel")
2016-12-06 00:33:01 +08:00
oTextModel.setPropertyValue ("PositionX", 65)
2016-12-05 16:44:04 +08:00
oTextModel.setPropertyValue ("PositionY", 96)
oTextModel.setPropertyValue ("Height", 8)
oTextModel.setPropertyValue ("Width", 100)
oDialogModel.insertByName ("txtBestAfter", oTextModel)
' Adds the second best stat check box.
2016-11-29 15:02:15 +08:00
oCheckBoxModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlCheckBoxModel")
2016-12-05 16:44:04 +08:00
oCheckBoxModel.setPropertyValue ("PositionX", 10)
oCheckBoxModel.setPropertyValue ("PositionY", 111)
oCheckBoxModel.setPropertyValue ("Height", 8)
2016-12-06 00:33:01 +08:00
oCheckBoxModel.setPropertyValue ("Width", 200)
2016-12-05 16:44:04 +08:00
oDialogModel.insertByName ("cbxBest2", oCheckBoxModel)
' Adds the third best stat check box.
2016-11-29 15:02:15 +08:00
oCheckBoxModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlCheckBoxModel")
2016-12-05 16:44:04 +08:00
oCheckBoxModel.setPropertyValue ("PositionX", 10)
oCheckBoxModel.setPropertyValue ("PositionY", 126)
oCheckBoxModel.setPropertyValue ("Height", 8)
2016-12-06 00:33:01 +08:00
oCheckBoxModel.setPropertyValue ("Width", 200)
2016-12-05 16:44:04 +08:00
oDialogModel.insertByName ("cbxBest3", oCheckBoxModel)
2016-11-29 15:02:15 +08:00
' Adds the second appraisal list.
oListModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlListBoxModel")
oListModel.setPropertyValue ("PositionX", 10)
2016-12-06 00:33:01 +08:00
oListModel.setPropertyValue ("PositionY", 139)
2016-11-29 15:02:15 +08:00
oListModel.setPropertyValue ("Height", 12)
oListModel.setPropertyValue ("Width", 200)
oListModel.setPropertyValue ("Dropdown", True)
oDialogModel.insertByName ("lstApprasal2", oListModel)
' Adds the OK button.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 35)
2016-12-05 16:44:04 +08:00
oButtonModel.setPropertyValue ("PositionY", 165)
2016-11-29 15:02:15 +08:00
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 60)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.OK)
oButtonModel.setPropertyValue ("DefaultButton", True)
2016-12-06 16:58:24 +08:00
oButtonModel.setPropertyValue ("Enabled", False)
2016-11-29 15:02:15 +08:00
oDialogModel.insertByName ("btnOK", oButtonModel)
' Adds the cancel button.
oButtonModel = oDialogModel.createInstance ( _
"com.sun.star.awt.UnoControlButtonModel")
oButtonModel.setPropertyValue ("PositionX", 125)
2016-12-05 16:44:04 +08:00
oButtonModel.setPropertyValue ("PositionY", 165)
2016-11-29 15:02:15 +08:00
oButtonModel.setPropertyValue ("Height", 15)
oButtonModel.setPropertyValue ("Width", 60)
oButtonModel.setPropertyValue ("PushButtonType", _
com.sun.star.awt.PushButtonType.CANCEL)
oDialogModel.insertByName ("btnCancel", oButtonModel)
' Adds the dialog model to the control and runs it.
oDialog = CreateUnoService ("com.sun.star.awt.UnoControlDialog")
oDialog.setModel (oDialogModel)
oDialog.setVisible (True)
oDialog.getControl ("lstPokemon").setFocus
2016-12-06 16:58:24 +08:00
oListener = CreateUnoListener ("subBtnOKCheck_", _
"com.sun.star.awt.XItemListener")
oDialog.getControl ("lstPokemon").addItemListener (oListener)
oListener = CreateUnoListener ("subBtnOKCheck_", _
"com.sun.star.awt.XTextListener")
oDialog.getControl ("numCP").addTextListener (oListener)
oListener = CreateUnoListener ("subBtnOKCheck_", _
"com.sun.star.awt.XTextListener")
oDialog.getControl ("numHP").addTextListener (oListener)
oListener = CreateUnoListener ("subBtnOKCheck_", _
"com.sun.star.awt.XItemListener")
oDialog.getControl ("lstStarDust").addItemListener (oListener)
2016-12-05 16:44:04 +08:00
oListener = CreateUnoListener ("subRdoTeamRedItemChanged_", _
"com.sun.star.awt.XItemListener")
oDialog.getControl ("rdoTeamRed").addItemListener (oListener)
oListener = CreateUnoListener ("subRdoTeamBlueItemChanged_", _
"com.sun.star.awt.XItemListener")
oDialog.getControl ("rdoTeamBlue").addItemListener (oListener)
oListener = CreateUnoListener ("subRdoTeamYellowItemChanged_", _
"com.sun.star.awt.XItemListener")
oDialog.getControl ("rdoTeamYellow").addItemListener (oListener)
oListener = CreateUnoListener ("subLstBestItemChanged_", _
"com.sun.star.awt.XItemListener")
oDialog.getControl ("lstBest").addItemListener (oListener)
oDialog.getControl ("lstApprasal1").setVisible (False)
oDialog.getControl ("txtBestBefore").setVisible (False)
oDialog.getControl ("lstBest").setVisible (False)
oDialog.getControl ("txtBestAfter").setVisible (False)
oDialog.getControl ("cbxBest2").setVisible (False)
oDialog.getControl ("cbxBest3").setVisible (False)
oDialog.getControl ("lstApprasal2").setVisible (False)
2016-11-29 15:02:15 +08:00
If oDialog.execute = 0 Then
aQuery.bIsCancelled = True
2016-12-05 16:44:04 +08:00
fnAskParam0 = aQuery
2016-11-29 15:02:15 +08:00
Exit Function
End If
With aQuery
.sPokemon = oDialog.getControl ("lstPokemon").getSelectedItem
.nCP = oDialog.getControl ("numCP").getValue
.nHP = oDialog.getControl ("numHP").getValue
.nStarDust = CInt (oDialog.getControl ("lstStarDust").getSelectedItem)
.nPlayerLevel = CInt (oDialog.getControl ("lstPlayerLevel").getSelectedItem)
.nAppraisal1 = oDialog.getControl ("lstApprasal1").getSelectedItemPos + 1
.nAppraisal2 = oDialog.getControl ("lstApprasal2").getSelectedItemPos + 1
.bIsCancelled = False
End With
If oDialog.getControl ("cbxIsNew").getState = 1 Then
aQuery.bIsNew = True
Else
aQuery.bIsNew = False
End If
2016-12-06 07:34:41 +08:00
2016-12-05 16:44:04 +08:00
' The best stats
bIsBestAttack = False
bIsBestDefense = False
bIsBestHP = False
If oDialog.getControl ("lstBest").getSelectedItem = "Attack" Then
bIsBestAttack = True
If oDialog.getControl ("cbxBest2").getState = 1 Then
bIsBestDefense = True
End If
If oDialog.getControl ("cbxBest3").getState = 1 Then
bIsBestHP = True
End If
End If
If oDialog.getControl ("lstBest").getSelectedItem = "Defense" Then
bIsBestDefense = True
If oDialog.getControl ("cbxBest2").getState = 1 Then
bIsBestAttack = True
End If
If oDialog.getControl ("cbxBest3").getState = 1 Then
bIsBestHP = True
End If
End If
If oDialog.getControl ("lstBest").getSelectedItem = "HP" Then
bIsBestHP = True
If oDialog.getControl ("cbxBest2").getState = 1 Then
bIsBestAttack = True
End If
If oDialog.getControl ("cbxBest3").getState = 1 Then
bIsBestDefense = True
End If
End If
2016-11-29 15:02:15 +08:00
aQuery.sBest = ""
2016-12-05 16:44:04 +08:00
If bIsBestAttack Then
2016-11-29 15:02:15 +08:00
aQuery.sBest = aQuery.sBest & "Atk "
End If
2016-12-05 16:44:04 +08:00
If bIsBestDefense Then
2016-11-29 15:02:15 +08:00
aQuery.sBest = aQuery.sBest & "Def "
End If
2016-12-05 16:44:04 +08:00
If bIsBestHP Then
2016-11-29 15:02:15 +08:00
aQuery.sBest = aQuery.sBest & "Sta "
End If
2016-12-06 07:34:41 +08:00
2016-12-05 16:44:04 +08:00
fnAskParam0 = aQuery
2016-11-29 15:02:15 +08:00
End Function
2016-12-06 16:58:24 +08:00
' subBtnOKCheck_disposing: Dummy for the listener.
Sub subBtnOKCheck_disposing (oEvent As object)
End Sub
' subBtnOKCheck_itemStateChanged: When the Pokémon or star dust is selected.
Sub subBtnOKCheck_itemStateChanged (oEvent As object)
Dim oDialog As Object
Dim oPokemon As Object, oCP As Object
Dim oHP As Object, oStarDust As Object, oOK As Object
oDialog = oEvent.Source.getContext
oPokemon = oDialog.getControl ("lstPokemon")
oCP = oDialog.getControl ("numCP")
oHP = oDialog.getControl ("numHP")
oStarDust = oDialog.getControl ("lstStarDust")
oOK = oDialog.getControl ("btnOK")
If oPokemon.getSelectedItemPos <> -1 _
And oCP.getText <> "" _
And oHP.getText <> "" _
And oStarDust.getSelectedItemPos <> -1 Then
oOK.setEnable (True)
Else
oOK.setEnable (False)
End If
End Sub
' subBtnOKCheck_textChanged: When the CP or HP is filled
Sub subBtnOKCheck_textChanged (oEvent As object)
subBtnOKCheck_itemStateChanged (oEvent)
End Sub
2016-12-06 00:33:01 +08:00
' subRdoTeamRedItemChanged_disposing: Dummy for the listener.
2016-12-05 16:44:04 +08:00
Sub subRdoTeamRedItemChanged_disposing (oEvent As object)
End Sub
' subRdoTeamRedItemChanged_itemStateChanged: When the team is selected.
Sub subRdoTeamRedItemChanged_itemStateChanged (oEvent As object)
Dim oDialog As Object, oList As Object, oText As Object
Dim mItems () As String
2016-12-06 16:58:24 +08:00
oDialog = oEvent.Source.getContext
2016-12-05 16:44:04 +08:00
mItems = Array ( _
2016-12-06 00:33:01 +08:00
"Overall, your [Pokémon] simply amazes me. It can accomplish anything!", _
"Overall, your [Pokémon] is a strong Pokémon. You should be proud!", _
"Overall, your [Pokémon] is a decent Pokémon.", _
"Overall, your [Pokémon] may not be great in battle, but I still like it!")
2016-12-05 16:44:04 +08:00
oList = oDialog.getControl ("lstApprasal1")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setVisible (True)
oText = oDialog.getControl ("txtBestBefore")
oText.setPosSize (30, 96, 20, 8, _
com.sun.star.awt.PosSize.X + com.sun.star.awt.PosSize.WIDTH)
oText.setVisible (True)
oText.setText ("Its")
mItems = Array ("Attack", "Defense", "HP")
oList = oDialog.getControl ("lstBest")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setPosSize (50, 96, 35, 8, _
com.sun.star.awt.PosSize.X)
oList.setVisible (True)
oText = oDialog.getControl ("txtBestAfter")
oText.setPosSize (145, 96, 160, 8, _
com.sun.star.awt.PosSize.X + com.sun.star.awt.PosSize.WIDTH)
oText.setVisible (True)
oText.setText ("is its strongest feature.")
oList = oDialog.getControl ("cbxBest2")
oList.setVisible (False)
oList = oDialog.getControl ("cbxBest3")
oList.setVisible (False)
mItems = Array ( _
2016-12-06 00:33:01 +08:00
"I'm blown away by its stats. WOW!", _
"It's got excellent stats! How exciting!", _
"Its stats indicate that in battle, it'll get the job done.", _
"Its stats don't point to greatness in battle.")
2016-12-05 16:44:04 +08:00
oList = oDialog.getControl ("lstApprasal2")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setVisible (True)
End Sub
2016-12-06 00:33:01 +08:00
' subRdoTeamBlueItemChanged_disposing: Dummy for the listener.
2016-12-05 16:44:04 +08:00
Sub subRdoTeamBlueItemChanged_disposing (oEvent As object)
End Sub
' subRdoTeamBlueItemChanged_itemStateChanged: When the blue team is selected.
Sub subRdoTeamBlueItemChanged_itemStateChanged (oEvent As object)
Dim oDialog As Object, oList As Object, oText As Object
Dim mItems () As String
2016-12-06 16:58:24 +08:00
oDialog = oEvent.Source.getContext
2016-12-05 16:44:04 +08:00
mItems = Array ( _
2016-12-06 00:33:01 +08:00
"Overall, your [Pokémon] is a wonder! What a breathtaking Pokémon!", _
"Overall, your [Pokémon] has certainly caught my attention.", _
"Overall, your [Pokémon] is above average.", _
"Overall, your [Pokémon] is not likely to make much headway in battle.")
2016-12-05 16:44:04 +08:00
oList = oDialog.getControl ("lstApprasal1")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setVisible (True)
oText = oDialog.getControl ("txtBestBefore")
oText.setPosSize (30, 96, 200, 8, _
com.sun.star.awt.PosSize.X + com.sun.star.awt.PosSize.WIDTH)
oText.setVisible (True)
oText.setText ("I see that its best attribute is its")
mItems = Array ("Attack", "Defense", "HP")
oList = oDialog.getControl ("lstBest")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setPosSize (230, 96, 35, 8, _
com.sun.star.awt.PosSize.X)
oList.setVisible (True)
oText = oDialog.getControl ("txtBestAfter")
oText.setPosSize (325, 96, 5, 8, _
com.sun.star.awt.PosSize.X + com.sun.star.awt.PosSize.WIDTH)
oText.setVisible (True)
oText.setText (".")
oList = oDialog.getControl ("cbxBest2")
oList.setVisible (False)
oList = oDialog.getControl ("cbxBest3")
oList.setVisible (False)
mItems = Array ( _
2016-12-06 00:33:01 +08:00
"Its stats exceed my calculations. It's incredible!", _
"I am certainly impressed by its stats, I must say.", _
"Its stats are noticeably trending to the positive.", _
"Its stats are not out of the norm, in my opinion.")
2016-12-05 16:44:04 +08:00
oList = oDialog.getControl ("lstApprasal2")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setVisible (True)
End Sub
2016-12-06 00:33:01 +08:00
' subRdoTeamYellowItemChanged_disposing: Dummy for the listener.
2016-12-05 16:44:04 +08:00
Sub subRdoTeamYellowItemChanged_disposing (oEvent As object)
End Sub
' subRdoTeamYellowItemChanged_itemStateChanged: When the yellow team is selected.
Sub subRdoTeamYellowItemChanged_itemStateChanged (oEvent As object)
Dim oDialog As Object, oList As Object, oText As Object
Dim mItems () As String
2016-12-06 16:58:24 +08:00
oDialog = oEvent.Source.getContext
2016-12-05 16:44:04 +08:00
mItems = Array ( _
2016-12-06 00:33:01 +08:00
"Overall, your [Pokémon] looks like it can really battle with the best of them!", _
"Overall, your [Pokémon] is really strong!", _
"Overall, your [Pokémon] is pretty decent!", _
"Overall, your [Pokémon] has room for improvement as far as battling goes.")
2016-12-05 16:44:04 +08:00
oList = oDialog.getControl ("lstApprasal1")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setVisible (True)
oText = oDialog.getControl ("txtBestBefore")
oText.setPosSize (30, 96, 115, 8, _
com.sun.star.awt.PosSize.X + com.sun.star.awt.PosSize.WIDTH)
oText.setVisible (True)
oText.setText ("Its best quality is")
mItems = Array ("Attack", "Defense", "HP")
oList = oDialog.getControl ("lstBest")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setPosSize (145, 96, 35, 8, _
com.sun.star.awt.PosSize.X)
oList.setVisible (True)
oText = oDialog.getControl ("txtBestAfter")
oText.setPosSize (240, 96, 5, 8, _
com.sun.star.awt.PosSize.X + com.sun.star.awt.PosSize.WIDTH)
oText.setVisible (True)
oText.setText (".")
oList = oDialog.getControl ("cbxBest2")
oList.setVisible (False)
oList = oDialog.getControl ("cbxBest3")
oList.setVisible (False)
mItems = Array ( _
2016-12-06 00:33:01 +08:00
"Its stats are the best I've ever seen! No doubt about it!", _
"Its stats are really strong! Impressive.", _
"It's definitely got some good stats. Definitely!", _
"Its stats are all right, but kinda basic, as far as I can see.")
2016-12-05 16:44:04 +08:00
oList = oDialog.getControl ("lstApprasal2")
oList.removeItems (0, oList.getItemCount())
oList.addItems (mItems, 0)
oList.setVisible (True)
End Sub
2016-12-06 00:33:01 +08:00
' subLstBestItemChanged_disposing: Dummy for the listener.
2016-12-05 16:44:04 +08:00
Sub subLstBestItemChanged_disposing (oEvent As object)
End Sub
' subLstBestItemChanged_itemStateChanged: When the best stat is selected.
Sub subLstBestItemChanged_itemStateChanged (oEvent As object)
Dim oDialog As Object, oCheckBox As Object
oDialog = oEvent.Source.getContext
If oDialog.getControl ("rdoTeamRed").getState Then
If oDialog.getControl ("lstBest").getSelectedItem = "Attack" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("I'm just as impressed with its Defense.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("I'm just as impressed with its HP.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
If oDialog.getControl ("lstBest").getSelectedItem = "Defense" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("I'm just as impressed with its Attack.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("I'm just as impressed with its HP.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
If oDialog.getControl ("lstBest").getSelectedItem = "HP" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("I'm just as impressed with its Attack.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("I'm just as impressed with its Defense.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
End If
If oDialog.getControl ("rdoTeamBlue").getState Then
If oDialog.getControl ("lstBest").getSelectedItem = "Attack" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("It is matched equally by its Defense.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("It is matched equally by its HP.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
If oDialog.getControl ("lstBest").getSelectedItem = "Defense" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("It is matched equally by its Attack.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("It is matched equally by its HP.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
If oDialog.getControl ("lstBest").getSelectedItem = "HP" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("It is matched equally by its Attack.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("It is matched equally by its Defense.")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
End If
If oDialog.getControl ("rdoTeamYellow").getState Then
If oDialog.getControl ("lstBest").getSelectedItem = "Attack" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("Its Defense is great, too!")
oCheckBox.setVisible (True)
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("Its HP is great, too!")
oCheckBox.setVisible (True)
End If
If oDialog.getControl ("lstBest").getSelectedItem = "Defense" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("Its Attack is great, too!")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("Its HP is great, too!")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
If oDialog.getControl ("lstBest").getSelectedItem = "HP" Then
oCheckBox = oDialog.getControl ("cbxBest2")
oCheckBox.setLabel ("Its Attack is great, too!")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
oCheckBox = oDialog.getControl ("cbxBest3")
oCheckBox.setLabel ("Its Defense is great, too!")
oCheckBox.setVisible (True)
2016-12-06 00:33:01 +08:00
oCheckBox.setState (0)
2016-12-05 16:44:04 +08:00
End If
End If
End Sub
2016-11-29 14:23:00 +08:00
' fnFindIV: Finds the possible individual values of the Pokémon
2016-11-28 00:18:16 +08:00
Function fnFindIV (aQuery As aFindIVParam) As Variant
Dim aBaseStats As New aStats, maIV () As New aStats
Dim fLevel As Double, nStamina As Integer
Dim nAttack As Integer, nDefense As integer
Dim nI As Integer, nJ As Integer
2016-11-28 23:00:20 +08:00
Dim fStep As Double, nCount As Integer
2016-11-28 00:18:16 +08:00
Dim aEvBaseStats As new aStats, aTempIV As New aStats
2016-12-06 16:18:00 +08:00
Dim maEvolvedForms () As New aEvolveForm
2016-11-28 00:18:16 +08:00
2016-11-29 14:23:00 +08:00
If aQuery.sPokemon = "" Then
2016-11-28 00:18:16 +08:00
fnFindIV = maIV
Exit Function
End If
If aQuery.bIsNew Then
2016-11-28 23:00:20 +08:00
fStep = 1
2016-11-28 00:18:16 +08:00
Else
2016-11-28 23:00:20 +08:00
fStep = 0.5
2016-11-28 00:18:16 +08:00
End If
aBaseStats = fnGetBaseStats (aQuery.sPokemon)
subReadStarDust
nCount = -1
2016-11-28 23:00:20 +08:00
For fLevel = 1 To UBound (mStarDust) Step fStep
If mStarDust (CInt (fLevel - 0.5)) = aQuery.nStarDust Then
2016-11-28 00:18:16 +08:00
For nStamina = 0 To 15
If fnCalcHP (aBaseStats, fLevel, nStamina) = aQuery.nHP Then
For nAttack = 0 To 15
For nDefense = 0 To 15
If fnCalcCP (aBaseStats, fLevel, nAttack, nDefense, nStamina) = aQuery.nCP _
And Not (fnFilterAppraisals (aQuery, nAttack, nDefense, nStamina)) Then
2016-11-28 23:00:20 +08:00
nCount = nCount + 1
2016-11-28 00:18:16 +08:00
ReDim Preserve maIV (nCount) As New aStats
2016-11-28 23:00:20 +08:00
With maIV (nCount)
2016-11-28 00:24:27 +08:00
.sNo = aBaseStats.sNo
2016-11-28 00:18:16 +08:00
.sPokemon = aQuery.sPokemon
.fLevel = fLevel
.nAttack = nAttack
.nDefense = nDefense
.nStamina = nStamina
.nTotal = nAttack + nDefense + nStamina
End With
2016-11-29 14:23:00 +08:00
If aQuery.nPlayerLevel <> 0 Then
2016-12-06 16:18:00 +08:00
maIV (nCount).nMaxCP = fnCalcCP (aBaseStats, aQuery.nPlayerLevel + 1.5, nAttack, nDefense, nStamina)
2016-11-28 00:18:16 +08:00
Else
maIV (nCount).nMaxCP = -1
End If
2016-12-06 16:18:00 +08:00
maIV (nCount).maEvolvedForms = fnGetEvolvedFormArray (UBound (aBaseStats.maEvolvedForms))
For nI = 0 To UBound (aBaseStats.maEvolvedForms)
maIV (nCount).maEvolvedForms (nI).sPokemon = aBaseStats.maEvolvedForms (nI).sPokemon
aEvBaseStats = fnGetBaseStats (aBaseStats.maEvolvedForms (nI).sPokemon)
maIV (nCount).maEvolvedForms (nI).nCP = fnCalcCP (aEvBaseStats, fLevel, nAttack, nDefense, nStamina)
If aQuery.nPlayerLevel <> 0 Then
maIV (nCount).maEvolvedForms (nI).nMaxCP = fnCalcCP (aEvBaseStats, aQuery.nPlayerLevel + 1.5, nAttack, nDefense, nStamina)
Else
maIV (nCount).maEvolvedForms (nI).nMaxCP = -1
End If
Next nI
2016-11-28 00:18:16 +08:00
End If
Next nDefense
Next nAttack
End If
Next nStamina
End If
2016-11-28 23:00:20 +08:00
Next fLevel
2016-11-29 14:23:00 +08:00
' Sorts the IVs
2016-11-28 00:18:16 +08:00
For nI = 0 To UBound (maIV) - 1
For nJ = nI + 1 To UBound (maIV)
2016-11-29 14:23:00 +08:00
If fnCompareIV (maIV (nI), maIV (nJ)) > 0 Then
2016-11-28 00:18:16 +08:00
subCopyIV (maIV (nI), aTempIV)
subCopyIV (maIV (nJ), maIV (nI))
subCopyIV (aTempIV, maIV (nJ))
End If
Next nJ
Next nI
fnFindIV = maIV
End Function
2016-11-29 14:23:00 +08:00
' fnCompareIV: Compare two IVs for sorting
2016-11-28 00:18:16 +08:00
Function fnCompareIV (aIVa As aStats, aIVb As aStats) As Double
2016-12-06 16:18:00 +08:00
Dim nCPa As Integer, nCPb As Integer, nI As Integer
nCPa = aIVa.nMaxCP
For nI = 0 To UBound (aIVa.maEvolvedForms)
If nCPa < aIVa.maEvolvedForms (nI).nMaxCP Then
nCPa = aIVa.maEvolvedForms (nI).nMaxCP
End If
Next nI
nCPb = aIVb.nMaxCP
For nI = 0 To UBound (aIVb.maEvolvedForms)
If nCPb < aIVb.maEvolvedForms (nI).nMaxCP Then
nCPb = aIVb.maEvolvedForms (nI).nMaxCP
End If
Next nI
fnCompareIV = nCPb - nCPa
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
2016-12-06 16:18:00 +08:00
nCPa = 0
For nI = 0 To UBound (aIVa.maEvolvedForms)
If nCPa < aIVa.maEvolvedForms (nI).nCP Then
nCPa = aIVa.maEvolvedForms (nI).nCP
End If
Next nI
nCPb = 0
For nI = 0 To UBound (aIVb.maEvolvedForms)
If nCPb < aIVb.maEvolvedForms (nI).nCP Then
nCPb = aIVb.maEvolvedForms (nI).nCP
End If
Next nI
fnCompareIV = nCPb - nCPa
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
2016-12-06 16:18:00 +08:00
2016-11-28 00:18:16 +08:00
fnCompareIV = aIVb.nTotal - aIVa.nTotal
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
fnCompareIV = aIVb.fLevel - aIVa.fLevel
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
fnCompareIV = aIVb.nStamina - aIVa.nStamina
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
fnCompareIV = aIVb.nAttack - aIVa.nAttack
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
fnCompareIV = aIVb.nDefense - aIVa.nDefense
2016-11-29 14:23:00 +08:00
If fnCompareIV <> 0 Then
2016-11-28 00:18:16 +08:00
Exit Function
End If
End Function
2016-11-29 14:23:00 +08:00
' subCopyIV: Copies one IV to another
2016-11-28 00:18:16 +08:00
Function subCopyIV (aFrom As aStats, aTo As aStats) As Double
2016-12-06 16:18:00 +08:00
Dim nI As Integer, maEvolvedForms () As New aEvolveForm
2016-11-28 00:18:16 +08:00
With aTo
2016-11-28 00:24:27 +08:00
.sNo = aFrom.sNo
2016-11-28 00:18:16 +08:00
.sPokemon = aFrom.sPokemon
.fLevel = aFrom.fLevel
.nAttack = aFrom.nAttack
.nDefense = aFrom.nDefense
.nStamina = aFrom.nStamina
.nTotal = aFrom.nTotal
2016-11-28 00:24:27 +08:00
.nMaxCP = aFrom.nMaxCP
2016-11-28 00:18:16 +08:00
End With
2016-12-06 16:18:00 +08:00
aTo.maEvolvedForms = fnGetEvolvedFormArray (UBound (aFrom.maEvolvedForms))
For nI = 0 To UBound (aFrom.maEvolvedForms)
With aTo.maEvolvedForms (nI)
.sPokemon = aFrom.maEvolvedForms (nI).sPokemon
.nCP = aFrom.maEvolvedForms (nI).nCP
.nMaxCP = aFrom.maEvolvedForms (nI).nMaxCP
End With
Next nI
2016-11-28 00:18:16 +08:00
End Function
2016-11-29 14:23:00 +08:00
' subSaveIV: Saves the found IV
2016-11-28 00:24:27 +08:00
Sub subSaveIV (aQuery As aFindIVParam, maIVs () As aStats)
2016-12-06 16:18:00 +08:00
Dim oDoc As Object, oSheet As Object
Dim oRange As Object, oColumns As Object, oRows As Object
Dim nI As Integer, nJ As Integer, nFrontCols As Integer
Dim mData (Ubound (maIVs) + 1) As Variant, mRow () As Variant
2016-11-28 00:24:27 +08:00
Dim mProps () As New com.sun.star.beans.PropertyValue
oDoc = StarDesktop.loadComponentFromURL ( _
2016-11-29 14:23:00 +08:00
"private:factory/scalc", "_default", 0, mProps)
2016-11-28 00:24:27 +08:00
oSheet = oDoc.getSheets.getByIndex (0)
2016-12-06 16:18:00 +08:00
mRow = Array ( _
"No", "Pokemon", "CP", "HP", "Star dust", _
"Lv", "Atk", "Def", "Sta", "IV")
nFrontCols = UBound (mRow)
If aQuery.sPokemon = "Eevee" Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFrontCols + 6) As Variant
mRow (nFrontCols + 1) = "CP as " & maIVs (0).maEvolvedForms (0).sPokemon
mRow (nFrontCols + 2) = "Powered-up as " & maIVs (0).maEvolvedForms (0).sPokemon
mRow (nFrontCols + 3) = "CP as " & maIVs (0).maEvolvedForms (1).sPokemon
mRow (nFrontCols + 4) = "Powered-up as " & maIVs (0).maEvolvedForms (1).sPokemon
mRow (nFrontCols + 5) = "CP as " & maIVs (0).maEvolvedForms (2).sPokemon
mRow (nFrontCols + 6) = "Powered-up as " & maIVs (0).maEvolvedForms (2).sPokemon
Else
ReDim Preserve mRow (nFrontCols + 3) As Variant
mRow (nFrontCols + 1) = "CP as " & maIVs (0).maEvolvedForms (0).sPokemon
mRow (nFrontCols + 2) = "CP as " & maIVs (0).maEvolvedForms (1).sPokemon
mRow (nFrontCols + 3) = "CP as " & maIVs (0).maEvolvedForms (2).sPokemon
End If
Else
If UBound (maIVs (0).maEvolvedForms) = -1 Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFrontCols + 1) As Variant
mRow (nFrontCols + 1) = "Powered-up"
End If
Else
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFrontCols + UBound (maIVs (0).maEvolvedForms) + 2) As Variant
For nJ = 0 To UBound (maIVs (0).maEvolvedForms)
mRow (nFrontCols + nJ + 1) = "CP as " & maIVs (0).maEvolvedForms (nJ).sPokemon
Next nJ
mRow (UBound (mRow)) = "Powered-up as " & maIVs (0).maEvolvedForms (UBound (maIVs (0).maEvolvedForms)).sPokemon
Else
ReDim Preserve mRow (nFrontCols + UBound (maIVs (0).maEvolvedForms) + 1) As Variant
For nJ = 0 To UBound (maIVs (0).maEvolvedForms)
mRow (nFrontCols + nJ + 1) = "CP as " & maIVs (0).maEvolvedForms (nJ).sPokemon
Next nJ
End If
End If
End If
mData (0) = mRow
For nI = 0 To UBound (maIVs)
mRow = Array ( _
"", "", "", "", "", _
2016-11-28 00:24:27 +08:00
maIVs (nI).fLevel, maIVs (nI).nAttack, maIVs (nI).nDefense, _
2016-12-06 16:18:00 +08:00
maIVs (nI).nStamina, maIVs (nI).nTotal / 45)
If aQuery.sPokemon = "Eevee" Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFrontCols + 6) As Variant
mRow (nFrontCols + 1) = maIVs (nI).maEvolvedForms (0).nCP
mRow (nFrontCols + 2) = maIVs (nI).maEvolvedForms (0).nMaxCP
mRow (nFrontCols + 3) = maIVs (nI).maEvolvedForms (1).nCP
mRow (nFrontCols + 4) = maIVs (nI).maEvolvedForms (1).nMaxCP
mRow (nFrontCols + 5) = maIVs (nI).maEvolvedForms (2).nCP
mRow (nFrontCols + 6) = maIVs (nI).maEvolvedForms (2).nMaxCP
Else
ReDim Preserve mRow (nFrontCols + 3) As Variant
mRow (nFrontCols + 1) = maIVs (nI).maEvolvedForms (0).nCP
mRow (nFrontCols + 2) = maIVs (nI).maEvolvedForms (1).nCP
mRow (nFrontCols + 3) = maIVs (nI).maEvolvedForms (2).nCP
End If
Else
If UBound (maIVs (nI).maEvolvedForms) = -1 Then
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFrontCols + 1) As Variant
mRow (nFrontCols + 1) = maIVs (nI).nMaxCP
End If
Else
If aQuery.nPlayerLevel <> 0 Then
ReDim Preserve mRow (nFrontCols + UBound (maIVs (nI).maEvolvedForms) + 2) As Variant
For nJ = 0 To UBound (maIVs (nI).maEvolvedForms)
mRow (nFrontCols + nJ + 1) = maIVs (nI).maEvolvedForms (nJ).nCP
Next nJ
mRow (UBound (mRow)) = maIVs (nI).maEvolvedForms (UBound (maIVs (nI).maEvolvedForms)).nMaxCP
Else
ReDim Preserve mRow (nFrontCols + UBound (maIVs (nI).maEvolvedForms) + 1) As Variant
For nJ = 0 To UBound (maIVs (nI).maEvolvedForms)
mRow (nFrontCols + nJ + 1) = maIVs (nI).maEvolvedForms (nJ).nCP
Next nJ
End If
End If
End If
mData (nI + 1) = mRow
2016-11-28 00:24:27 +08:00
Next nI
2016-12-06 16:18:00 +08:00
' Fills the query information at the first row
mData (1) (0) = maIVs (0).sNo
mData (1) (1) = aQuery.sPokemon
mData (1) (2) = aQuery.nCP
mData (1) (3) = aQuery.nHP
mData (1) (4) = aQuery.nStarDust
2016-11-28 00:24:27 +08:00
oRange = oSheet.getCellRangeByPosition ( _
0, 0, UBound (mData (0)), UBound (mData))
oRange.setDataArray (mData)
2016-11-29 14:23:00 +08:00
oRange.setPropertyValue ("VertJustify", _
2016-11-28 00:24:27 +08:00
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 ( _
2016-12-06 16:18:00 +08:00
4, 1, 4, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, 1, 9, UBound (mData))
2016-11-29 14:23:00 +08:00
oRange.setPropertyValue ("NumberFormat", 10)
2016-11-28 00:24:27 +08:00
2016-12-06 16:18:00 +08:00
If aQuery.sPokemon = "Eevee" Then
oRange = oSheet.getCellRangeByPosition ( _
10, 0, 15, 0)
Else
If UBound (maIVs (0).maEvolvedForms) = -1 Then
oRange = oSheet.getCellRangeByPosition ( _
10, 0, 10, 0)
Else
oRange = oSheet.getCellRangeByPosition ( _
10, 0, 10 + UBound (maIVs (0).maEvolvedForms) + 2, 0)
End If
End If
oRange.setPropertyValue ("IsTextWrapped", True)
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue ("Height", 840)
2016-11-28 00:24:27 +08:00
oColumns = oSheet.getColumns
2016-12-06 16:18:00 +08:00
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.sPokemon = "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 UBound (maIVs (0).maEvolvedForms) = -1 Then
If aQuery.nPlayerLevel <> 0 Then
oColumns.getByIndex (10).setPropertyValue ("Width", 2200)
End If
Else
For nI = 0 To UBound (maIVs (0).maEvolvedForms)
oColumns.getByIndex (10 + nI).setPropertyValue ("Width", 2310)
Next nI
If aQuery.nPlayerLevel <> 0 Then
oColumns.getByIndex (10 + UBound (maIVs (0).maEvolvedForms) + 1).setPropertyValue ("Width", 2810)
End If
End If
End If
2016-11-28 00:24:27 +08:00
End Sub
2016-11-29 14:23:00 +08:00
' fnFilterAppraisals: Filters the IV by the appraisals.
2016-11-28 00:18:16 +08:00
Function fnFilterAppraisals (aQuery As aFindIVParam, nAttack As Integer, nDefense As Integer, nStamina As Integer) As Boolean
Dim nTotal As Integer, nMax As Integer, sBest As String
2016-11-29 14:23:00 +08:00
' The first appraisal.
2016-11-28 00:18:16 +08:00
nTotal = nAttack + nDefense + nStamina
2016-11-29 14:23:00 +08:00
If aQuery.nAppraisal1 = 1 And Not (nTotal >= 37) Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
2016-11-29 14:23:00 +08:00
If aQuery.nAppraisal1 = 2 And Not (nTotal >= 30 And nTotal <= 36) Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
2016-11-29 14:23:00 +08:00
If aQuery.nAppraisal1 = 3 And Not (nTotal >= 23 And nTotal <= 29) Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
2016-11-29 14:23:00 +08:00
If aQuery.nAppraisal1 = 4 And Not (nTotal <= 22) Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
2016-11-29 14:23:00 +08:00
' The best stats.
2016-11-28 00:18:16 +08:00
nMax = nAttack
2016-11-29 14:23:00 +08:00
If nDefense > nMax Then
2016-11-28 00:18:16 +08:00
nMax = nDefense
End If
2016-11-29 14:23:00 +08:00
If nStamina > nMax Then
2016-11-28 00:18:16 +08:00
nMax = nStamina
End If
2016-11-29 14:23:00 +08:00
If aQuery.sBest <> "" Then
sBest = ""
2016-11-28 00:18:16 +08:00
If nAttack = nMax Then
2016-11-29 14:23:00 +08:00
sBest = sBest & "Atk "
2016-11-28 00:18:16 +08:00
End If
If nDefense = nMax Then
2016-11-29 14:23:00 +08:00
sBest = sBest & "Def "
2016-11-28 00:18:16 +08:00
End If
If nStamina = nMax Then
2016-11-29 14:23:00 +08:00
sBest = sBest & "Sta "
2016-11-28 00:18:16 +08:00
End If
2016-11-29 14:23:00 +08:00
If aQuery.sBest <> sBest Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
End If
2016-11-29 14:23:00 +08:00
' The second appraisal.
2016-11-28 00:18:16 +08:00
If aQuery.nAppraisal2 = 1 And Not (nMax = 15) Then
fnFilterAppraisals = True
Exit Function
End If
If aQuery.nAppraisal2 = 2 And Not (nMax = 13 Or nMax = 14) Then
fnFilterAppraisals = True
Exit Function
End If
2016-11-29 14:23:00 +08:00
If aQuery.nAppraisal2 = 3 And Not (nMax >= 8 And nMax <= 12) Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
2016-11-29 14:23:00 +08:00
If aQuery.nAppraisal2 = 4 And Not (nMax <= 7) Then
2016-11-28 00:18:16 +08:00
fnFilterAppraisals = True
Exit Function
End If
fnFilterAppraisals = False
End Function
2016-11-29 14:23:00 +08:00
' fnCalcCP: Calculates the combat power of the Pokémon
2016-11-28 00:18:16 +08:00
Function fnCalcCP (aBaseStats As aStats, fLevel As Double, nAttack As Integer, nDefense As Integer, nStamina As Integer) As Integer
fnCalcCP = fnFloor ((aBaseStats.nAttack + nAttack) _
* ((aBaseStats.nDefense + nDefense) ^ 0.5) _
* ((aBaseStats.nStamina + nStamina) ^ 0.5) _
* (fnGetCPM (fLevel) ^ 2) / 10)
End Function
2016-11-29 14:23:00 +08:00
' fnCalcHP: Calculates the hit points of the Pokémon
2016-11-28 00:18:16 +08:00
Function fnCalcHP (aBaseStats As aStats, fLevel As Double, nStamina As Integer) As Integer
fnCalcHP = fnFloor ((aBaseStats.nStamina + nStamina) _
* fnGetCPM (fLevel))
End Function
2016-11-29 14:23:00 +08:00
' fnGetBaseStats: Returns the base stats of the Pokémon.
2016-11-28 00:18:16 +08:00
Function fnGetBaseStats (sPokemon As String) As aStats
Dim nI As Integer
subReadBaseStats
For nI = 0 To UBound (maBaseStats)
If maBaseStats (nI).sPokemon = sPokemon Then
fnGetBaseStats = maBaseStats (nI)
Exit Function
End If
Next nI
2016-11-28 23:00:20 +08:00
End Function
2016-11-28 00:18:16 +08:00
2016-11-29 14:23:00 +08:00
' fnGetCPM: Returns the combat power multiplier.
2016-11-28 00:18:16 +08:00
Function fnGetCPM (fLevel As Double) As Double
Dim nI As Integer
subReadCPM
2016-11-28 23:00:20 +08:00
If CInt (fLevel) = fLevel Then
fnGetCPM = mCPM (fLevel)
Else
fnGetCPM = ((mCpm (fLevel - 0.5) ^ 2 _
+ mCpm (fLevel + 0.5) ^ 2) / 2) ^ 0.5
End If
End Function
2016-11-28 00:18:16 +08:00
2016-11-29 14:23:00 +08:00
' fnFloor: Returns the floor of the number
2016-11-28 00:18:16 +08:00
Function fnFloor (fNumber As Double) As Integer
fnFloor = CInt (fNumber - 0.5)
End Function
2016-11-29 14:23:00 +08:00
' subReadBaseStats: Reads the base stats table.
2016-11-28 00:18:16 +08:00
Sub subReadBaseStats
2016-12-06 16:18:00 +08:00
Dim mData As Variant, nI As Integer, nJ As Integer
2016-11-28 00:18:16 +08:00
If UBound (maBaseStats) = -1 Then
2016-11-28 23:00:20 +08:00
mData = fnGetBaseStatsData
ReDim Preserve maBaseStats (UBound (mData)) As New aStats
For nI = 0 To UBound (mData)
With maBaseStats (nI)
.sNo = mData (nI) (1)
.sPokemon = mData (nI) (0)
.nStamina = mData (nI) (2)
.nAttack = mData (nI) (3)
.nDefense = mData (nI) (4)
2016-11-28 00:18:16 +08:00
End With
2016-12-06 16:18:00 +08:00
maBaseStats (nI).maEvolvedForms = fnGetEvolvedFormArray (UBound (mData (nI) (5)))
For nJ = 0 To UBound (maBaseStats (nI).maEvolvedForms)
With maBaseStats (nI).maEvolvedForms (nJ)
.sPokemon = mData (nI) (5) (nJ)
.nCP = -1
.nMaxCP = -1
End With
Next nJ
2016-11-28 23:00:20 +08:00
Next nI
2016-11-28 00:18:16 +08:00
End If
2016-11-28 23:00:20 +08:00
End Sub
2016-11-28 00:18:16 +08:00
2016-12-06 16:18:00 +08:00
' fnGetEvolvedFormArray: Obtains a blank aEvolveForm array
Function fnGetEvolvedFormArray (nUBound As Integer) As Variant
If nUBound = -1 Then
fnGetEvolvedFormArray = fnGetEmptyEvolvedFormArray
Else
fnGetEvolvedFormArray = fnGetNumberedEvolvedFormArray (nUBound)
End If
End Function
' fnGetNumberedEvolvedFormArray: Obtains a numbered aEvolveForm array
Function fnGetNumberedEvolvedFormArray (nUBound As Integer) As Variant
Dim mData (nUBound) As New aEvolveForm
fnGetNumberedEvolvedFormArray = mData
End Function
' fnGetEmptyEvolvedFormArray: Obtains an empty aEvolveForm array
Function fnGetEmptyEvolvedFormArray () As Variant
Dim mData () As New aEvolveForm
fnGetEmptyEvolvedFormArray = mData
End Function
2016-11-29 14:23:00 +08:00
' subReadCPM: Reads the CPM table.
2016-11-28 00:18:16 +08:00
Sub subReadCPM
2016-11-28 23:00:20 +08:00
If UBound (mCPM) = -1 Then
mCPM = fnGetCPMData
2016-11-28 00:18:16 +08:00
End If
2016-11-28 23:00:20 +08:00
End Sub
2016-11-28 00:18:16 +08:00
2016-11-29 14:23:00 +08:00
' subReadStarDust: Reads the star dust table.
2016-11-28 00:18:16 +08:00
Sub subReadStarDust
2016-11-28 23:00:20 +08:00
If UBound (mStarDust) = -1 Then
mStarDust = fnGetStarDustData
2016-11-28 00:18:16 +08:00
End If
2016-11-28 23:00:20 +08:00
End Sub
2016-11-29 14:23:00 +08:00
</script:module>