<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="9Load" script:language="StarBasic">&apos; Copyright (c) 2016-2017 imacat.
&apos; 
&apos; Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
&apos; you may not use this file except in compliance with the License.
&apos; You may obtain a copy of the License at
&apos; 
&apos;     http://www.apache.org/licenses/LICENSE-2.0
&apos; 
&apos; Unless required by applicable law or agreed to in writing, software
&apos; distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
&apos; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
&apos; See the License for the specific language governing permissions and
&apos; limitations under the License.

&apos; 9Load: The Pokémon GO data sheets loader
&apos;   by imacat &lt;imacat@mail.imacat.idv.tw&gt;, 2016-11-28

Option Explicit

&apos; subReadDataSheets: Reads the data sheets and shows the data as
&apos;                    OpenOffice Basic arrays
Sub subReadDataSheets
	Dim sOutput as String, mData As Variant
	
	sOutput = &quot;&quot; _
		&amp; &quot;&apos; Copyright (c) 2016-&quot; &amp; Year (Now) &amp; &quot; imacat.&quot; &amp; Chr (10) _
		&amp; &quot;&apos; &quot; &amp; Chr (10) _
		&amp; &quot;&apos; Licensed under the Apache License, Version 2.0 (the &quot;&quot;License&quot;&quot;);&quot; &amp; Chr (10) _
		&amp; &quot;&apos; you may not use this file except in compliance with the License.&quot; &amp; Chr (10) _
		&amp; &quot;&apos; You may obtain a copy of the License at&quot; &amp; Chr (10) _
		&amp; &quot;&apos; &quot; &amp; Chr (10) _
		&amp; &quot;&apos;     http://www.apache.org/licenses/LICENSE-2.0&quot; &amp; Chr (10) _
		&amp; &quot;&apos; &quot; &amp; Chr (10) _
		&amp; &quot;&apos; Unless required by applicable law or agreed to in writing, software&quot; &amp; Chr (10) _
		&amp; &quot;&apos; distributed under the License is distributed on an &quot;&quot;AS IS&quot;&quot; BASIS,&quot; &amp; Chr (10) _
		&amp; &quot;&apos; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&quot; &amp; Chr (10) _
		&amp; &quot;&apos; See the License for the specific language governing permissions and&quot; &amp; Chr (10) _
		&amp; &quot;&apos; limitations under the License.&quot; &amp; Chr (10) _
		&amp; Chr (10) _
		&amp; &quot;&apos; 3Data: The Pokémon GO data for IV calculation&quot; &amp; Chr (10) _
		&amp; &quot;&apos;   by imacat &lt;imacat@mail.imacat.idv.tw&gt;, &quot; &amp; Format (Date (), &quot;yyyy-mm-dd&quot;) &amp; Chr (10) _
		&amp; &quot;&apos;   Generated with 9Load.subReadDataSheets ()&quot; &amp; Chr (10) _
		&amp; Chr (10) _
		&amp; &quot;Option Explicit&quot;
	sOutput = sOutput &amp; Chr (10) &amp; Chr (10) &amp; fnReadBaseStatsSheet
	sOutput = sOutput &amp; Chr (10) &amp; Chr (10) &amp; fnReadCPMSheet
	sOutput = sOutput &amp; Chr (10) &amp; Chr (10) &amp; fnReadStardustSheet
	subShowText (sOutput)
End Sub

&apos; subShowChinesePokemonNames: Shows the Chinese names of Pokémons as
&apos;                             resource properties.
Sub subShowChinesePokemonNames
	Dim oSheet As Object, oRange As Object
	Dim mData As Variant, nI As Integer
	Dim sNo As String, sName As String, sNewName As String
	Dim nJ As Integer, sChar As String, nCharCode As Long
	Dim sResult As String

	oSheet = ThisComponent.getSheets.getByName (&quot;basestat&quot;)
	oRange = oSheet.getCellRangeByName (&quot;BaseStats&quot;)
	mData = oRange.getDataArray
	sResult = &quot;&quot;
	For nI = 1 To UBound (mData)
		sNo = mData (nI) (1)
		sName = mData (nI) (2)
		If sName = &quot;&quot; Then
			sName = mData (nI) (0)
		Else
			sNewName = &quot;&quot;
			For nJ = 1 To Len (sName)
				sChar = Mid (sName, nJ, 1)
				nCharCode = Asc (sChar)
				If nCharCode &gt; 255 Then
					sNewName = sNewName &amp; &quot;\u&quot; &amp; LCase (Hex (nCharCode))
				Else
					sNewName = sNewName &amp; sChar
				End If
			Next nJ
			sName = sNewName
		End If
		sResult = sResult &amp; &quot;1&quot; &amp; sNo &amp; &quot;.lstPokemon.StringItemList=&quot; _
			&amp; sName &amp; Chr (10)
	Next nI
	subShowText (sResult)
