├── .gitignore ├── .idea ├── compiler.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libclicker ├── .gitignore ├── build.gradle └── src │ ├── main │ └── java │ │ └── eu │ │ └── manabreak │ │ └── libclicker │ │ ├── Automator.java │ │ ├── Currency.java │ │ ├── Item.java │ │ ├── PurchaseResult.java │ │ ├── World.java │ │ ├── formatting │ │ ├── CurrencyFormatter.java │ │ ├── Formatter.java │ │ └── ItemPriceFormatter.java │ │ ├── generators │ │ ├── Generator.java │ │ └── Resource.java │ │ ├── modifiers │ │ ├── GeneratorModifier.java │ │ ├── Modifiable.java │ │ ├── Modifier.java │ │ └── WorldModifier.java │ │ └── utils │ │ └── RandomUtils.java │ └── test │ └── java │ └── eu │ └── manabreak │ └── libclicker │ ├── AutomatorTest.java │ ├── CurrencyFormatterTest.java │ ├── CurrencyTest.java │ ├── GeneratorTest.java │ ├── ItemTest.java │ ├── ModifierTest.java │ ├── NumberFormatterTest.java │ └── SerializationTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 26 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 1.8 58 | 59 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 manabreak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libclicker 2 | Libclicker is a library for creating idle / incremental / clicker games. 3 | It features resources, resource generators, automators for generators and 4 | modifiers, as well as utilities e.g. for presentation. 5 | 6 | ## Install 7 | 8 | Using Gradle, add the following line to your repositories: 9 | ``` 10 | allprojects { 11 | repositories { 12 | ... 13 | maven { url 'https://jitpack.io' } 14 | } 15 | } 16 | ``` 17 | 18 | Also add the following line to your dependencies: 19 | 20 | ``` 21 | compile 'com.github.manabreak:libclicker2:0.1' 22 | ``` 23 | 24 | That's it! 25 | 26 | ## Usage 27 | 28 | Here's a basic introduction on how to use libclicker. 29 | 30 | ### World 31 | 32 | First off, you will need a `World` container for all your objects. 33 | A `World` object will keep track of the generators, automators and other 34 | items. 35 | 36 | ```java 37 | World world = new World(); 38 | ``` 39 | 40 | To update the world as your game progresses, call the `update()` method 41 | with your frame time as the parameter: 42 | 43 | ```java 44 | // Advance the world by 1/60th of a seconds, or 60 times per second 45 | world.update(1.0 / 60.0); 46 | ``` 47 | ### Currencies 48 | 49 | Quite often, procedural games have some sort of resources (gold, cookies etc.). 50 | To declare a new currency, you can use a `Currency.Builder`: 51 | 52 | ```java 53 | // Creates a new currency called "Gold" 54 | Currency gold = new Currency.Builder(world) 55 | .name("Gold") 56 | .build(); 57 | ``` 58 | 59 | The whole system will only have one instance of a currency at a time. The 60 | currency object will keep track of how much of the said currency has been 61 | generated. 62 | 63 | ### Generators 64 | 65 | To produce a currency, you have to create a generator. Again, like currencies, 66 | this happens through a Builder class: 67 | 68 | ```java 69 | // Creates a generator that creates gold 70 | Generator goldMine = new Generator.Builder(world) 71 | .generate(gold) // Generate gold 72 | .baseAmount(10) // Defaults to 10 gold per tick 73 | .multiplier(1.15) // Increase amount by 15 % per level 74 | .price(100) // Price of level 1 gold mine 75 | .priceMultiplier(1.25) // Increase price by 25 % per level 76 | .build(); 77 | 78 | // Manually generate some gold 79 | goldMine.process(); 80 | ``` 81 | 82 | Do note that generators start at level 0, producing nothing. To activate the 83 | generator, "upgrade" it to level one to produce the base amount: 84 | 85 | ```java 86 | // Upgrade the gold mine to level 1 87 | goldMine.upgrade(); 88 | ``` 89 | 90 | ### Automators 91 | 92 | Commonly generators can be automated in clicker games. To automate the gold mine 93 | from the previous example: 94 | 95 | ```java 96 | // Create a "gold digger" to automatically dig gold 97 | Automator goldDigger = new Automator.Builder(world) 98 | .automate(goldMine) 99 | .every(3.0) // Tick every three seconds 100 | .build(); 101 | 102 | // Advance the world by 30 seconds to make the automator work 103 | world.update(30.0); 104 | ``` 105 | 106 | ### Modifiers 107 | 108 | Yet another common thing found in procedural games is the use of upgrades, bonuses 109 | or other modifiers that change the outcome of the system in some way. Modifiers 110 | are supported in libclicker and can be applied to any other elements, modifying 111 | just about any of their properties (at least in the near future). 112 | 113 | The usage of modifiers follows the same pattern: 114 | 115 | ```java 116 | // World to modify 117 | World w = new World(); 118 | 119 | // Modify the world by creating a "double speed bonus" modifiers 120 | Modifier m = new Modifier.Builder() 121 | .modify(w) 122 | .speedBy(2.0) 123 | .build(); 124 | 125 | // By enabling the modifier, the speed bonus turns on 126 | m.enable(); 127 | 128 | // World is now actually advanced by 20 seconds instead of 10 129 | w.update(10.0); 130 | 131 | // Let's disable the modifier ("back to normal") 132 | m.disable(); 133 | 134 | // Back to normal 10-second updates 135 | w.update(10.0); 136 | ``` 137 | 138 | Note that multiple modifiers can be stacked: 139 | 140 | ```java 141 | // Double speed bonus 142 | Modifier m1 = new Modifier.Builder() 143 | .modify(w) 144 | .speedBy(2.0) 145 | .build(); 146 | 147 | // Triple speed bonus 148 | Modifier m2 = new Modifier.Builder() 149 | .modify(w) 150 | .speedBy(3.0) 151 | .build(); 152 | 153 | // Enable both bonuses, result is 6X speed bonus 154 | m1.enable(); 155 | m2.enable(); 156 | 157 | // World advances 6 seconds now, instead of 1 158 | w.update(1.0); 159 | 160 | // You can disable a single modifier and leave the other on 161 | m1.disable(); 162 | 163 | // Only the triple bonus is now enabled --> 3 seconds advancement 164 | w.update(1.0); 165 | ``` 166 | 167 | The modifier support is still pretty small, but more modifiers and 168 | modifiable properties will be available in the near future. 169 | 170 | ### Purchasing items 171 | 172 | Every item starts from level 0, meaning they don't "do" anything. 173 | You can query the price of an item by calling its `getPrice()` method: 174 | 175 | ```java 176 | Item item = ...; 177 | 178 | // Query the price of the NEXT level of the item 179 | BigInteger price = item.getPrice(); 180 | ``` 181 | 182 | To upgrade an item with currency, call the item's `buyWith()` method: 183 | 184 | ```java 185 | Currency gold = ...; 186 | Item item = ...; 187 | 188 | PurchaseResult result = item.buyWith(gold); 189 | ``` 190 | 191 | The returned `PurchaseResult` is an enum denoting the result. The 192 | possible out outcomes are: 193 | 194 | - `PurchaseResult.OK` when the item was successfully purchased or upgraded and the money was deducted 195 | 196 | - `PurchaseResult.INSUFFICIENT_FUNDS` when there was not enough money to buy the item 197 | 198 | - `PurchaseResult.MAX_LEVEL_REACHED` when the item has already reached its max level and cannot be upgraded any further 199 | 200 | ### Formatters 201 | 202 | You can query the amount of currency by calling its `getAmountAsString()` method, but 203 | this produces a rather ugly output that may not even fit on the screen. 204 | Instead, you can create a currency formatter to produce a nice output: 205 | 206 | ```java 207 | Formatter printGold = new Formatter.ForCurrency(gold) 208 | .groupDigits() // Group digits into groups of three 209 | .showHighestThousand() // Show only the highest triplet in the amount 210 | .showDecimals(2) // Show two decimals if "truncating" lower numbers 211 | .build(); 212 | 213 | // The formatter is now ready and prints out the current amount of gold 214 | System.out.println("Gold now: " + printGold); 215 | ``` 216 | 217 | In this example, if there's 123,456,789 gold, the output would be: 218 | 219 | ```java 220 | Gold now: 123.45 221 | ``` 222 | 223 | You usually want to use some indicators about the multitude of the currency (K for thousand, 224 | M for millions etc.). You can do this by supplying an array of "names" for each "thousand": 225 | 226 | ```java 227 | Formatter printGold = new Formatter.ForCurrency(gold) 228 | .groupDigits() 229 | .showHighestThousand() 230 | .showDecimals(2) 231 | .useAbbreviations(new String[] {"K", "M", "B", "T"}) 232 | .build(); 233 | 234 | System.out.println("Gold now: " + printGold); 235 | ``` 236 | 237 | In this case, if there's 123,456,789 gold, the output would be: 238 | 239 | ```java 240 | Gold now: 123.45M 241 | ``` 242 | 243 | If the amount of currency is higher than the amount of abbreviations supplied, 244 | the abbreviation will be omitted. Similarly, if the amount is less than 1,000, 245 | no abbreviation will be added. 246 | 247 | You can also format other things, e.g. the price of an item: 248 | 249 | ```java 250 | Formatter printItemPrice = new Formatter.ForItemPrice(item) 251 | .build(); 252 | ``` 253 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manabreak/libclicker2/e511d28655b3601d54fa475d99ebe14fcd0fedfd/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /libclicker/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /libclicker/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | dependencies { 4 | compile fileTree(dir: 'libs', include: ['*.jar']) 5 | compile 'junit:junit:4.12' 6 | } 7 | 8 | sourceCompatibility = "1.7" 9 | targetCompatibility = "1.7" 10 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/Automator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigInteger; 28 | 29 | import eu.manabreak.libclicker.generators.Generator; 30 | 31 | /** 32 | * Automator class for automating generators. 33 | *