End Sub

&apos; subShowText: Shows the text in a text box for copy and paste.
Sub subShowText (sContent As String)
	Dim oDialog As Object, oDialogModel As Object
	Dim oEditModel As Object, oButtonModel As Object
	
	&apos; Creates a dialog
	oDialogModel = CreateUnoService ( _
		&quot;com.sun.star.awt.UnoControlDialogModel&quot;)
	oDialogModel.setPropertyValue (&quot;PositionX&quot;, 100)
	oDialogModel.setPropertyValue (&quot;PositionY&quot;, 100)
	oDialogModel.setPropertyValue (&quot;Height&quot;, 130)
	oDialogModel.setPropertyValue (&quot;Width&quot;, 200)
	oDialogModel.setPropertyValue (&quot;Title&quot;, &quot;Pokémon GO Data&quot;)
	
	&apos; Adds the content area
	oEditModel = oDialogModel.createInstance ( _
		&quot;com.sun.star.awt.UnoControlEditModel&quot;)
	oEditModel.setPropertyValue (&quot;PositionX&quot;, 5)
	oEditModel.setPropertyValue (&quot;PositionY&quot;, 5)
	oEditModel.setPropertyValue (&quot;Height&quot;, 100)
	oEditModel.setPropertyValue (&quot;Width&quot;, 190)
	oEditModel.setPropertyValue (&quot;MultiLine&quot;, True)
	oEditModel.setPropertyValue (&quot;Text&quot;, sContent)
	oEditModel.setPropertyValue (&quot;ReadOnly&quot;, True)
	oDialogModel.insertByName (&quot;edtContent&quot;, oEditModel)
	
	&apos; Adds the OK button.
	oButtonModel = oDialogModel.createInstance ( _
		&quot;com.sun.star.awt.UnoControlButtonModel&quot;)
	oButtonModel.setPropertyValue (&quot;PositionX&quot;, 70)
	oButtonModel.setPropertyValue (&quot;PositionY&quot;, 110)
	oButtonModel.setPropertyValue (&quot;Height&quot;, 15)
	oButtonModel.setPropertyValue (&quot;Width&quot;, 60)
	oButtonModel.setPropertyValue (&quot;PushButtonType&quot;, _
		com.sun.star.awt.PushButtonType.OK)
	oButtonModel.setPropertyValue (&quot;DefaultButton&quot;, True)
	oDialogModel.insertByName (&quot;btnOK&quot;, oButtonModel)
	
	&apos; Adds the dialog model to the control and runs it.
	oDialog = CreateUnoService (&quot;com.sun.star.awt.UnoControlDialog&quot;)
	oDialog.setModel (oDialogModel)
	oDialog.setVisible (True)
	oDialog.execute
End Sub

&apos; fnReadBaseStatsSheet: Reads the base stats sheet.
Function fnReadBaseStatsSheet As String
	Dim oSheet As Object, oRange As Object, mData As Variant
	Dim nI As Integer, sOutput As String
	Dim nJ As Integer, nStart As Integer, nEnd As Integer
	Dim sEvolveForms As String
	
	oSheet = ThisComponent.getSheets.getByName (&quot;basestat&quot;)
	oRange = oSheet.getCellRangeByName (&quot;BaseStats&quot;)
	mData = oRange.getDataArray
	
	sOutput = &quot;&quot; _
		&amp; &quot;&apos; fnGetBaseStatsData: Returns the base stats data.&quot; &amp; Chr (10) _
		&amp; &quot;Function fnGetBaseStatsData As Variant&quot; &amp; Chr (10) _
		&amp; Chr (9) &amp; &quot;fnGetBaseStatsData = Array( _&quot; &amp; Chr (10)
	For nI = 1 To UBound (mData) - 1
		sEvolveForms = fnFindEvolveForms (mData (nI))
		sOutput = sOutput _
			&amp; Chr (9) &amp; Chr (9) &amp; &quot;Array (&quot;&quot;&quot; _
				&amp; fnMapPokemonNameToId (mData (nI) (0)) _
				&amp; &quot;&quot;&quot;, &quot;&quot;&quot; &amp; mData (nI) (1) _
				&amp; &quot;&quot;&quot;, &quot; &amp; mData (nI) (3) _
				&amp; &quot;, &quot; &amp; mData (nI) (4) _
				&amp; &quot;, &quot; &amp; mData (nI) (5) _
				&amp; &quot;, &quot; &amp; sEvolveForms &amp; &quot;), _&quot; &amp; Chr (10)
	Next nI
	nI = UBound (mData)
	sEvolveForms = fnFindEvolveForms (mData (nI))
	sOutput = sOutput _
		&amp; Chr (9) &amp; Chr (9) &amp; &quot;Array (&quot;&quot;&quot; _
			&amp; fnMapPokemonNameToId (mData (nI) (0)) _
			&amp; &quot;&quot;&quot;, &quot;&quot;&quot; &amp; mData (nI) (1) _
			&amp; &quot;&quot;&quot;, &quot; &amp; mData (nI) (3) _
			&amp; &quot;, &quot; &amp; mData (nI) (4) _
			&amp; &quot;, &quot; &amp; mData (nI) (5) _
			&amp; &quot;, &quot; &amp; sEvolveForms &amp; &quot;))&quot; &amp; Chr (10) _
		&amp; &quot;End Function&quot;
	fnReadBaseStatsSheet = sOutput
End Function

&apos; fnFindEvolveForms: Finds the evolved forms of the Pokémons.
Function fnFindEvolveForms (mData () As Variant) As String
	Dim nJ As Integer, nStart As Integer, nEnd As Integer
	Dim sEvolveForms As String
	
	&apos; Special cases
	If mData (0) = &quot;Oddish&quot; Then
		fnFindEvolveForms = &quot;Array (&quot;&quot;Gloom&quot;&quot;, &quot;&quot;Vileplume&quot;&quot;, &quot;&quot;Bellossom&quot;&quot;)&quot;
		Exit Function
	End If
	If mData (0) = &quot;Gloom&quot; Then
		fnFindEvolveForms = &quot;Array (&quot;&quot;Vileplume&quot;&quot;, &quot;&quot;Bellossom&quot;&quot;)&quot;
		Exit Function
	End If
	If mData (0) = &quot;Slowpoke&quot; Then
		fnFindEvolveForms = &quot;Array (&quot;&quot;Slowbro&quot;&quot;, &quot;&quot;Slowking&quot;&quot;)&quot;
		Exit Function
	End If
	If mData (0) = &quot;Tyrogue&quot; Then
		fnFindEvolveForms = &quot;Array (&quot;&quot;Hitmonlee&quot;&quot;, &quot;&quot;Hitmonchan&quot;&quot;, &quot;&quot;Hitmontop&quot;&quot;)&quot;
		Exit Function
	End If
	If mData (0) = &quot;Eevee&quot; Then
		fnFindEvolveForms = &quot;Array (&quot;&quot;Vaporeon&quot;&quot;, &quot;&quot;Jolteon&quot;&quot;, &quot;&quot;Flareon&quot;&quot;, &quot;&quot;Espeon&quot;&quot;, &quot;&quot;Umbreon&quot;&quot;)&quot;
		Exit Function
	End If
	
	For nJ = 6 To 8
		If mData (nJ) = mData (0) Then
			nStart = nJ + 1
			nJ = 9
		End If
	Next nJ
	If nStart = 9 Then
		nEnd = 8
	Else
		For nJ = nStart To 8
			If mData (nJ) = &quot;&quot; Then
				nEnd = nJ - 1
				nJ = 9
			Else
				If nJ = 8 Then
					nEnd = 8
					nJ = 9
				End If
			End If
		Next nJ
	End If
	If nEnd = nStart - 1 Then
		sEvolveForms = &quot;Array ()&quot;
	Else
		sEvolveForms = &quot;&quot;&quot;&quot; _
			&amp; fnMapPokemonNameToId (mData (nStart)) &amp; &quot;&quot;&quot;&quot;
		For nJ = nStart + 1 To nEnd
			sEvolveForms = sEvolveForms _
				&amp; &quot;, &quot;&quot;&quot; _
				&amp; fnMapPokemonNameToId (mData (nJ)) &amp; &quot;&quot;&quot;&quot;
		Next nJ
		sEvolveForms = &quot;Array (&quot; &amp; sEvolveForms &amp; &quot;)&quot;
	End If
	fnFindEvolveForms = sEvolveForms