34 | * Normally generators are manually controlled, i.e. they generate resources 35 | * when explicitly told to. Automators are used to trigger generators 36 | * during the world's update cycles. 37 | */ 38 | public class Automator extends Item implements Serializable { 39 | private Generator generator; 40 | private double tickRate = 1.0; 41 | private double tickTimer = 0.0; 42 | private double multiplier; 43 | private boolean enabled; 44 | private double actualTickRate; 45 | 46 | private Automator(World world, String name) { 47 | super(world, name); 48 | } 49 | 50 | /** 51 | * Enables this automator. Automators are enabled by default when 52 | * they are created. 53 | */ 54 | public void enable() { 55 | if (!enabled) { 56 | world.addAutomator(this); 57 | enabled = true; 58 | } 59 | } 60 | 61 | /** 62 | * Disables this automator, effectively turning the automation off. 63 | */ 64 | public void disable() { 65 | if (enabled) { 66 | world.removeAutomator(this); 67 | enabled = false; 68 | } 69 | } 70 | 71 | @Override 72 | public void upgrade() { 73 | super.upgrade(); //To change body of generated methods, choose Tools | Templates. 74 | actualTickRate = getFinalTickRate(); 75 | System.out.println("Upgraded, final tick rate now: " + actualTickRate); 76 | } 77 | 78 | private double getFinalTickRate() { 79 | if (itemLevel == 0) return 0.0; 80 | double r = tickRate; 81 | double m = Math.pow(multiplier, itemLevel - 1); 82 | return r / m; 83 | } 84 | 85 | void update(double delta) { 86 | if (!enabled || itemLevel == 0) return; 87 | 88 | tickTimer += delta; 89 | while (tickTimer >= actualTickRate) { 90 | tickTimer -= actualTickRate; 91 | generator.process(); 92 | } 93 | } 94 | 95 | /** 96 | * Retrieves the tick rate of this automator. 97 | * 98 | * @return Tick rate in seconds 99 | */ 100 | public double getTickRate() { 101 | return tickRate; 102 | } 103 | 104 | /** 105 | * Sets the tick rate of this automator. 106 | * 107 | * @param tickRate Tick rate in seconds 108 | */ 109 | public void setTickRate(double tickRate) { 110 | this.tickRate = tickRate; 111 | if (this.tickRate < 0.0) this.tickRate = 0.0; 112 | } 113 | 114 | /** 115 | * Retrieves the percentage of the tick. Useful 116 | * when creating progress bars for generators. 117 | * 118 | * @return Percentage of tick completion 119 | */ 120 | public double getTimerPercentage() { 121 | return tickRate != 0.0 ? tickTimer / tickRate : 1.0; 122 | } 123 | 124 | public static class Builder { 125 | private final World world; 126 | private Generator generator; 127 | private double tickRate = 1.0; 128 | private String name = "Nameless automator"; 129 | private boolean enabled = true; 130 | private BigInteger basePrice = BigInteger.ONE; 131 | private double priceMultiplier = 1.1; 132 | private double tickRateMultiplier = 1.08; 133 | 134 | /** 135 | * Constructs a new automator builder 136 | * 137 | * @param world World the automator belongs to 138 | */ 139 | public Builder(World world) { 140 | this.world = world; 141 | } 142 | 143 | /** 144 | * Constructs a new automator builder for the given generator 145 | * 146 | * @param world World the automator belongs to 147 | * @param generator Generator to automate 148 | */ 149 | public Builder(World world, Generator generator) { 150 | this.world = world; 151 | this.generator = generator; 152 | } 153 | 154 | public Builder basePrice(int price) { 155 | basePrice = new BigInteger("" + price); 156 | return this; 157 | } 158 | 159 | public Builder basePrice(long price) { 160 | basePrice = new BigInteger("" + price); 161 | return this; 162 | } 163 | 164 | public Builder basePrice(BigInteger price) { 165 | basePrice = price; 166 | return this; 167 | } 168 | 169 | public Builder priceMultiplier(double multiplier) { 170 | priceMultiplier = multiplier; 171 | return this; 172 | } 173 | 174 | public Builder tickRateMultiplier(double multiplier) { 175 | tickRateMultiplier = multiplier; 176 | return this; 177 | } 178 | 179 | /** 180 | * Sets the target generator this automator should automate. 181 | * 182 | * @param generator Generator to automate 183 | * @return This builder for chaining 184 | */ 185 | public Builder automate(Generator generator) { 186 | this.generator = generator; 187 | return this; 188 | } 189 | 190 | /** 191 | * Sets the name for this automator. 192 | * 193 | * @param name Name 194 | * @return This builder for chaining 195 | */ 196 | public Builder name(String name) { 197 | this.name = name; 198 | return this; 199 | } 200 | 201 | /** 202 | * Sets the tick rate of this automator, i.e. how often 203 | * this automator should do its business. 204 | * 205 | * @param seconds Tick rate in seconds 206 | * @return This builder for chaining 207 | */ 208 | public Builder every(double seconds) { 209 | tickRate = seconds; 210 | return this; 211 | } 212 | 213 | /** 214 | * Constructs the automator based on the given properties. 215 | * 216 | * @return The automator 217 | */ 218 | public Automator build() { 219 | if (generator == null) throw new IllegalStateException("Generator cannot be null"); 220 | 221 | Automator a = new Automator(world, name); 222 | a.generator = generator; 223 | a.tickRate = tickRate; 224 | a.enabled = enabled; 225 | a.basePrice = basePrice; 226 | a.priceMultiplier = priceMultiplier; 227 | a.multiplier = tickRateMultiplier; 228 | world.addAutomator(a); 229 | return a; 230 | } 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/Currency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigDecimal; 28 | import java.math.BigInteger; 29 | 30 | import eu.manabreak.libclicker.generators.Resource; 31 | 32 | /** 33 | * Base class for all currencies. 34 | */ 35 | public class Currency implements Serializable, Resource { 36 | 37 | private String name; 38 | private BigInteger value = BigInteger.ZERO; 39 | 40 | /** 41 | * Constructs a new currency with initial amount of 0 42 | * 43 | * @param name of the currency 44 | */ 45 | private Currency(String name) { 46 | this.name = name; 47 | } 48 | 49 | /** 50 | * Retrieves the name of this currency 51 | * 52 | * @return name 53 | */ 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public String getAmountAsString() { 59 | return value.toString(); 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return name + ": " + getAmountAsString(); 65 | } 66 | 67 | public BigInteger getValue() { 68 | return value; 69 | } 70 | 71 | @Override 72 | public void generate(BigInteger amount) { 73 | value = value.add(amount); 74 | } 75 | 76 | public void sub(BigInteger amount) { 77 | value = value.subtract(amount); 78 | } 79 | 80 | public void multiply(double multiplier) { 81 | BigDecimal tmp = new BigDecimal(value); 82 | tmp = tmp.multiply(new BigDecimal(multiplier)); 83 | value = tmp.toBigInteger(); 84 | } 85 | 86 | void set(BigInteger newValue) { 87 | value = newValue; 88 | } 89 | 90 | public static class Builder { 91 | private final World world; 92 | private String name = "Gold"; 93 | 94 | public Builder(World world) { 95 | this.world = world; 96 | } 97 | 98 | public Builder name(String name) { 99 | this.name = name; 100 | return this; 101 | } 102 | 103 | public Currency build() { 104 | Currency c = new Currency(name); 105 | world.addCurrency(c); 106 | return c; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/Item.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigDecimal; 28 | import java.math.BigInteger; 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | import eu.manabreak.libclicker.modifiers.Modifier; 33 | 34 | /** 35 | * Base class for all the purchasable "items". 36 | */ 37 | public abstract class Item implements Serializable { 38 | /** 39 | * World this item belongs to 40 | */ 41 | protected final World world; 42 | 43 | /** 44 | * Modifiers applied to this item 45 | */ 46 | protected final List modifiers = new ArrayList<>(); 47 | 48 | /** 49 | * The base price of the item (i.e. the price of the first level of this item) 50 | */ 51 | protected BigInteger basePrice = BigInteger.ONE; 52 | 53 | /** 54 | * Name of this item 55 | */ 56 | protected String name = "Nameless Item"; 57 | 58 | /** 59 | * Description text for this item 60 | */ 61 | protected String description = "No description."; 62 | 63 | /** 64 | * Current level of this item 65 | */ 66 | protected long itemLevel = 0; 67 | 68 | /** 69 | * Max. item level 70 | */ 71 | protected long maxItemLevel = Long.MAX_VALUE; 72 | 73 | /** 74 | * Price multiplier per level. This is used in the price formula 75 | * like this: price = (base price) * (price multiplier) ^ (item level) 76 | */ 77 | protected double priceMultiplier = 1.145; 78 | 79 | /** 80 | * Constructs a new item 81 | * 82 | * @param world World this item belongs to 83 | */ 84 | protected Item(World world) { 85 | this.world = world; 86 | } 87 | 88 | /** 89 | * Constructs a new item 90 | * 91 | * @param world World this item belongs to 92 | * @param name Name of this item 93 | */ 94 | protected Item(World world, String name) { 95 | this.world = world; 96 | setName(name); 97 | } 98 | 99 | /** 100 | * Retrieves the name of this item 101 | * 102 | * @return Name of this item 103 | */ 104 | public String getName() { 105 | return name; 106 | } 107 | 108 | /** 109 | * Sets the name of this item 110 | * 111 | * @param name New name for this item 112 | */ 113 | public void setName(String name) { 114 | if (name == null || name.length() == 0) 115 | throw new RuntimeException("Item name cannot be null or empty"); 116 | this.name = name; 117 | } 118 | 119 | public String getDescription() { 120 | return description; 121 | } 122 | 123 | public void setDescription(String description) { 124 | this.description = description; 125 | } 126 | 127 | /** 128 | * Retrieves the base price of this item 129 | * 130 | * @return Base price of this item 131 | */ 132 | public BigInteger getBasePrice() { 133 | return basePrice; 134 | } 135 | 136 | public void setBasePrice(int basePrice) { 137 | this.basePrice = new BigInteger("" + basePrice); 138 | } 139 | 140 | public BigInteger getPrice() { 141 | BigDecimal tmp = new BigDecimal(basePrice); 142 | tmp = tmp.multiply(new BigDecimal(Math.pow(priceMultiplier, itemLevel))); 143 | return tmp.toBigInteger(); 144 | } 145 | 146 | public PurchaseResult buyWith(Currency currency) { 147 | if (currency == null) throw new IllegalArgumentException("Currency cannot be null"); 148 | if (itemLevel >= maxItemLevel) 149 | return PurchaseResult.MAX_LEVEL_REACHED; 150 | 151 | BigInteger price = getPrice(); 152 | BigInteger result = currency.getValue().subtract(price); 153 | if (result.signum() < 0) { 154 | return PurchaseResult.INSUFFICIENT_FUNDS; 155 | } 156 | currency.sub(price); 157 | upgrade(); 158 | return PurchaseResult.OK; 159 | } 160 | 161 | /** 162 | * Sets the base price of this item 163 | * 164 | * @param basePrice New base price for this item 165 | */ 166 | public void setBasePrice(BigInteger basePrice) { 167 | if (basePrice == null) throw new RuntimeException("Base price cannot be null"); 168 | if (basePrice.equals(BigInteger.ZERO)) 169 | throw new RuntimeException("Base price cannot be zero"); 170 | this.basePrice = basePrice; 171 | } 172 | 173 | public void setBasePrice(long basePrice) { 174 | this.basePrice = new BigInteger("" + basePrice); 175 | } 176 | 177 | /** 178 | * Retrieves the price multiplier 179 | * 180 | * @return Price multiplier 181 | */ 182 | public double getPriceMultiplier() { 183 | return priceMultiplier; 184 | } 185 | 186 | /** 187 | * Sets the price multiplier of this item 188 | * 189 | * @param multiplier Price multiplier 190 | */ 191 | public void setPriceMultiplier(double multiplier) { 192 | priceMultiplier = multiplier; 193 | } 194 | 195 | public long getMaxItemLevel() { 196 | return maxItemLevel; 197 | } 198 | 199 | public void setMaxItemLevel(long maxLvl) { 200 | if (maxLvl <= 0) throw new RuntimeException("Max item level cannot be zero or negative"); 201 | maxItemLevel = maxLvl; 202 | } 203 | 204 | public long getItemLevel() { 205 | return itemLevel; 206 | } 207 | 208 | public void setItemLevel(long lvl) { 209 | itemLevel = lvl < 0 ? 0 : lvl > maxItemLevel ? maxItemLevel : lvl; 210 | } 211 | 212 | public void upgrade() { 213 | if (itemLevel < maxItemLevel) { 214 | itemLevel++; 215 | } 216 | } 217 | 218 | public void downgrade() { 219 | if (itemLevel > 0) { 220 | itemLevel--; 221 | } 222 | } 223 | 224 | public void maximize() { 225 | itemLevel = maxItemLevel; 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/PurchaseResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | /** 27 | * A purchase result enumeration. Denotes the result when trying to 28 | * purchase an item. 29 | */ 30 | public enum PurchaseResult { 31 | OK, 32 | INSUFFICIENT_FUNDS, 33 | MAX_LEVEL_REACHED 34 | } 35 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/World.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | import eu.manabreak.libclicker.generators.Generator; 31 | import eu.manabreak.libclicker.modifiers.Modifier; 32 | 33 | /** 34 | * A container for all the clicker objects 35 | */ 36 | public class World implements Serializable { 37 | 38 | private final List generators = new ArrayList<>(); 39 | private final List automators = new ArrayList<>(); 40 | private final List currencies = new ArrayList<>(); 41 | private final List modifiers = new ArrayList<>(); 42 | 43 | private double speedMultiplier = 1.0; 44 | private boolean updateAutomators = true; 45 | 46 | /** 47 | * Constructs a new world. All the other components require an existing 48 | * "world" to function. A world is a container for the whole system. 49 | */ 50 | public World() { 51 | 52 | } 53 | 54 | /** 55 | * Adds a new generator to this world 56 | * 57 | * @param generator Generator to generate 58 | */ 59 | public void addGenerator(Generator generator) { 60 | if (generator != null && !generators.contains(generator)) { 61 | generators.add(generator); 62 | } 63 | } 64 | 65 | /** 66 | * Returns the number of generators in this world 67 | * 68 | * @return The number of generators in this world 69 | */ 70 | public int getGeneratorCount() { 71 | return generators.size(); 72 | } 73 | 74 | /** 75 | * Removes a generator 76 | * 77 | * @param generator Generator to remove 78 | */ 79 | public void removeGenerator(Generator generator) { 80 | if (generator != null && generators.contains(generator)) { 81 | generators.remove(generator); 82 | } 83 | } 84 | 85 | /** 86 | * Removes all the generators from this world 87 | */ 88 | public void removeAllGenerators() { 89 | generators.clear(); 90 | } 91 | 92 | /** 93 | * Registers a new currency in the world, making 94 | * the currency usable. 95 | * 96 | * @param c currency to register 97 | */ 98 | public void addCurrency(Currency c) { 99 | if (c != null && !currencies.contains(c)) { 100 | currencies.add(c); 101 | } 102 | } 103 | 104 | /** 105 | * Removes a currency from the world. 106 | * 107 | * @param c currency to remove 108 | */ 109 | public void removeCurrency(Currency c) { 110 | if (c != null) { 111 | currencies.remove(c); 112 | } 113 | } 114 | 115 | /** 116 | * Retrieves a currency at the given index. 117 | * The index is based on the order in which 118 | * the currencies were added to the world. 119 | * 120 | * @param index of the currency 121 | * @return the currency at the given index, or null if not found 122 | */ 123 | public Currency getCurrency(int index) { 124 | return currencies.get(index); 125 | } 126 | 127 | /** 128 | * Retrieves a list of all the currencies currently 129 | * registered in the world. 130 | * 131 | * @return list of currencies 132 | */ 133 | public List getCurrencies() { 134 | return currencies; 135 | } 136 | 137 | /** 138 | * Removes all currencies registered in the world. 139 | */ 140 | public void removeAllCurrencies() { 141 | currencies.clear(); 142 | } 143 | 144 | /** 145 | * Advances the world state by the given amount of seconds. 146 | * Useful when calculating away-from-keyboard income etc. 147 | * 148 | * @param seconds Seconds to advance 149 | */ 150 | public void update(double seconds) { 151 | seconds *= speedMultiplier; 152 | 153 | if (updateAutomators) { 154 | for (Automator a : automators) { 155 | a.update(seconds); 156 | } 157 | } 158 | } 159 | 160 | /** 161 | * Registers a new automator to the world. 162 | * 163 | * @param automator to register 164 | */ 165 | public void addAutomator(Automator automator) { 166 | if (automator != null && !automators.contains(automator)) { 167 | automators.add(automator); 168 | } 169 | } 170 | 171 | /** 172 | * Registers a new modifier 173 | * 174 | * @param modifier to register 175 | */ 176 | public void addModifier(Modifier modifier) { 177 | if (modifier != null && !modifiers.contains(modifier)) { 178 | modifiers.add(modifier); 179 | } 180 | } 181 | 182 | /** 183 | * Retrieves the global speed multiplier 184 | * 185 | * @return the speed multiplier 186 | */ 187 | public double getSpeedMultiplier() { 188 | return speedMultiplier; 189 | } 190 | 191 | /** 192 | * Sets the global speed multiplier 193 | * 194 | * @param multiplier of the world update speed 195 | */ 196 | public void setSpeedMultiplier(double multiplier) { 197 | speedMultiplier = multiplier; 198 | } 199 | 200 | /** 201 | * Disables all automators 202 | */ 203 | public void disableAutomators() { 204 | updateAutomators = false; 205 | } 206 | 207 | /** 208 | * Enables all automators 209 | */ 210 | public void enableAutomators() { 211 | updateAutomators = true; 212 | } 213 | 214 | /** 215 | * Removes an automator from the world 216 | * 217 | * @param automator to remove 218 | */ 219 | public void removeAutomator(Automator automator) { 220 | if (automator != null) { 221 | automators.remove(automator); 222 | } 223 | } 224 | 225 | /** 226 | * Retrieves all the automators registered in the world 227 | * 228 | * @return list of automators 229 | */ 230 | public List getAutomators() { 231 | return automators; 232 | } 233 | 234 | /** 235 | * Retrieves all the modifiers registered in the world 236 | * 237 | * @return list of modifiers 238 | */ 239 | public List getModifiers() { 240 | return modifiers; 241 | } 242 | 243 | /** 244 | * Removes a modifier from the world 245 | * 246 | * @param modifier to remove 247 | */ 248 | public void removeModifier(Modifier modifier) { 249 | if (modifier != null) { 250 | modifiers.remove(modifier); 251 | } 252 | } 253 | 254 | /** 255 | * Queries whether or not the automators are enabled. 256 | * 257 | * @return True if automation is enabled, false otherwise. 258 | */ 259 | public boolean isAutomationEnabled() { 260 | return updateAutomators; 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/formatting/CurrencyFormatter.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.formatting; 2 | 3 | import eu.manabreak.libclicker.Currency; 4 | 5 | /** 6 | * Formats a currency to a nice string representation. 7 | */ 8 | public class CurrencyFormatter extends Formatter { 9 | private final Currency currency; 10 | 11 | CurrencyFormatter(Builder builder, Currency currency) { 12 | super(builder); 13 | this.currency = currency; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | setRawString(currency.getValue().toString()); 19 | return super.toString(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/formatting/Formatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker.formatting; 25 | 26 | import eu.manabreak.libclicker.Currency; 27 | import eu.manabreak.libclicker.Item; 28 | 29 | /** 30 | * A formatter for BigInteger values. 31 | * 32 | * @author Harri Pellikka 33 | */ 34 | public class Formatter { 35 | 36 | protected final boolean groupDigits; 37 | protected final String thousandSeparator; 38 | protected final boolean showDecimals; 39 | protected final int decimals; 40 | protected final String decimalSeparator; 41 | protected final boolean cutAtHighest; 42 | protected final String[] abbreviations; 43 | 44 | protected Formatter(Builder builder) { 45 | groupDigits = builder.groupDigits; 46 | thousandSeparator = builder.thousandSeparator; 47 | showDecimals = builder.showDecimals; 48 | decimals = builder.decimals; 49 | decimalSeparator = builder.decimalSeparator; 50 | cutAtHighest = builder.cutAtHighest; 51 | abbreviations = builder.abbreviations; 52 | } 53 | 54 | public static class ForItemPrice extends Builder { 55 | private Item item; 56 | 57 | public ForItemPrice(Item item) { 58 | this.item = item; 59 | } 60 | 61 | @Override 62 | public ItemPriceFormatter build() { 63 | return new ItemPriceFormatter(this, item); 64 | } 65 | } 66 | 67 | public static class ForCurrency extends Builder { 68 | private Currency currency; 69 | 70 | public ForCurrency(Currency c) { 71 | currency = c; 72 | } 73 | 74 | public CurrencyFormatter build() { 75 | return new CurrencyFormatter(this, currency); 76 | } 77 | } 78 | 79 | public static abstract class Builder { 80 | private boolean groupDigits = true; 81 | private String thousandSeparator = ","; 82 | private boolean showDecimals = false; 83 | private int decimals = 2; 84 | private String decimalSeparator; 85 | private boolean cutAtHighest = true; 86 | private String[] abbreviations = null; 87 | 88 | private Builder() { 89 | 90 | } 91 | 92 | public Builder showHighestThousand() { 93 | cutAtHighest = true; 94 | return this; 95 | } 96 | 97 | public Builder showFully() { 98 | cutAtHighest = false; 99 | return this; 100 | } 101 | 102 | public Builder groupDigits() { 103 | return groupDigits(","); 104 | } 105 | 106 | public Builder groupDigits(String separator) { 107 | groupDigits = true; 108 | thousandSeparator = separator; 109 | return this; 110 | } 111 | 112 | public Builder dontGroupDigits() { 113 | groupDigits = false; 114 | thousandSeparator = null; 115 | return this; 116 | } 117 | 118 | public Builder showDecimals() { 119 | return showDecimals(2, "."); 120 | } 121 | 122 | public Builder showDecimals(int count) { 123 | return showDecimals(count, "."); 124 | } 125 | 126 | public Builder showDecimals(String separator) { 127 | return showDecimals(2, separator); 128 | } 129 | 130 | public Builder showDecimals(int count, String separator) { 131 | showDecimals = true; 132 | decimals = count; 133 | decimalSeparator = separator; 134 | return this; 135 | } 136 | 137 | public Builder dontShowDecimals() { 138 | showDecimals = false; 139 | decimals = 0; 140 | decimalSeparator = null; 141 | return this; 142 | } 143 | 144 | public Builder useAbbreviations(String[] abbreviations) { 145 | this.abbreviations = abbreviations; 146 | return this; 147 | } 148 | 149 | public abstract Formatter build(); 150 | } 151 | 152 | 153 | private String rawString = ""; 154 | 155 | public void setRawString(String raw) { 156 | rawString = raw; 157 | if (rawString == null) rawString = ""; 158 | } 159 | 160 | @Override 161 | public String toString() { 162 | String raw = rawString; 163 | if (cutAtHighest) { 164 | int length = raw.length(); 165 | if (length < 4) return raw; 166 | int rem = length % 3; 167 | rem = rem == 0 ? 3 : rem; 168 | String top = raw.substring(0, rem); 169 | 170 | if (showDecimals) { 171 | top += decimalSeparator; 172 | int decimals = Math.min(this.decimals, length - rem); 173 | top += raw.substring(rem, rem + decimals); 174 | } 175 | 176 | if (abbreviations != null) { 177 | int tri = (raw.length() - 1) / 3; 178 | if (tri > 0 && tri <= abbreviations.length) { 179 | top += abbreviations[tri - 1]; 180 | } 181 | } 182 | 183 | return top; 184 | } else { 185 | if (groupDigits) { 186 | int len = raw.length() - 3; 187 | for (int i = len; i > 0; --i) { 188 | if ((len - i) % 3 == 0) { 189 | raw = raw.substring(0, i) + thousandSeparator + raw.substring(i); 190 | } 191 | } 192 | } 193 | return raw; 194 | } 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/formatting/ItemPriceFormatter.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.formatting; 2 | 3 | import eu.manabreak.libclicker.Item; 4 | 5 | /** 6 | * Formats an item's price to a nice string representation. 7 | */ 8 | public class ItemPriceFormatter extends Formatter { 9 | private final Item item; 10 | 11 | ItemPriceFormatter(Builder builder, Item item) { 12 | super(builder); 13 | this.item = item; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | setRawString(item.getPrice().toString()); 19 | return super.toString(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/generators/Generator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker.generators; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigDecimal; 28 | import java.math.BigInteger; 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | import eu.manabreak.libclicker.Item; 33 | import eu.manabreak.libclicker.World; 34 | import eu.manabreak.libclicker.modifiers.GeneratorModifier; 35 | import eu.manabreak.libclicker.utils.RandomUtils; 36 | 37 | /** 38 | * A base class for all the generators. 39 | *

40 | * Generators are used to produce resources (e.g. currencies), and 41 | * can be controlled either manually or automatically by using 42 | * an Automator. 43 | */ 44 | public class Generator extends Item implements Serializable { 45 | public interface Callback { 46 | void onProcessed(); 47 | } 48 | 49 | private Callback callback = null; 50 | private T resource; 51 | private long timesProcessed = 0; 52 | private BigInteger baseAmount; 53 | private double amountMultiplier; 54 | private double probability; 55 | private boolean useProbability; 56 | private boolean useRemainder; 57 | private double remainder; 58 | private double cooldown; 59 | private List modifiers = new ArrayList<>(); 60 | 61 | /** 62 | * Builder class for creating new generators 63 | */ 64 | public static class Builder { 65 | private final World world; 66 | private String name = "Nameless generator"; 67 | private Callback onProcessed = null; 68 | private Resource resource; 69 | private BigInteger baseAmount = BigInteger.ONE; 70 | private double amountMultiplier = 1.1; 71 | private long maxLevel = Long.MAX_VALUE; 72 | private BigInteger basePrice = BigInteger.ONE; 73 | private double priceMultiplier = 1.1; 74 | private double probability = 1.0; 75 | private boolean probabilitySet = false; 76 | private boolean useRemainder = true; 77 | private double cooldown = 0.0; 78 | 79 | /** 80 | * Creates a new generator builder 81 | * 82 | * @param world World to build the generator into 83 | */ 84 | public Builder(World world) { 85 | this.world = world; 86 | } 87 | 88 | /** 89 | * Sets the cooldown of this generator (in seconds). 90 | * This is the minimum time between processing this 91 | * generator. 92 | * 93 | * @param cooldown in seconds 94 | * @return This builder for chaining 95 | */ 96 | public Builder cooldown(double cooldown) { 97 | this.cooldown = cooldown; 98 | return this; 99 | } 100 | 101 | /** 102 | * Store remainder of resources and generate an extra 103 | * when the remainder "overflows" 104 | * 105 | * @return This builder for chaining 106 | */ 107 | public Builder useRemainder() { 108 | useRemainder = true; 109 | return this; 110 | } 111 | 112 | /** 113 | * Discard remainder of resources when generating. 114 | * 115 | * @return This builder for chaining 116 | */ 117 | public Builder discardRemainder() { 118 | useRemainder = false; 119 | return this; 120 | } 121 | 122 | /** 123 | * Sets the name for the generator 124 | * 125 | * @param name Name for the generator 126 | * @return This builder for chaining 127 | */ 128 | public Builder name(String name) { 129 | this.name = name; 130 | return this; 131 | } 132 | 133 | /** 134 | * Sets the multiplier for resource generation. This multiplier 135 | * is used in the formula (amount) = (base amount) * (multiplier) ^ (level) 136 | * 137 | * @param multiplier Amount generation multiplier per level 138 | * @return This builder for chaining 139 | */ 140 | public Builder multiplier(double multiplier) { 141 | amountMultiplier = multiplier; 142 | return this; 143 | } 144 | 145 | /** 146 | * Sets the maximum allowed level for this generator. The max level must 147 | * be greated than zero. 148 | * 149 | * @param maxLevel Maximum allowed level for this generator 150 | * @return This builder for chaining 151 | */ 152 | public Builder maxLevel(long maxLevel) { 153 | if (maxLevel <= 0) 154 | throw new IllegalArgumentException("Max level must be greater than 0"); 155 | this.maxLevel = maxLevel; 156 | return this; 157 | } 158 | 159 | /** 160 | * Sets the base amount of resources generated by this generator. 161 | * This is the amount the generator generates at level 1 and is used 162 | * as the base for the higher levels. 163 | * 164 | * @param amount Base amount of resources generated at level 1 165 | * @return This builder for chaining 166 | */ 167 | public Builder baseAmount(BigInteger amount) { 168 | if (amount == null) throw new IllegalArgumentException("Base amount cannot be null"); 169 | baseAmount = amount; 170 | return this; 171 | } 172 | 173 | /** 174 | * Sets the base amount of resources generated by this generator. 175 | * This is the amount the generator generates at level 1 and is used 176 | * as the base for the higher levels. 177 | * 178 | * @param amount Base amount of resources generated at level 1 179 | * @return This builder for chaining 180 | */ 181 | public Builder baseAmount(long amount) { 182 | baseAmount = new BigInteger("" + amount); 183 | return this; 184 | } 185 | 186 | /** 187 | * Sets the base amount of resources generated by this generator. 188 | * This is the amount the generator generates at level 1 and is used 189 | * as the base for the higher levels. 190 | * 191 | * @param amount Base amount of resources generated at level 1 192 | * @return This builder for chaining 193 | */ 194 | public Builder baseAmount(int amount) { 195 | baseAmount = new BigInteger("" + amount); 196 | return this; 197 | } 198 | 199 | /** 200 | * Sets the currency that should be generated by the generator. 201 | * 202 | * @param resource Resource to generate 203 | * @return This builder for chaining 204 | * @throws IllegalArgumentException Thrown if the currency is null 205 | */ 206 | public Builder generate(Resource resource) throws IllegalArgumentException { 207 | if (resource == null) throw new IllegalArgumentException("Currency cannot be null"); 208 | this.resource = resource; 209 | return this; 210 | } 211 | 212 | /** 213 | * Sets a callback for the generator to be called when the generator 214 | * has finished its processing cycle (i.e. has generated something). 215 | * 216 | * @param callback Callback to call after generating something 217 | * @return This builder for chaining 218 | */ 219 | public Builder callback(Callback callback) { 220 | onProcessed = callback; 221 | return this; 222 | } 223 | 224 | public Builder price(BigInteger price) { 225 | basePrice = price; 226 | return this; 227 | } 228 | 229 | public Builder price(long price) { 230 | basePrice = new BigInteger("" + price); 231 | return this; 232 | } 233 | 234 | public Builder price(int price) { 235 | basePrice = new BigInteger("" + price); 236 | return this; 237 | } 238 | 239 | public Builder priceMultiplier(double multiplier) { 240 | priceMultiplier = multiplier; 241 | return this; 242 | } 243 | 244 | /** 245 | * Set a probability for this generator to "work" when it's processed 246 | * 247 | * @param probability Probability percentage (between 0.0 and 1.0) 248 | * @return This builder for chaining 249 | */ 250 | public Builder probability(double probability) { 251 | if (probability < 0 || probability > 1.0) 252 | throw new IllegalArgumentException("Probability should be between 0.0 and 1.0"); 253 | this.probability = probability; 254 | probabilitySet = true; 255 | return this; 256 | } 257 | 258 | /** 259 | * Constructs the generator based on the given parameters 260 | * 261 | * @return The generator 262 | */ 263 | public Generator build() { 264 | Generator g = new Generator(world, name); 265 | g.callback = onProcessed; 266 | g.resource = resource; 267 | g.amountMultiplier = amountMultiplier; 268 | g.baseAmount = baseAmount; 269 | g.maxItemLevel = maxLevel; 270 | g.basePrice = basePrice; 271 | g.priceMultiplier = priceMultiplier; 272 | g.probability = probability; 273 | g.useProbability = probabilitySet; 274 | g.useRemainder = useRemainder; 275 | g.cooldown = cooldown; 276 | world.addGenerator(g); 277 | return g; 278 | } 279 | } 280 | 281 | /** 282 | * Constructs a new generator 283 | */ 284 | private Generator(World world) { 285 | super(world); 286 | } 287 | 288 | /** 289 | * Constructs a new generator 290 | * 291 | * @param name Name of this generator 292 | */ 293 | private Generator(World world, String name) { 294 | super(world, name); 295 | } 296 | 297 | /** 298 | * Upgrades this generator by one level 299 | */ 300 | public void upgrade() { 301 | if (itemLevel < maxItemLevel) { 302 | itemLevel++; 303 | } 304 | } 305 | 306 | /** 307 | * Downgrades this generator by one level 308 | */ 309 | public void downgrade() { 310 | if (itemLevel > 0) { 311 | itemLevel--; 312 | } 313 | } 314 | 315 | /** 316 | * Retrieves the amount this generator currently is generating per 317 | * processing cycle 318 | * 319 | * @return Amount of resources generated by this generator 320 | */ 321 | public BigInteger getGeneratedAmount() { 322 | if (itemLevel == 0) return BigInteger.ZERO; 323 | 324 | BigDecimal tmp = new BigDecimal(baseAmount); 325 | tmp = tmp.multiply(new BigDecimal(Math.pow(amountMultiplier, itemLevel - 1))); 326 | if (useRemainder) { 327 | double tmpRem = tmp.remainder(BigDecimal.ONE).doubleValue(); 328 | remainder += tmpRem; 329 | if (remainder >= 0.999) { 330 | remainder -= 1.0; 331 | tmp = tmp.add(new BigDecimal(1)); 332 | } 333 | } 334 | 335 | tmp = processModifiers(tmp); 336 | 337 | return tmp.toBigInteger(); 338 | } 339 | 340 | private BigDecimal processModifiers(BigDecimal val) { 341 | if (modifiers.size() == 0) return val; 342 | 343 | for (GeneratorModifier m : modifiers) { 344 | double d = m.getMultiplier(); 345 | if (d != 1.0) { 346 | val = val.multiply(new BigDecimal(d)); 347 | } 348 | } 349 | 350 | return val; 351 | } 352 | 353 | /** 354 | * Determines if this generator should generate anything based on its 355 | * properties such as item level and probability. 356 | * 357 | * @return True if should work, false otherwise 358 | */ 359 | private boolean isWorking() { 360 | if (itemLevel > 0) { 361 | if (!useProbability || RandomUtils.nextDouble() < probability) return true; 362 | } 363 | return false; 364 | } 365 | 366 | /** 367 | * Processes this generator, generating resources as per the rules 368 | * of this generator. 369 | */ 370 | public void process() { 371 | if (isWorking()) { 372 | resource.generate(getGeneratedAmount()); 373 | timesProcessed++; 374 | if (callback != null) callback.onProcessed(); 375 | } 376 | } 377 | 378 | /** 379 | * Retrieves the number of times this generator has done its processing 380 | * 381 | * @return Number of times processed 382 | */ 383 | public long getTimesProcessed() { 384 | return timesProcessed; 385 | } 386 | 387 | public void attachModifier(GeneratorModifier modifier) { 388 | if (modifier != null && !modifiers.contains(modifier)) { 389 | modifiers.add(modifier); 390 | } 391 | } 392 | 393 | public void detachModifier(GeneratorModifier modifier) { 394 | if (modifier != null) { 395 | modifiers.remove(modifier); 396 | } 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/generators/Resource.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.generators; 2 | 3 | import java.math.BigInteger; 4 | 5 | /** 6 | * Represents a resource that can be generated 7 | * by the generators. 8 | */ 9 | public interface Resource { 10 | void generate(BigInteger amount); 11 | } 12 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/modifiers/GeneratorModifier.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.modifiers; 2 | 3 | import eu.manabreak.libclicker.World; 4 | import eu.manabreak.libclicker.generators.Generator; 5 | 6 | /** 7 | * Modifier for generators. 8 | */ 9 | public class GeneratorModifier extends Modifier { 10 | private final Generator generator; 11 | double multiplier = 1.0; 12 | 13 | GeneratorModifier(World world, Generator generator) { 14 | super(world); 15 | this.generator = generator; 16 | } 17 | 18 | @Override 19 | protected void onEnable() { 20 | generator.attachModifier(this); 21 | } 22 | 23 | @Override 24 | protected void onDisable() { 25 | generator.detachModifier(this); 26 | } 27 | 28 | public double getMultiplier() { 29 | return multiplier; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/modifiers/Modifiable.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.modifiers; 2 | 3 | public interface Modifiable { 4 | void applyModification(Modifier modifier); 5 | } 6 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/modifiers/Modifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker.modifiers; 25 | 26 | import java.io.Serializable; 27 | 28 | import eu.manabreak.libclicker.Item; 29 | import eu.manabreak.libclicker.World; 30 | import eu.manabreak.libclicker.generators.Generator; 31 | 32 | /** 33 | * A base class for all the modifiers. 34 | *

35 | * A modifier does "something" to a component (generator, automator, the 36 | * world etc), for example speeds up, slows down, increases production 37 | * or something similar. 38 | * 39 | * @author Harri Pellikka 40 | */ 41 | public abstract class Modifier extends Item implements Serializable { 42 | private boolean enabled = false; 43 | 44 | protected Modifier(World world) { 45 | super(world); 46 | } 47 | 48 | protected abstract void onEnable(); 49 | 50 | protected abstract void onDisable(); 51 | 52 | /** 53 | * Enables this modifier, i.e. makes it active 54 | */ 55 | public void enable() { 56 | if (!enabled) { 57 | enabled = true; 58 | world.addModifier(this); 59 | onEnable(); 60 | } 61 | } 62 | 63 | /** 64 | * Disables this modifier, i.e. makes it inactive 65 | */ 66 | public void disable() { 67 | if (enabled) { 68 | onDisable(); 69 | world.removeModifier(this); 70 | enabled = false; 71 | } 72 | } 73 | 74 | /** 75 | * Checks whether or not this modifier is enabled 76 | * 77 | * @return True if enabled, false otherwise 78 | */ 79 | public boolean isEnabled() { 80 | return enabled; 81 | } 82 | 83 | /** 84 | * Builder class for the modifiers 85 | */ 86 | public static class Builder { 87 | /** 88 | * Constructs a new modifier builder 89 | */ 90 | public Builder() { 91 | 92 | } 93 | 94 | /** 95 | * Apply the modifier to a world 96 | * 97 | * @param world World to modify 98 | * @return A world target to set the modification details 99 | */ 100 | public final WorldTarget modify(World world) { 101 | return new WorldTarget(world); 102 | } 103 | 104 | /** 105 | * Apply the modifier to a generator 106 | * 107 | * @param gen Generator to modify 108 | * @return A generator target to set the modification details 109 | */ 110 | public final GeneratorTarget modify(World world, Generator gen) { 111 | return new GeneratorTarget(world, gen); 112 | } 113 | 114 | /** 115 | * A modifier settings class for world modifiers. 116 | * Keeps track of all the parameters the modifier should 117 | * modify. 118 | */ 119 | public static class WorldTarget { 120 | World world; 121 | private double speedMultiplier = 1.0; 122 | private boolean disableActivators = false; 123 | 124 | WorldTarget(World w) { 125 | world = w; 126 | } 127 | 128 | /** 129 | * Speeds up all the processing by the given multiplier. 130 | * 131 | * @param multiplier Multiplier for advancing the time 132 | * @return This target for chaining 133 | */ 134 | public WorldTarget speedBy(double multiplier) { 135 | speedMultiplier = multiplier; 136 | return this; 137 | } 138 | 139 | /** 140 | * Disables all the activators 141 | * 142 | * @return This target for chaining 143 | */ 144 | public WorldTarget disableActivators() { 145 | disableActivators = true; 146 | return this; 147 | } 148 | 149 | /** 150 | * Creates the actual modifier based on the given settings 151 | * 152 | * @return Modifier 153 | */ 154 | public Modifier build() { 155 | WorldModifier m = new WorldModifier(world); 156 | m.speedMultiplier = speedMultiplier; 157 | m.disableActivators = disableActivators; 158 | return m; 159 | } 160 | } 161 | 162 | /** 163 | * A modifier settings class for generator modifiers. 164 | * Keeps track of all the parameters the modifier should 165 | * modify. 166 | */ 167 | public static class GeneratorTarget { 168 | private final World world; 169 | private Generator generator; 170 | private double multiplier = 1.0; 171 | 172 | GeneratorTarget(World world, Generator gen) { 173 | this.world = world; 174 | generator = gen; 175 | } 176 | 177 | /** 178 | * Multiplies the production of the generator. 179 | * 180 | * @param multiplier Multiplier 181 | * @return This target for chaining 182 | */ 183 | public GeneratorTarget multiplier(double multiplier) { 184 | this.multiplier = multiplier; 185 | return this; 186 | } 187 | 188 | /** 189 | * Constructs the actual modifier with the given settings 190 | * 191 | * @return Modifier as per the given settings 192 | */ 193 | public Modifier build() { 194 | GeneratorModifier m = new GeneratorModifier(world, generator); 195 | m.multiplier = multiplier; 196 | return m; 197 | } 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/modifiers/WorldModifier.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.modifiers; 2 | 3 | import eu.manabreak.libclicker.World; 4 | 5 | /** 6 | * Modifier for worlds 7 | */ 8 | public class WorldModifier extends Modifier { 9 | double speedMultiplier; 10 | boolean disableActivators; 11 | 12 | public WorldModifier(World world) { 13 | super(world); 14 | } 15 | 16 | @Override 17 | protected void onEnable() { 18 | if (speedMultiplier != 1.0) { 19 | double speedMultiplierBefore = world.getSpeedMultiplier(); 20 | double speedMultiplierAfter = speedMultiplier * speedMultiplierBefore; 21 | world.setSpeedMultiplier(speedMultiplierAfter); 22 | } 23 | 24 | if (disableActivators) { 25 | world.disableAutomators(); 26 | } 27 | } 28 | 29 | @Override 30 | protected void onDisable() { 31 | if (speedMultiplier != 1.0) { 32 | double d = world.getSpeedMultiplier(); 33 | d /= speedMultiplier; 34 | world.setSpeedMultiplier(d); 35 | } 36 | 37 | if (disableActivators) { 38 | world.enableAutomators(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libclicker/src/main/java/eu/manabreak/libclicker/utils/RandomUtils.java: -------------------------------------------------------------------------------- 1 | package eu.manabreak.libclicker.utils; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomUtils { 6 | 7 | private static final Random random = new Random(); 8 | 9 | /** 10 | * Generates a new random integer 11 | * 12 | * @return random integer 13 | */ 14 | public static int getRandomInt() { 15 | return random.nextInt(); 16 | } 17 | 18 | /** 19 | * Generates a new random integer between 0 (inclusive) 20 | * and the given maximum value (exclusive) 21 | * 22 | * @param max value (exclusive) 23 | * @return random integer 24 | */ 25 | public static int getRandomInt(int max) { 26 | return random.nextInt(max); 27 | } 28 | 29 | /** 30 | * Generates a new random integer between the minimum 31 | * value (inclusive) and maximum value (exclusive) 32 | * 33 | * @param min minimum value (inclusive) 34 | * @param max maximum value (exclusive) 35 | * @return random integer 36 | */ 37 | public static int getRandomInt(int min, int max) { 38 | return random.nextInt(max - min) + min; 39 | } 40 | 41 | /** 42 | * Generates a new random double between 0.0 and 1.0, 43 | * both inclusive. 44 | * 45 | * @return random double between 0.0 and 1.0 46 | */ 47 | public static double nextDouble() { 48 | return random.nextDouble(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/AutomatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | import eu.manabreak.libclicker.generators.Generator; 29 | 30 | import static org.junit.Assert.assertEquals; 31 | 32 | public class AutomatorTest { 33 | @Test 34 | public void testUpdate() { 35 | World world = new World(); 36 | 37 | System.out.println("update()"); 38 | Currency c = new Currency.Builder(world) 39 | .build(); 40 | Generator g = new Generator.Builder(world) 41 | .generate(c) 42 | .build(); 43 | g.upgrade(); 44 | 45 | Automator a = new Automator.Builder(world) 46 | .automate(g) 47 | .every(1.0) 48 | .build(); 49 | a.upgrade(); 50 | 51 | world.update(1.0); 52 | assertEquals(1, g.getTimesProcessed()); 53 | 54 | world.update(9.0); 55 | assertEquals(10, g.getTimesProcessed()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/CurrencyFormatterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | 30 | import java.math.BigInteger; 31 | 32 | import eu.manabreak.libclicker.formatting.Formatter; 33 | 34 | import static org.junit.Assert.assertEquals; 35 | 36 | public class CurrencyFormatterTest { 37 | World w; 38 | Currency c; 39 | Formatter cf; 40 | 41 | @Before 42 | public void setUp() { 43 | w = new World(); 44 | c = new Currency.Builder(w).name("Gold").build(); 45 | cf = null; 46 | } 47 | 48 | @After 49 | public void tearDown() { 50 | w = null; 51 | c = null; 52 | cf = null; 53 | } 54 | 55 | @Test 56 | public void testDigitGrouping() { 57 | System.out.println("toString()"); 58 | 59 | // Test the 60 | cf = new Formatter.ForCurrency(c) 61 | .groupDigits() 62 | .showFully() 63 | .build(); 64 | 65 | assertEquals("0", cf.toString()); 66 | 67 | c.set(new BigInteger("1")); 68 | assertEquals("1", cf.toString()); 69 | 70 | c.set(new BigInteger("12")); 71 | assertEquals("12", cf.toString()); 72 | 73 | c.set(new BigInteger("123")); 74 | assertEquals("123", cf.toString()); 75 | 76 | c.set(new BigInteger("1234")); 77 | assertEquals("1,234", cf.toString()); 78 | 79 | c.set(new BigInteger("12345")); 80 | assertEquals("12,345", cf.toString()); 81 | 82 | c.set(new BigInteger("123456")); 83 | assertEquals("123,456", cf.toString()); 84 | 85 | c.set(new BigInteger("1234567")); 86 | assertEquals("1,234,567", cf.toString()); 87 | 88 | c.set(new BigInteger("12345678")); 89 | assertEquals("12,345,678", cf.toString()); 90 | } 91 | 92 | @Test 93 | public void testRaw() throws Exception { 94 | cf = new Formatter.ForCurrency(c) 95 | .dontGroupDigits() 96 | .showFully() 97 | .build(); 98 | 99 | assertEquals("0", cf.toString()); 100 | 101 | c.set(new BigInteger("1")); 102 | assertEquals("1", cf.toString()); 103 | 104 | c.set(new BigInteger("12")); 105 | assertEquals("12", cf.toString()); 106 | 107 | c.set(new BigInteger("123")); 108 | assertEquals("123", cf.toString()); 109 | 110 | c.set(new BigInteger("1234")); 111 | assertEquals("1234", cf.toString()); 112 | 113 | c.set(new BigInteger("12345")); 114 | assertEquals("12345", cf.toString()); 115 | 116 | c.set(new BigInteger("123456")); 117 | assertEquals("123456", cf.toString()); 118 | 119 | c.set(new BigInteger("1234567")); 120 | assertEquals("1234567", cf.toString()); 121 | 122 | c.set(new BigInteger("12345678")); 123 | assertEquals("12345678", cf.toString()); 124 | } 125 | 126 | @Test 127 | public void testCutAtHighestWithDecimals() throws Exception { 128 | cf = new Formatter.ForCurrency(c) 129 | .showHighestThousand() 130 | .showDecimals(2, ".") 131 | .build(); 132 | 133 | assertEquals("0", cf.toString()); 134 | 135 | c.set(new BigInteger("1")); 136 | assertEquals("1", cf.toString()); 137 | 138 | c.set(new BigInteger("123")); 139 | assertEquals("123", cf.toString()); 140 | 141 | c.set(new BigInteger("1234")); 142 | assertEquals("1.23", cf.toString()); 143 | 144 | c.set(new BigInteger("12345")); 145 | assertEquals("12.34", cf.toString()); 146 | 147 | c.set(new BigInteger("123456")); 148 | assertEquals("123.45", cf.toString()); 149 | 150 | c.set(new BigInteger("1234567")); 151 | assertEquals("1.23", cf.toString()); 152 | } 153 | 154 | @Test 155 | public void testCutAtHighestNoDecimals() throws Exception { 156 | cf = new Formatter.ForCurrency(c) 157 | .showHighestThousand() 158 | .dontShowDecimals() 159 | .build(); 160 | 161 | assertEquals("0", cf.toString()); 162 | 163 | c.set(new BigInteger("1")); 164 | assertEquals("1", cf.toString()); 165 | 166 | c.set(new BigInteger("12")); 167 | assertEquals("12", cf.toString()); 168 | 169 | c.set(new BigInteger("123")); 170 | assertEquals("123", cf.toString()); 171 | 172 | c.set(new BigInteger("1234")); 173 | assertEquals("1", cf.toString()); 174 | 175 | c.set(new BigInteger("5432")); 176 | assertEquals("5", cf.toString()); 177 | 178 | c.set(new BigInteger("54321")); 179 | assertEquals("54", cf.toString()); 180 | 181 | c.set(new BigInteger("123456")); 182 | assertEquals("123", cf.toString()); 183 | 184 | c.set(new BigInteger("98712345")); 185 | assertEquals("98", cf.toString()); 186 | } 187 | 188 | @Test 189 | public void testSeparators() throws Exception { 190 | cf = new Formatter.ForCurrency(c) 191 | .groupDigits() 192 | .showFully() 193 | .build(); 194 | 195 | // Default thousands separator ',' 196 | c.set(new BigInteger("123456789")); 197 | assertEquals("123,456,789", cf.toString()); 198 | 199 | // Set a single space as thousands separator 200 | cf = new Formatter.ForCurrency(c) 201 | .groupDigits(" ") 202 | .showFully() 203 | .build(); 204 | assertEquals("123 456 789", cf.toString()); 205 | 206 | // Default decimal separator '.' 207 | cf = new Formatter.ForCurrency(c) 208 | .showDecimals() 209 | .showHighestThousand() 210 | .build(); 211 | assertEquals("123.45", cf.toString()); 212 | 213 | // Custom separator '#' 214 | cf = new Formatter.ForCurrency(c) 215 | .showDecimals("#") 216 | .showHighestThousand() 217 | .build(); 218 | assertEquals("123#45", cf.toString()); 219 | 220 | // Show more decimals 221 | cf = new Formatter.ForCurrency(c) 222 | .showDecimals(3) 223 | .showHighestThousand() 224 | .build(); 225 | assertEquals("123.456", cf.toString()); 226 | 227 | // Show just one decimal 228 | cf = new Formatter.ForCurrency(c) 229 | .showDecimals(1) 230 | .showHighestThousand() 231 | .build(); 232 | assertEquals("123.4", cf.toString()); 233 | 234 | } 235 | 236 | @Test 237 | public void testNames() { 238 | cf = new Formatter.ForCurrency(c) 239 | .showDecimals(2) 240 | .showHighestThousand() 241 | .useAbbreviations(new String[]{"K", "M", "B", "T", "aa"}) 242 | .build(); 243 | 244 | c.set(new BigInteger("123")); 245 | assertEquals("123", cf.toString()); 246 | 247 | c.set(new BigInteger("1234")); 248 | assertEquals("1.23K", cf.toString()); 249 | 250 | c.set(new BigInteger("12345")); 251 | assertEquals("12.34K", cf.toString()); 252 | 253 | c.set(new BigInteger("123456")); 254 | assertEquals("123.45K", cf.toString()); 255 | 256 | c.set(new BigInteger("1234567")); 257 | assertEquals("1.23M", cf.toString()); 258 | 259 | c.set(new BigInteger("12345678")); 260 | assertEquals("12.34M", cf.toString()); 261 | 262 | c.set(new BigInteger("123456789")); 263 | assertEquals("123.45M", cf.toString()); 264 | 265 | c.set(new BigInteger("1234567890")); 266 | assertEquals("1.23B", cf.toString()); 267 | 268 | c.set(new BigInteger("12312312312")); 269 | assertEquals("12.31B", cf.toString()); 270 | 271 | c.set(new BigInteger("123123123123")); 272 | assertEquals("123.12B", cf.toString()); 273 | 274 | c.set(new BigInteger("1231231231231")); 275 | assertEquals("1.23T", cf.toString()); 276 | 277 | c.set(new BigInteger("12312312312312")); 278 | assertEquals("12.31T", cf.toString()); 279 | 280 | c.set(new BigInteger("123123123123123")); 281 | assertEquals("123.12T", cf.toString()); 282 | 283 | c.set(new BigInteger("1231231231231231")); 284 | assertEquals("1.23aa", cf.toString()); 285 | 286 | c.set(new BigInteger("12312312312312312")); 287 | assertEquals("12.31aa", cf.toString()); 288 | 289 | c.set(new BigInteger("123123123123123123")); 290 | assertEquals("123.12aa", cf.toString()); 291 | 292 | c.set(new BigInteger("1231231231231231231")); 293 | assertEquals("1.23", cf.toString()); 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/CurrencyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | import java.math.BigInteger; 29 | 30 | import static org.junit.Assert.assertEquals; 31 | 32 | public class CurrencyTest { 33 | 34 | @Test 35 | public void testGetName() { 36 | World world = new World(); 37 | System.out.println("getName()"); 38 | Currency instance = new Currency.Builder(world).name("TestCurrency").build(); 39 | String expResult = "TestCurrency"; 40 | String result = instance.getName(); 41 | assertEquals(expResult, result); 42 | } 43 | 44 | @Test 45 | public void testArithmetic() { 46 | World world = new World(); 47 | 48 | System.out.println("testArithmetic()"); 49 | Currency c = new Currency.Builder(world).build(); 50 | assertEquals(BigInteger.ZERO, c.getValue()); 51 | 52 | c.generate(new BigInteger("1")); 53 | assertEquals(BigInteger.ONE, c.getValue()); 54 | 55 | c.generate(new BigInteger("12344")); 56 | assertEquals(new BigInteger("12345"), c.getValue()); 57 | 58 | c.sub(new BigInteger("300")); 59 | assertEquals(new BigInteger("12045"), c.getValue()); 60 | 61 | c.set(new BigInteger("100")); 62 | assertEquals(new BigInteger("100"), c.getValue()); 63 | 64 | c.multiply(2.0); 65 | assertEquals(new BigInteger("200"), c.getValue()); 66 | 67 | c.multiply(1.145); 68 | int targetVal = (int) (1.145 * 200); 69 | assertEquals(new BigInteger("" + targetVal), c.getValue()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/GeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | import java.math.BigInteger; 29 | 30 | import eu.manabreak.libclicker.formatting.Formatter; 31 | import eu.manabreak.libclicker.generators.Generator; 32 | 33 | import static org.junit.Assert.assertEquals; 34 | 35 | public class GeneratorTest { 36 | 37 | @Test 38 | public void testGeneration() throws Exception { 39 | World w = new World(); 40 | Currency c = new Currency.Builder(w).name("Gold").build(); 41 | 42 | Formatter cf = new Formatter.ForCurrency(c) 43 | .showHighestThousand() 44 | .showDecimals() 45 | .build(); 46 | 47 | Generator g = new Generator.Builder(w) 48 | .baseAmount(100) 49 | .multiplier(1.2) 50 | .generate(c) 51 | .build(); 52 | 53 | assertEquals(BigInteger.ZERO, g.getGeneratedAmount()); 54 | g.process(); 55 | assertEquals(BigInteger.ZERO, c.getValue()); 56 | 57 | g.upgrade(); 58 | assertEquals(new BigInteger("" + 100), g.getGeneratedAmount()); 59 | g.process(); 60 | assertEquals(new BigInteger("" + 100), c.getValue()); 61 | 62 | BigInteger amount = g.getGeneratedAmount(); 63 | g.upgrade(); 64 | g.process(); 65 | amount = amount.add(g.getGeneratedAmount()); 66 | // assertEquals(amount, c.getValue()); 67 | assertEquals(amount, c.getValue()); 68 | } 69 | 70 | @Test 71 | public void testRemainderUsage() throws Exception { 72 | World w = new World(); 73 | 74 | Currency c = new Currency.Builder(w) 75 | .name("Gold") 76 | .build(); 77 | 78 | Generator g = new Generator.Builder(w) 79 | .baseAmount(1) 80 | .multiplier(1.2) 81 | .useRemainder() 82 | .generate(c) 83 | .build(); 84 | 85 | // Set to level 2 86 | g.setItemLevel(2); 87 | 88 | assertEquals(BigInteger.ZERO, c.getValue()); 89 | 90 | g.process(); 91 | assertEquals(new BigInteger("1"), c.getValue()); 92 | 93 | g.process(); 94 | assertEquals(new BigInteger("2"), c.getValue()); 95 | 96 | g.process(); 97 | assertEquals(new BigInteger("3"), c.getValue()); 98 | 99 | g.process(); 100 | assertEquals(new BigInteger("4"), c.getValue()); 101 | 102 | g.process(); 103 | assertEquals(new BigInteger("6"), c.getValue()); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/ItemTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | import java.math.BigInteger; 29 | 30 | import eu.manabreak.libclicker.generators.Generator; 31 | 32 | import static org.junit.Assert.assertEquals; 33 | 34 | public class ItemTest { 35 | 36 | @Test 37 | public void testName() { 38 | Item item = new ItemImpl(); 39 | item.setName("Test"); 40 | assertEquals("Test", item.getName()); 41 | } 42 | 43 | @Test 44 | public void testDescription() { 45 | Item item = new ItemImpl(); 46 | item.setDescription("Description text here."); 47 | assertEquals("Description text here.", item.getDescription()); 48 | } 49 | 50 | @Test 51 | public void testBasePrice() { 52 | Item item = new ItemImpl(); 53 | item.setBasePrice(10); 54 | assertEquals(new BigInteger("10"), item.getBasePrice()); 55 | } 56 | 57 | @Test 58 | public void testPrice() { 59 | Item item = new ItemImpl(); 60 | 61 | item.setBasePrice(10); 62 | item.setPriceMultiplier(1.5); 63 | 64 | assertEquals(new BigInteger("10"), item.getPrice()); 65 | 66 | item.upgrade(); 67 | 68 | assertEquals(new BigInteger("15"), item.getPrice()); 69 | } 70 | 71 | @Test 72 | public void testPurchase() { 73 | World world = new World(); 74 | Currency c = new Currency.Builder(world) 75 | .name("Gold") 76 | .build(); 77 | 78 | Generator g = new Generator.Builder(world) 79 | .baseAmount(1000) 80 | .price(500) 81 | .generate(c) 82 | .build(); 83 | 84 | assertEquals(BigInteger.ZERO, c.getValue()); 85 | 86 | PurchaseResult pr = g.buyWith(c); 87 | assertEquals(PurchaseResult.INSUFFICIENT_FUNDS, pr); 88 | 89 | g.upgrade(); 90 | g.process(); 91 | 92 | assertEquals(1, g.getItemLevel()); 93 | 94 | pr = g.buyWith(c); 95 | assertEquals(PurchaseResult.OK, pr); 96 | assertEquals(2, g.getItemLevel()); 97 | 98 | g.setMaxItemLevel(2); 99 | 100 | g.process(); 101 | pr = g.buyWith(c); 102 | assertEquals(PurchaseResult.MAX_LEVEL_REACHED, pr); 103 | assertEquals(2, g.getItemLevel()); 104 | } 105 | 106 | @Test 107 | public void testSetBasePrice_BigInteger() { 108 | Item item = new ItemImpl(); 109 | item.setBasePrice(new BigInteger("1234")); 110 | assertEquals(new BigInteger("1234"), item.getBasePrice()); 111 | } 112 | 113 | @Test 114 | public void testSetBasePrice_long() { 115 | Item item = new ItemImpl(); 116 | long price = 1234; 117 | item.setBasePrice(1234); 118 | assertEquals(new BigInteger("1234"), item.getBasePrice()); 119 | } 120 | 121 | @Test 122 | public void testSetBasePrice_int() { 123 | Item item = new ItemImpl(); 124 | int price = 1234; 125 | item.setBasePrice(1234); 126 | assertEquals(new BigInteger("1234"), item.getBasePrice()); 127 | } 128 | 129 | @Test 130 | public void testPriceMultiplier() { 131 | Item item = new ItemImpl(); 132 | item.setPriceMultiplier(1.23); 133 | assertEquals(1.23, item.getPriceMultiplier(), 0.001); 134 | 135 | } 136 | 137 | @Test 138 | public void testMaxItemLevel() { 139 | Item item = new ItemImpl(); 140 | item.setMaxItemLevel(12); 141 | 142 | // Try to set the level greater than max level 143 | item.setItemLevel(14); 144 | assertEquals(12, item.getItemLevel()); 145 | 146 | item.setItemLevel(5); 147 | assertEquals(5, item.getItemLevel()); 148 | 149 | item.setItemLevel(12); 150 | assertEquals(12, item.getItemLevel()); 151 | 152 | item.upgrade(); 153 | assertEquals(12, item.getItemLevel()); 154 | 155 | item.setMaxItemLevel(13); 156 | assertEquals(12, item.getItemLevel()); 157 | 158 | item.upgrade(); 159 | assertEquals(13, item.getItemLevel()); 160 | } 161 | 162 | @Test 163 | public void testUpgradeDowngradeMaximize() { 164 | Item item = new ItemImpl(); 165 | assertEquals(0, item.getItemLevel()); 166 | item.upgrade(); 167 | assertEquals(1, item.getItemLevel()); 168 | item.upgrade(); 169 | assertEquals(2, item.getItemLevel()); 170 | item.downgrade(); 171 | assertEquals(1, item.getItemLevel()); 172 | item.downgrade(); 173 | assertEquals(0, item.getItemLevel()); 174 | item.downgrade(); 175 | assertEquals(0, item.getItemLevel()); 176 | 177 | item.setMaxItemLevel(10); 178 | item.maximize(); 179 | assertEquals(item.getMaxItemLevel(), item.getItemLevel()); 180 | } 181 | 182 | public class ItemImpl extends Item { 183 | 184 | public ItemImpl() { 185 | super(null); 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/ModifierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri Pellikka. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | import java.math.BigInteger; 29 | 30 | import eu.manabreak.libclicker.generators.Generator; 31 | import eu.manabreak.libclicker.modifiers.Modifier; 32 | 33 | import static org.junit.Assert.assertEquals; 34 | import static org.junit.Assert.assertFalse; 35 | import static org.junit.Assert.assertTrue; 36 | 37 | public class ModifierTest { 38 | 39 | @Test 40 | public void testSingleWorldSpeedModifier() { 41 | System.out.println("testWorldModifier()"); 42 | World w = new World(); 43 | assertEquals(1.0, w.getSpeedMultiplier(), 0.01); 44 | 45 | Modifier m = new Modifier.Builder() 46 | .modify(w) 47 | .speedBy(2.0) 48 | .build(); 49 | 50 | m.enable(); 51 | 52 | assertEquals(1.0 * 2.0, w.getSpeedMultiplier(), 0.01); 53 | 54 | m.disable(); 55 | 56 | assertEquals(1.0, w.getSpeedMultiplier(), 0.01); 57 | } 58 | 59 | @Test 60 | public void testMultipleWorldSpeedModifiers() { 61 | System.out.println("test multiple speed by"); 62 | World w = new World(); 63 | 64 | Modifier m = new Modifier.Builder() 65 | .modify(w) 66 | .speedBy(2.0) 67 | .build(); 68 | 69 | Modifier m2 = new Modifier.Builder() 70 | .modify(w) 71 | .speedBy(3.0) 72 | .build(); 73 | 74 | m.enable(); 75 | m2.enable(); 76 | 77 | assertEquals(1.0 * 2.0 * 3.0, w.getSpeedMultiplier(), 0.01); 78 | 79 | m.disable(); 80 | 81 | assertEquals(1.0 * 3.0, w.getSpeedMultiplier(), 0.01); 82 | 83 | m2.disable(); 84 | 85 | assertEquals(1.0, w.getSpeedMultiplier(), 0.01); 86 | } 87 | 88 | @Test 89 | public void testDisableAllAutomators() { 90 | World w = new World(); 91 | 92 | Currency c = new Currency.Builder(w) 93 | .name("Gold") 94 | .build(); 95 | 96 | Generator g = new Generator.Builder(w) 97 | .generate(c) 98 | .baseAmount(1) 99 | .build(); 100 | g.upgrade(); 101 | 102 | Automator a = new Automator.Builder(w) 103 | .automate(g) 104 | .every(1.0) 105 | .build(); 106 | a.upgrade(); 107 | 108 | assertEquals(BigInteger.ZERO, c.getValue()); 109 | 110 | w.update(10.0); 111 | 112 | assertEquals(new BigInteger("10"), c.getValue()); 113 | 114 | Modifier m = new Modifier.Builder() 115 | .modify(w) 116 | .disableActivators() 117 | .build(); 118 | 119 | m.enable(); 120 | 121 | w.update(10.0); 122 | 123 | assertEquals(new BigInteger("10"), c.getValue()); 124 | 125 | m.disable(); 126 | 127 | w.update(10.0); 128 | 129 | assertEquals(new BigInteger("20"), c.getValue()); 130 | } 131 | 132 | @Test 133 | public void testSpeedGenerators() { 134 | World w = new World(); 135 | Currency c = new Currency.Builder(w) 136 | .name("Gold") 137 | .build(); 138 | 139 | Generator g = new Generator.Builder(w) 140 | .baseAmount(1) 141 | .generate(c) 142 | .build(); 143 | g.upgrade(); 144 | 145 | g.process(); 146 | 147 | assertEquals(BigInteger.ONE, c.getValue()); 148 | 149 | Modifier m = new Modifier.Builder() 150 | .modify(w, g) 151 | .multiplier(2.0) 152 | .build(); 153 | m.enable(); 154 | 155 | g.process(); 156 | assertEquals(new BigInteger("3"), c.getValue()); 157 | 158 | m.disable(); 159 | g.process(); 160 | assertEquals(new BigInteger("4"), c.getValue()); 161 | } 162 | 163 | @Test 164 | public void testIsEnabled() { 165 | System.out.println("isEnabled"); 166 | 167 | World w = new World(); 168 | 169 | Modifier m = new Modifier.Builder() 170 | .modify(w) 171 | .build(); 172 | 173 | assertFalse(m.isEnabled()); 174 | m.enable(); 175 | assertTrue(m.isEnabled()); 176 | m.disable(); 177 | assertFalse(m.isEnabled()); 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/NumberFormatterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | public class NumberFormatterTest { 29 | 30 | public NumberFormatterTest() { 31 | } 32 | 33 | @Test 34 | public void testBigIntegerFormatting() { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libclicker/src/test/java/eu/manabreak/libclicker/SerializationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Harri. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | 28 | import java.io.ByteArrayInputStream; 29 | import java.io.ByteArrayOutputStream; 30 | import java.io.IOException; 31 | import java.io.ObjectInputStream; 32 | import java.io.ObjectOutputStream; 33 | import java.math.BigInteger; 34 | 35 | import eu.manabreak.libclicker.generators.Generator; 36 | import eu.manabreak.libclicker.modifiers.Modifier; 37 | 38 | import static org.junit.Assert.assertEquals; 39 | 40 | public class SerializationTest { 41 | 42 | @Test 43 | public void testSerialization() throws IOException, ClassNotFoundException { 44 | String currencyName = "Serialized Gold"; 45 | String generatorName = "Serialized Gold Generator"; 46 | int genBaseAmount = 1234; 47 | double genMultiplier = 1.34; 48 | int genMaxLevel = 42; 49 | int genLevel = 13; 50 | 51 | World world = new World(); 52 | Currency gold = new Currency.Builder(world) 53 | .name(currencyName) 54 | .build(); 55 | 56 | Generator gen = new Generator.Builder(world) 57 | .baseAmount(genBaseAmount) 58 | .multiplier(genMultiplier) 59 | .maxLevel(genMaxLevel) 60 | .generate(gold) 61 | .build(); 62 | 63 | for (int i = 0; i < genLevel; ++i) { 64 | gen.upgrade(); 65 | } 66 | 67 | Automator a = new Automator.Builder(world) 68 | .automate(gen) 69 | .every(2.3) 70 | .build(); 71 | 72 | gen.process(); 73 | 74 | Modifier mWorld = new Modifier.Builder() 75 | .modify(world) 76 | .disableActivators() 77 | .speedBy(3.5) 78 | .build(); 79 | mWorld.enable(); 80 | 81 | Modifier mGen = new Modifier.Builder() 82 | .modify(world, gen) 83 | .multiplier(4.2) 84 | .build(); 85 | mGen.enable(); 86 | 87 | BigInteger goldBeforeSerialization = gold.getValue(); 88 | 89 | /* SERIALIZATION */ 90 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 91 | ObjectOutputStream oos = new ObjectOutputStream(bos); 92 | oos.writeObject(world); 93 | 94 | byte[] bytes = bos.toByteArray(); 95 | oos.close(); 96 | 97 | /* DESERIALIZATION */ 98 | ByteArrayInputStream bis = new ByteArrayInputStream(bytes); 99 | ObjectInputStream ois = new ObjectInputStream(bis); 100 | World newWorld = (World) ois.readObject(); 101 | 102 | assertEquals(world.getGeneratorCount(), newWorld.getGeneratorCount()); 103 | assertEquals(world.getCurrencies().size(), newWorld.getCurrencies().size()); 104 | assertEquals(world.getAutomators().size(), newWorld.getAutomators().size()); 105 | assertEquals(world.getModifiers().size(), newWorld.getModifiers().size()); 106 | assertEquals(world.getSpeedMultiplier(), newWorld.getSpeedMultiplier(), 0.001); 107 | assertEquals(world.isAutomationEnabled(), newWorld.isAutomationEnabled()); 108 | 109 | for (int i = 0; i < world.getCurrencies().size(); ++i) { 110 | assertEquals(world.getCurrency(i).getName(), newWorld.getCurrency(i).getName()); 111 | assertEquals(world.getCurrency(i).getValue(), newWorld.getCurrency(i).getValue()); 112 | } 113 | 114 | for (int i = 0; i < world.getAutomators().size(); ++i) { 115 | Automator a0 = world.getAutomators().get(i); 116 | Automator a1 = newWorld.getAutomators().get(i); 117 | assertEquals(a0.getBasePrice(), a1.getBasePrice()); 118 | assertEquals(a0.getDescription(), a1.getDescription()); 119 | assertEquals(a0.getItemLevel(), a1.getItemLevel()); 120 | assertEquals(a0.getMaxItemLevel(), a1.getMaxItemLevel()); 121 | assertEquals(a0.getName(), a1.getName()); 122 | assertEquals(a0.getPrice(), a1.getPrice()); 123 | assertEquals(a0.getPriceMultiplier(), a1.getPriceMultiplier(), 0.001); 124 | assertEquals(a0.getTickRate(), a1.getTickRate(), 0.001); 125 | assertEquals(a0.getTimerPercentage(), a1.getTimerPercentage(), 0.001); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':libclicker' 2 | --------------------------------------------------------------------------------