End Function

&apos; fnMapPokemonNameToId: Maps the English Pokémon names to their IDs.
Function fnMapPokemonNameToId (sName As String) As String
	Dim sId As String
	
	sId = &quot;&quot;
	If sName = &quot;Farfetch&apos;d&quot; Then
		sId = &quot;Farfetchd&quot;
	End If
	If sName = &quot;Nidoran♀&quot; Then
		sId = &quot;NidoranFemale&quot;
	End If
	If sName = &quot;Nidoran♂&quot; Then
		sId = &quot;NidoranMale&quot;
	End If
	If sName = &quot;Mr. Mime&quot; Then
		sId = &quot;MrMime&quot;
	End If
	If sName = &quot;Ho-Oh&quot; Then
		sId = &quot;HoOh&quot;
	End If
	If sId = &quot;&quot; Then
		sId = sName
	End If
	fnMapPokemonNameToId = sId
End Function

&apos; fnReadCPMSheet: Reads the combat power multiplier sheet.
Function fnReadCPMSheet As String
	Dim oSheet As Object, oRange As Object, mData As Variant
	Dim nI As Integer, sOutput As String
	
	oSheet = ThisComponent.getSheets.getByName (&quot;cpm&quot;)
	oRange = oSheet.getCellRangeByName (&quot;CPM&quot;)
	mData = oRange.getDataArray
	
	sOutput = &quot;&quot; _
		&amp; &quot;&apos; fnGetCPMData: Returns the combat power multiplier data.&quot; &amp; Chr (10) _
		&amp; &quot;Function fnGetCPMData As Variant&quot; &amp; Chr (10) _
		&amp; Chr (9) &amp; &quot;fnGetCPMData = Array( _&quot; &amp; Chr (10) _
		&amp; Chr (9) &amp; Chr (9) &amp; &quot;-1, _&quot; &amp; Chr (10)
	For nI = 1 To UBound (mData) - 2 Step 2
		sOutput = sOutput _
			&amp; Chr (9) &amp; Chr (9) &amp; mData (nI) (1) &amp; &quot;, _&quot; &amp; Chr (10)
	Next nI
	nI = UBound (mData) - 2
	sOutput = sOutput _
		&amp; Chr (9) &amp; Chr (9) &amp; mData (nI) (1) &amp; &quot;)&quot; &amp; Chr (10) _
		&amp; &quot;End Function&quot;
	fnReadCPMSheet = sOutput
End Function

&apos; fnReadStardustSheet: Reads the stardust sheet.
Function fnReadStardustSheet As String
	Dim oSheet As Object, oRange As Object, mData As Variant
	Dim nI As Integer, sOutput As String
	
	oSheet = ThisComponent.getSheets.getByName (&quot;lvup&quot;)
	oRange = oSheet.getCellRangeByName (&quot;A2:D81&quot;)
	mData = oRange.getDataArray
	
	sOutput = &quot;&quot; _
		&amp; &quot;&apos; fnGetStardustData: Returns the stardust data.&quot; &amp; Chr (10) _
		&amp; &quot;Function fnGetStardustData As Variant&quot; &amp; Chr (10) _
		&amp; Chr (9) &amp; &quot;fnGetStardustData = Array( _&quot; &amp; Chr (10) _
		&amp; Chr (9) &amp; Chr (9) &amp; &quot;-1, _&quot; &amp; Chr (10)
	For nI = 1 To UBound (mData) - 1 Step 2
		sOutput = sOutput _
			&amp; Chr (9) &amp; Chr (9) &amp; mData (nI) (2) &amp; &quot;, _&quot; &amp; Chr (10)
	Next nI
	nI = UBound (mData)
	sOutput = sOutput _
		&amp; Chr (9) &amp; Chr (9) &amp; mData (nI) (2) &amp; &quot;)&quot; &amp; Chr (10) _
		&amp; &quot;End Function&quot;
	fnReadStardustSheet = sOutput
End Function
</script:module>