├── .gitignore ├── LICENSE ├── README.md ├── build.xml ├── build └── built-jar.properties ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── private │ ├── config.properties │ ├── private.properties │ └── private.xml ├── project.properties └── project.xml ├── src └── com │ └── manabreak │ └── libclicker │ ├── Automator.java │ ├── Currency.java │ ├── Formatter.java │ ├── Generator.java │ ├── Item.java │ ├── Modifier.java │ ├── PurchaseResult.java │ └── World.java └── test └── com └── manabreak └── libclicker ├── AutomatorTest.java ├── CurrencyFormatterTest.java ├── CurrencyTest.java ├── GeneratorTest.java ├── ItemTest.java ├── ModifierTest.java ├── NumberFormatterTest.java ├── SerializationTest.java └── WorldTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | /build/ 14 | /dist/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 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 | 23 | -------------------------------------------------------------------------------- /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 | ## Usage 7 | 8 | Here's a basic introduction on how to use libclicker. 9 | 10 | ### World 11 | 12 | First off, you will need a `World` container for all your objects. 13 | A `World` object will keep track of the generators, automators and other 14 | items. 15 | 16 | ```java 17 | World world = new World(); 18 | ``` 19 | 20 | To update the world as your game progresses, call the `update()` method 21 | with your frame time as the parameter: 22 | 23 | ```java 24 | // Advance the world by 1/60th of a seconds, or 60 times per second 25 | world.update(1.0 / 60.0); 26 | ``` 27 | ### Currencies 28 | 29 | Quite often, procedural games have some sort of resources (gold, cookies etc.). 30 | To declare a new currency, you can use a `Currency.Builder`: 31 | 32 | ```java 33 | // Creates a new currency called "Gold" 34 | Currency gold = new Currency.Builder(world) 35 | .name("Gold") 36 | .build(); 37 | ``` 38 | 39 | The whole system will only have one instance of a currency at a time. The 40 | currency object will keep track of how much of the said currency has been 41 | generated. 42 | 43 | ### Generators 44 | 45 | To produce a currency, you have to create a generator. Again, like currencies, 46 | this happens through a Builder class: 47 | 48 | ```java 49 | // Creates a generator that creates gold 50 | Generator goldMine = new Generator.Builder(world) 51 | .generate(gold) // Generate gold 52 | .baseAmount(10) // Defaults to 10 gold per tick 53 | .multiplier(1.15) // Increase amount by 15 % per level 54 | .price(100) // Price of level 1 gold mine 55 | .priceMultiplier(1.25) // Increase price by 25 % per level 56 | .build(); 57 | 58 | // Manually generate some gold 59 | goldMine.process(); 60 | ``` 61 | 62 | Do note that generators start at level 0, producing nothing. To activate the 63 | generator, "upgrade" it to level one to produce the base amount: 64 | 65 | ```java 66 | // Upgrade the gold mine to level 1 67 | goldMine.upgrade(); 68 | ``` 69 | 70 | ### Automators 71 | 72 | Commonly generators can be automated in clicker games. To automate the gold mine 73 | from the previous example: 74 | 75 | ```java 76 | // Create a "gold digger" to automatically dig gold 77 | Automator goldDigger = new Automator.Builder(world) 78 | .automate(goldMine) 79 | .every(3.0) // Tick every three seconds 80 | .build(); 81 | 82 | // Advance the world by 30 seconds to make the automator work 83 | world.update(30.0); 84 | ``` 85 | 86 | ### Modifiers 87 | 88 | Yet another common thing found in procedural games is the use of upgrades, bonuses 89 | or other modifiers that change the outcome of the system in some way. Modifiers 90 | are supported in libclicker and can be applied to any other elements, modifying 91 | just about any of their properties (at least in the near future). 92 | 93 | The usage of modifiers follows the same pattern: 94 | 95 | ```java 96 | // World to modify 97 | World w = new World(); 98 | 99 | // Modify the world by creating a "double speed bonus" modifiers 100 | Modifier m = new Modifier.Builder() 101 | .modify(w) 102 | .speedBy(2.0) 103 | .build(); 104 | 105 | // By enabling the modifier, the speed bonus turns on 106 | m.enable(); 107 | 108 | // World is now actually advanced by 20 seconds instead of 10 109 | w.update(10.0); 110 | 111 | // Let's disable the modifier ("back to normal") 112 | m.disable(); 113 | 114 | // Back to normal 10-second updates 115 | w.update(10.0); 116 | ``` 117 | 118 | Note that multiple modifiers can be stacked: 119 | 120 | ```java 121 | // Double speed bonus 122 | Modifier m1 = new Modifier.Builder() 123 | .modify(w) 124 | .speedBy(2.0) 125 | .build(); 126 | 127 | // Triple speed bonus 128 | Modifier m2 = new Modifier.Builder() 129 | .modify(w) 130 | .speedBy(3.0) 131 | .build(); 132 | 133 | // Enable both bonuses, result is 6X speed bonus 134 | m1.enable(); 135 | m2.enable(); 136 | 137 | // World advances 6 seconds now, instead of 1 138 | w.update(1.0); 139 | 140 | // You can disable a single modifier and leave the other on 141 | m1.disable(); 142 | 143 | // Only the triple bonus is now enabled --> 3 seconds advancement 144 | w.update(1.0); 145 | ``` 146 | 147 | The modifier support is still pretty small, but more modifiers and 148 | modifiable properties will be available in the near future. 149 | 150 | ### Purchasing items 151 | 152 | Every item starts from level 0, meaning they don't "do" anything. 153 | You can query the price of an item by calling its `getPrice()` method: 154 | 155 | ```java 156 | Item item = ...; 157 | 158 | // Query the price of the NEXT level of the item 159 | BigInteger price = item.getPrice(); 160 | ``` 161 | 162 | To upgrade an item with currency, call the item's `buyWith()` method: 163 | 164 | ```java 165 | Currency gold = ...; 166 | Item item = ...; 167 | 168 | PurchaseResult result = item.buyWith(gold); 169 | ``` 170 | 171 | The returned `PurchaseResult` is an enum denoting the result. The 172 | possible out outcomes are: 173 | 174 | - `PurchaseResult.OK` when the item was successfully purchased or upgraded and the money was deducted 175 | 176 | - `PurchaseResult.INSUFFICIENT_FUNDS` when there was not enough money to buy the item 177 | 178 | - `PurchaseResult.MAX_LEVEL_REACHED` when the item has already reached its max level and cannot be upgraded any further 179 | 180 | ### Formatters 181 | 182 | You can query the amount of currency by calling its `getAmountAsString()` method, but 183 | this produces a rather ugly output that may not even fit on the screen. 184 | Instead, you can create a currency formatter to produce a nice output: 185 | 186 | ```java 187 | Formatter printGold = new Formatter.ForCurrency(gold) 188 | .groupDigits() // Group digits into groups of three 189 | .showHighestThousand() // Show only the highest triplet in the amount 190 | .showDecimals(2) // Show two decimals if "truncating" lower numbers 191 | .build(); 192 | 193 | // The formatter is now ready and prints out the current amount of gold 194 | System.out.println("Gold now: " + printGold); 195 | ``` 196 | 197 | In this example, if there's 123,456,789 gold, the output would be: 198 | 199 | ```java 200 | Gold now: 123.45 201 | ``` 202 | 203 | You usually want to use some indicators about the multitude of the currency (K for thousand, 204 | M for millions etc.). You can do this by supplying an array of "names" for each "thousand": 205 | 206 | ```java 207 | Formatter printGold = new Formatter.ForCurrency(gold) 208 | .groupDigits() 209 | .showHighestThousand() 210 | .showDecimals(2) 211 | .useAbbreviations(new String[] {"K", "M", "B", "T"}) 212 | .build(); 213 | 214 | System.out.println("Gold now: " + printGold); 215 | ``` 216 | 217 | In this case, if there's 123,456,789 gold, the output would be: 218 | 219 | ```java 220 | Gold now: 123.45M 221 | ``` 222 | 223 | If the amount of currency is higher than the amount of abbreviations supplied, 224 | the abbreviation will be omitted. Similarly, if the amount is less than 1,000, 225 | no abbreviation will be added. 226 | 227 | You can also format other things, e.g. the price of an item: 228 | 229 | ```java 230 | Formatter printItemPrice = new Formatter.ForItemPrice(item) 231 | .build(); 232 | ``` -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Builds, tests, and runs the project libclicker. 12 | 13 | 73 | 74 | -------------------------------------------------------------------------------- /build/built-jar.properties: -------------------------------------------------------------------------------- 1 | #Wed, 04 Nov 2015 15:05:04 +0200 2 | 3 | 4 | E\:\\Koodit\\libclicker= 5 | -------------------------------------------------------------------------------- /nbproject/build-impl.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | Must set src.dir 227 | Must set test.src.dir 228 | Must set build.dir 229 | Must set dist.dir 230 | Must set build.classes.dir 231 | Must set dist.javadoc.dir 232 | Must set build.test.classes.dir 233 | Must set build.test.results.dir 234 | Must set build.classes.excludes 235 | Must set dist.jar 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | Must set javac.includes 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | No tests executed. 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | Must set JVM to use for profiling in profiler.info.jvm 716 | Must set profiler agent JVM arguments in profiler.info.jvmargs.agent 717 | 718 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | Must select some files in the IDE or set javac.includes 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | To run this application from the command line without Ant, try: 995 | 996 | java -jar "${dist.jar.resolved}" 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | Must select one file in the IDE or set run.class 1044 | 1045 | 1046 | 1047 | Must select one file in the IDE or set run.class 1048 | 1049 | 1050 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | Must select one file in the IDE or set debug.class 1075 | 1076 | 1077 | 1078 | 1079 | Must select one file in the IDE or set debug.class 1080 | 1081 | 1082 | 1083 | 1084 | Must set fix.includes 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1096 | 1099 | 1100 | This target only works when run from inside the NetBeans IDE. 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | Must select one file in the IDE or set profile.class 1110 | This target only works when run from inside the NetBeans IDE. 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | This target only works when run from inside the NetBeans IDE. 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | This target only works when run from inside the NetBeans IDE. 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | Must select one file in the IDE or set run.class 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | Must select some files in the IDE or set test.includes 1177 | 1178 | 1179 | 1180 | 1181 | Must select one file in the IDE or set run.class 1182 | 1183 | 1184 | 1185 | 1186 | Must select one file in the IDE or set applet.url 1187 | 1188 | 1189 | 1190 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | Must select some files in the IDE or set javac.includes 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 1288 | 1289 | Some tests failed; see details above. 1290 | 1291 | 1292 | 1293 | 1294 | 1295 | 1296 | 1297 | 1298 | Must select some files in the IDE or set test.includes 1299 | 1300 | 1301 | 1302 | Some tests failed; see details above. 1303 | 1304 | 1305 | 1306 | Must select some files in the IDE or set test.class 1307 | Must select some method in the IDE or set test.method 1308 | 1309 | 1310 | 1311 | Some tests failed; see details above. 1312 | 1313 | 1314 | 1319 | 1320 | Must select one file in the IDE or set test.class 1321 | 1322 | 1323 | 1324 | Must select one file in the IDE or set test.class 1325 | Must select some method in the IDE or set test.method 1326 | 1327 | 1328 | 1329 | 1330 | 1331 | 1332 | 1333 | 1334 | 1335 | 1336 | 1337 | 1342 | 1343 | Must select one file in the IDE or set applet.url 1344 | 1345 | 1346 | 1347 | 1348 | 1349 | 1350 | 1355 | 1356 | Must select one file in the IDE or set applet.url 1357 | 1358 | 1359 | 1360 | 1361 | 1362 | 1363 | 1364 | 1369 | 1370 | 1371 | 1372 | 1373 | 1374 | 1375 | 1376 | 1377 | 1378 | 1379 | 1380 | 1381 | 1382 | 1383 | 1384 | 1385 | 1386 | 1387 | 1388 | 1389 | 1390 | 1391 | 1392 | 1393 | 1394 | 1395 | 1396 | 1397 | 1398 | 1399 | 1400 | 1401 | 1402 | 1403 | 1404 | 1405 | 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=6931c472 2 | build.xml.script.CRC32=cc14b70d 3 | build.xml.stylesheet.CRC32=8064a381@1.75.2.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=6931c472 7 | nbproject/build-impl.xml.script.CRC32=1e2ff7d7 8 | nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 9 | -------------------------------------------------------------------------------- /nbproject/private/config.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manabreak/libclicker/a5f74b43c9993321d37bc9b298ce616fa88f46ff/nbproject/private/config.properties -------------------------------------------------------------------------------- /nbproject/private/private.properties: -------------------------------------------------------------------------------- 1 | compile.on.save=false 2 | do.depend=false 3 | do.jar=true 4 | javac.debug=true 5 | javadoc.preview=true 6 | user.properties.file=C:\\Users\\Harri\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties 7 | -------------------------------------------------------------------------------- /nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | file:/E:/Koodit/libclicker/test/com/manabreak/libclicker/GeneratorTest.java 7 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/CurrencyFormatter.java 8 | file:/E:/Koodit/libclicker/test/com/manabreak/libclicker/ModifierTest.java 9 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/Currency.java 10 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/Modifier.java 11 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/World.java 12 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/PurchaseResult.java 13 | file:/E:/Koodit/libclicker/test/com/manabreak/libclicker/SerializationTest.java 14 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/Automator.java 15 | file:/E:/Koodit/libclicker/test/com/manabreak/libclicker/CurrencyFormatterTest.java 16 | file:/E:/Koodit/libclicker/src/com/manabreak/libclicker/Generator.java 17 | file:/E:/Koodit/libclicker/test/com/manabreak/libclicker/WorldTest.java 18 | file:/E:/Koodit/libclicker/test/com/manabreak/libclicker/CurrencyTest.java 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=true 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.processors.list= 4 | annotation.processing.run.all.processors=true 5 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 6 | application.title=libclicker 7 | application.vendor=Harri 8 | build.classes.dir=${build.dir}/classes 9 | build.classes.excludes=**/*.java,**/*.form 10 | # This directory is removed when the project is cleaned: 11 | build.dir=build 12 | build.generated.dir=${build.dir}/generated 13 | build.generated.sources.dir=${build.dir}/generated-sources 14 | # Only compile against the classpath explicitly listed here: 15 | build.sysclasspath=ignore 16 | build.test.classes.dir=${build.dir}/test/classes 17 | build.test.results.dir=${build.dir}/test/results 18 | # Uncomment to specify the preferred debugger connection transport: 19 | #debug.transport=dt_socket 20 | debug.classpath=\ 21 | ${run.classpath} 22 | debug.test.classpath=\ 23 | ${run.test.classpath} 24 | # Files in build.classes.dir which should be excluded from distribution jar 25 | dist.archive.excludes= 26 | # This directory is removed when the project is cleaned: 27 | dist.dir=dist 28 | dist.jar=${dist.dir}/libclicker.jar 29 | dist.javadoc.dir=${dist.dir}/javadoc 30 | endorsed.classpath= 31 | excludes= 32 | includes=** 33 | jar.compress=false 34 | javac.classpath= 35 | # Space-separated list of extra javac options 36 | javac.compilerargs= 37 | javac.deprecation=false 38 | javac.processorpath=\ 39 | ${javac.classpath} 40 | javac.source=1.8 41 | javac.target=1.8 42 | javac.test.classpath=\ 43 | ${javac.classpath}:\ 44 | ${build.classes.dir}:\ 45 | ${libs.junit_4.classpath} 46 | javac.test.processorpath=\ 47 | ${javac.test.classpath} 48 | javadoc.additionalparam= 49 | javadoc.author=false 50 | javadoc.encoding=${source.encoding} 51 | javadoc.noindex=false 52 | javadoc.nonavbar=false 53 | javadoc.notree=false 54 | javadoc.private=false 55 | javadoc.splitindex=true 56 | javadoc.use=true 57 | javadoc.version=false 58 | javadoc.windowtitle= 59 | meta.inf.dir=${src.dir}/META-INF 60 | mkdist.disabled=true 61 | platform.active=default_platform 62 | project.license=mit 63 | run.classpath=\ 64 | ${javac.classpath}:\ 65 | ${build.classes.dir} 66 | # Space-separated list of JVM arguments used when running the project. 67 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. 68 | # To set system properties for unit tests define test-sys-prop.name=value: 69 | run.jvmargs= 70 | run.test.classpath=\ 71 | ${javac.test.classpath}:\ 72 | ${build.test.classes.dir} 73 | source.encoding=UTF-8 74 | src.dir=src 75 | test.src.dir=test 76 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | libclicker 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/com/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 com.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigInteger; 28 | 29 | /** 30 | * Automator class for automating generators. 31 | * 32 | * Normally generators are manually controlled, i.e. they generate resources 33 | * when explicitly told to. Automators are used to trigger generators 34 | * during the world's update cycles. 35 | * 36 | * @author Harri Pellikka 37 | */ 38 | public class Automator extends Item implements Serializable 39 | { 40 | private Generator mGenerator; 41 | private double mTickRate = 1.0; 42 | private double mTickTimer = 0.0; 43 | private double mMultiplier; 44 | private boolean mEnabled; 45 | private double mActualTickRate; 46 | 47 | public static class Builder 48 | { 49 | private final World mWorld; 50 | private Generator mGenerator; 51 | private double mTickRate = 1.0; 52 | private String mName = "Nameless automator"; 53 | private boolean mEnabled = true; 54 | private BigInteger mBasePrice = BigInteger.ONE; 55 | private double mPriceMultiplier = 1.1; 56 | private double mTickRateMultiplier = 1.08; 57 | 58 | /** 59 | * Constructs a new automator builder 60 | * @param world World the automator belongs to 61 | */ 62 | public Builder(World world) 63 | { 64 | mWorld = world; 65 | } 66 | 67 | /** 68 | * Constructs a new automator builder for the given generator 69 | * @param world World the automator belongs to 70 | * @param generator Generator to automate 71 | */ 72 | public Builder(World world, Generator generator) 73 | { 74 | mWorld = world; 75 | mGenerator = generator; 76 | } 77 | 78 | public Builder basePrice(int price) 79 | { 80 | mBasePrice = new BigInteger("" + price); 81 | return this; 82 | } 83 | 84 | public Builder basePrice(long price) 85 | { 86 | mBasePrice = new BigInteger("" + price); 87 | return this; 88 | } 89 | 90 | public Builder basePrice(BigInteger price) 91 | { 92 | mBasePrice = price; 93 | return this; 94 | } 95 | 96 | public Builder priceMultiplier(double multiplier) 97 | { 98 | mPriceMultiplier = multiplier; 99 | return this; 100 | } 101 | 102 | public Builder tickRateMultiplier(double multiplier) 103 | { 104 | mTickRateMultiplier = multiplier; 105 | return this; 106 | } 107 | 108 | /** 109 | * Sets the target generator this automator should automate. 110 | * 111 | * @param generator Generator to automate 112 | * @return This builder for chaining 113 | */ 114 | public Builder automate(Generator generator) 115 | { 116 | mGenerator = generator; 117 | return this; 118 | } 119 | 120 | /** 121 | * Sets the name for this automator. 122 | * 123 | * @param name Name 124 | * @return This builder for chaining 125 | */ 126 | public Builder name(String name) 127 | { 128 | mName = name; 129 | return this; 130 | } 131 | 132 | /** 133 | * Sets the tick rate of this automator, i.e. how often 134 | * this automator should do its business. 135 | * 136 | * @param seconds Tick rate in seconds 137 | * @return This builder for chaining 138 | */ 139 | public Builder every(double seconds) 140 | { 141 | mTickRate = seconds; 142 | return this; 143 | } 144 | 145 | /** 146 | * Constructs the automator based on the given properties. 147 | * @return The automator 148 | */ 149 | public Automator build() 150 | { 151 | if(mGenerator == null) throw new IllegalStateException("Generator cannot be null"); 152 | 153 | Automator a = new Automator(mWorld, mName); 154 | a.mGenerator = mGenerator; 155 | a.mTickRate = mTickRate; 156 | a.mEnabled = mEnabled; 157 | a.mBasePrice = mBasePrice; 158 | a.mPriceMultiplier = mPriceMultiplier; 159 | a.mMultiplier = mTickRateMultiplier; 160 | mWorld.addAutomator(a); 161 | return a; 162 | } 163 | } 164 | 165 | private Automator(World world, String name) 166 | { 167 | super(world, name); 168 | } 169 | 170 | /** 171 | * Enables this automator. Automators are enabled by default when 172 | * they are created. 173 | */ 174 | public void enable() 175 | { 176 | if(!mEnabled) 177 | { 178 | getWorld().addAutomator(this); 179 | mEnabled = true; 180 | } 181 | } 182 | 183 | /** 184 | * Disables this automator, effectively turning the automation off. 185 | */ 186 | public void disable() 187 | { 188 | if(mEnabled) 189 | { 190 | getWorld().removeAutomator(this); 191 | mEnabled = false; 192 | } 193 | } 194 | 195 | @Override 196 | public void upgrade() 197 | { 198 | super.upgrade(); //To change body of generated methods, choose Tools | Templates. 199 | mActualTickRate = getFinalTickRate(); 200 | System.out.println("Upgraded, final tick rate now: " + mActualTickRate); 201 | } 202 | 203 | private double getFinalTickRate() 204 | { 205 | if(mItemLevel == 0) return 0.0; 206 | double r = mTickRate; 207 | double m = Math.pow(mMultiplier, mItemLevel - 1); 208 | return r / m; 209 | } 210 | 211 | void update(double delta) 212 | { 213 | if(!mEnabled || mItemLevel == 0) return; 214 | 215 | mTickTimer += delta; 216 | while(mTickTimer >= mActualTickRate) 217 | { 218 | mTickTimer -= mActualTickRate; 219 | mGenerator.process(); 220 | } 221 | } 222 | 223 | /** 224 | * Retrieves the tick rate of this automator. 225 | * @return Tick rate in seconds 226 | */ 227 | public double getTickRate() 228 | { 229 | return mTickRate; 230 | } 231 | 232 | /** 233 | * Sets the tick rate of this automator. 234 | * 235 | * @param tickRate Tick rate in seconds 236 | */ 237 | public void setTickRate(double tickRate) 238 | { 239 | mTickRate = tickRate; 240 | if(mTickRate < 0.0) mTickRate = 0.0; 241 | } 242 | 243 | /** 244 | * Retrieves the percentage of the tick. Useful 245 | * when creating progress bars for generators. 246 | * 247 | * @return Percentage of tick completion 248 | */ 249 | public double getTimerPercentage() 250 | { 251 | return mTickRate != 0.0 ? mTickTimer / mTickRate : 1.0; 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /src/com/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 com.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigDecimal; 28 | import java.math.BigInteger; 29 | 30 | /** 31 | * Base class for all currencies. 32 | * 33 | * @author Harri Pellikka 34 | */ 35 | public class Currency implements Serializable 36 | { 37 | /** 38 | * Name of this currency 39 | */ 40 | private String mName; 41 | 42 | /** 43 | * Huge number to hold the amount for this currency 44 | */ 45 | private BigInteger mValue = BigInteger.ZERO; 46 | 47 | private final World mWorld; 48 | 49 | public static class Builder 50 | { 51 | private final World mWorld; 52 | private String mName = "Gold"; 53 | 54 | public Builder(World world) 55 | { 56 | mWorld = world; 57 | } 58 | 59 | public Builder name(String name) 60 | { 61 | mName = name; 62 | return this; 63 | } 64 | 65 | public Currency build() 66 | { 67 | Currency c = new Currency(mWorld, mName); 68 | mWorld.addCurrency(c); 69 | return c; 70 | } 71 | } 72 | 73 | /** 74 | * Constructs a new currency with initial amount of 0 75 | * @param name 76 | */ 77 | private Currency(World world, String name) 78 | { 79 | mWorld = world; 80 | mName = name; 81 | } 82 | 83 | /** 84 | * Retrieves the name of this currency 85 | * @return 86 | */ 87 | public String getName() 88 | { 89 | return mName; 90 | } 91 | 92 | public String getAmountAsString() 93 | { 94 | return mValue.toString(); 95 | } 96 | 97 | @Override 98 | public String toString() 99 | { 100 | return mName + ": " + getAmountAsString(); 101 | } 102 | 103 | BigInteger getValue() 104 | { 105 | return mValue; 106 | } 107 | 108 | public void add(BigInteger other) 109 | { 110 | mValue = mValue.add(other); 111 | } 112 | 113 | public void sub(BigInteger other) 114 | { 115 | mValue = mValue.subtract(other); 116 | } 117 | 118 | public void multiply(double multiplier) 119 | { 120 | BigDecimal tmp = new BigDecimal(mValue); 121 | tmp = tmp.multiply(new BigDecimal(multiplier)); 122 | mValue = tmp.toBigInteger(); 123 | } 124 | 125 | void set(BigInteger newValue) 126 | { 127 | mValue = newValue; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/com/manabreak/libclicker/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 com.manabreak.libclicker; 25 | 26 | /** 27 | * A formatter for BigInteger values. 28 | * 29 | * @author Harri Pellikka 30 | */ 31 | public class Formatter 32 | { 33 | /** 34 | * Formats a currency to a nice string representation. 35 | */ 36 | public static class CurrencyFormatter extends Formatter 37 | { 38 | private final Currency mCurrency; 39 | 40 | private CurrencyFormatter(Builder builder, Currency currency) 41 | { 42 | super(builder); 43 | mCurrency = currency; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | setRawString(mCurrency.getValue().toString()); 50 | return super.toString(); 51 | } 52 | } 53 | 54 | /** 55 | * Formats an item's price to a nice string representation. 56 | */ 57 | public static class ItemPriceFormatter extends Formatter 58 | { 59 | private final Item mItem; 60 | 61 | private ItemPriceFormatter(Builder builder, Item item) 62 | { 63 | super(builder); 64 | mItem = item; 65 | } 66 | 67 | @Override 68 | public String toString() 69 | { 70 | setRawString(mItem.getPrice().toString()); 71 | return super.toString(); 72 | } 73 | } 74 | 75 | protected final boolean mGroupDigits; 76 | protected final String mThousandSeparator; 77 | protected final boolean mShowDecimals; 78 | protected final int mDecimals; 79 | protected final String mDecimalSeparator; 80 | protected final boolean mCutAtHighest; 81 | protected final String[] mAbbreviations; 82 | 83 | protected Formatter(Builder builder) 84 | { 85 | mGroupDigits = builder.mGroupDigits; 86 | mThousandSeparator = builder.mThousandSeparator; 87 | mShowDecimals = builder.mShowDecimals; 88 | mDecimals = builder.mDecimals; 89 | mDecimalSeparator = builder.mDecimalSeparator; 90 | mCutAtHighest = builder.mCutAtHighest; 91 | mAbbreviations = builder.mAbbreviations; 92 | } 93 | 94 | public static class ForItemPrice extends Builder 95 | { 96 | private Item mItem; 97 | 98 | public ForItemPrice(Item item) 99 | { 100 | mItem = item; 101 | } 102 | 103 | @Override 104 | public ItemPriceFormatter build() 105 | { 106 | return new ItemPriceFormatter(this, mItem); 107 | } 108 | } 109 | 110 | public static class ForCurrency extends Builder 111 | { 112 | private Currency mCurrency; 113 | 114 | public ForCurrency(Currency c) 115 | { 116 | mCurrency = c; 117 | } 118 | 119 | public CurrencyFormatter build() 120 | { 121 | return new CurrencyFormatter(this, mCurrency); 122 | } 123 | } 124 | 125 | public static abstract class Builder 126 | { 127 | private boolean mGroupDigits = true; 128 | private String mThousandSeparator = ","; 129 | private boolean mShowDecimals = false; 130 | private int mDecimals = 2; 131 | private String mDecimalSeparator; 132 | private boolean mCutAtHighest = true; 133 | private String[] mAbbreviations = null; 134 | 135 | private Builder() 136 | { 137 | 138 | } 139 | 140 | public Builder showHighestThousand() 141 | { 142 | mCutAtHighest = true; 143 | return this; 144 | } 145 | 146 | public Builder showFully() 147 | { 148 | mCutAtHighest = false; 149 | return this; 150 | } 151 | 152 | public Builder groupDigits() 153 | { 154 | return groupDigits(","); 155 | } 156 | 157 | public Builder groupDigits(String separator) 158 | { 159 | mGroupDigits = true; 160 | mThousandSeparator = separator; 161 | return this; 162 | } 163 | 164 | public Builder dontGroupDigits() 165 | { 166 | mGroupDigits = false; 167 | mThousandSeparator = null; 168 | return this; 169 | } 170 | 171 | public Builder showDecimals() 172 | { 173 | return showDecimals(2, "."); 174 | } 175 | 176 | public Builder showDecimals(int count) 177 | { 178 | return showDecimals(count, "."); 179 | } 180 | 181 | public Builder showDecimals(String separator) 182 | { 183 | return showDecimals(2, separator); 184 | } 185 | 186 | public Builder showDecimals(int count, String separator) 187 | { 188 | mShowDecimals = true; 189 | mDecimals = count; 190 | mDecimalSeparator = separator; 191 | return this; 192 | } 193 | 194 | public Builder dontShowDecimals() 195 | { 196 | mShowDecimals = false; 197 | mDecimals = 0; 198 | mDecimalSeparator = null; 199 | return this; 200 | } 201 | 202 | public Builder useAbbreviations(String[] abbreviations) 203 | { 204 | mAbbreviations = abbreviations; 205 | return this; 206 | } 207 | 208 | public abstract Formatter build(); 209 | } 210 | 211 | 212 | 213 | private String mRawString = ""; 214 | 215 | public void setRawString(String raw) 216 | { 217 | mRawString = raw; 218 | if(mRawString == null) mRawString = ""; 219 | } 220 | 221 | @Override 222 | public String toString() 223 | { 224 | String raw = mRawString; 225 | if(mCutAtHighest) 226 | { 227 | int length = raw.length(); 228 | if(length < 4) return raw; 229 | int rem = length % 3; 230 | rem = rem == 0 ? 3 : rem; 231 | String top = raw.substring(0, rem); 232 | 233 | if(mShowDecimals) 234 | { 235 | top += mDecimalSeparator; 236 | int decimals = Math.min(mDecimals, length - rem); 237 | top += raw.substring(rem, rem + decimals); 238 | } 239 | 240 | if(mAbbreviations != null) 241 | { 242 | int tri = (raw.length() - 1) / 3; 243 | if(tri > 0 && tri <= mAbbreviations.length) 244 | { 245 | top += mAbbreviations[tri - 1]; 246 | } 247 | } 248 | 249 | return top; 250 | } 251 | else 252 | { 253 | if(mGroupDigits) 254 | { 255 | int len = raw.length() - 3; 256 | for(int i = len; i > 0; --i) 257 | { 258 | if((len - i) % 3 == 0) 259 | { 260 | raw = raw.substring(0, i) + mThousandSeparator + raw.substring(i); 261 | } 262 | } 263 | } 264 | return raw; 265 | } 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /src/com/manabreak/libclicker/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 com.manabreak.libclicker; 25 | 26 | import com.manabreak.libclicker.Modifier.GeneratorModifier; 27 | import java.io.Serializable; 28 | import java.math.BigDecimal; 29 | import java.math.BigInteger; 30 | import java.util.ArrayList; 31 | import java.util.Random; 32 | 33 | /** 34 | * A base class for all the generators. 35 | * 36 | * Generators are used to produce resources (currencies), and 37 | * can be controlled either manually or automatically by using 38 | * an Automator. 39 | * 40 | * @author Harri Pellikka 41 | */ 42 | public class Generator extends Item implements Serializable 43 | { 44 | public interface Callback 45 | { 46 | void onProcessed(); 47 | } 48 | 49 | /** 50 | * Callback for extended functionality 51 | */ 52 | private Callback mCallback = null; 53 | 54 | /** 55 | * Currency this generator should generate 56 | */ 57 | private Currency mCurrency; 58 | 59 | /** 60 | * How many times this generator has been processed 61 | */ 62 | private long mTimesProcessed = 0; 63 | 64 | /** 65 | * Base amount of resources this generator generates 66 | */ 67 | private BigInteger mBaseAmount; 68 | 69 | /** 70 | * Multiplier used to increase the amount of resources generated 71 | * when this generator is upgraded 72 | */ 73 | private double mAmountMultiplier; 74 | 75 | /** 76 | * Probability for this generator to "work" 77 | */ 78 | private double mProbability; 79 | 80 | /** 81 | * Should this generator use probability? 82 | */ 83 | private boolean mUseProbability; 84 | 85 | /** 86 | * RNG for probability 87 | */ 88 | private Random mRandom; 89 | 90 | /** 91 | * Should we take remainders into consideration? 92 | */ 93 | private boolean mUseRemainder; 94 | 95 | /** 96 | * Remainder of the last processing cycle 97 | */ 98 | private double mRemainder; 99 | 100 | /** 101 | * Cooldown time between processing cycles. 102 | */ 103 | private double mCooldown; 104 | 105 | /** 106 | * List of active modifiers attached to this generator 107 | */ 108 | private ArrayList mModifiers = new ArrayList<>(); 109 | 110 | /** 111 | * Builder class for creating new generators 112 | */ 113 | public static class Builder 114 | { 115 | private final World mWorld; 116 | private String mName = "Nameless generator"; 117 | private Callback mOnProcessed = null; 118 | private Currency mCurrency = null; 119 | private BigInteger mBaseAmount = BigInteger.ONE; 120 | private double mAmountMultiplier = 1.1; 121 | private long mMaxLevel = Long.MAX_VALUE; 122 | private BigInteger mBasePrice = BigInteger.ONE; 123 | private double mPriceMultiplier = 1.1; 124 | private double mProbability = 1.0; 125 | private boolean mProbabilitySet = false; 126 | private boolean mUseRemainder = true; 127 | private double mCooldown = 0.0; 128 | /** 129 | * Creates a new generator builder 130 | * @param world World to build the generator into 131 | */ 132 | public Builder(World world) 133 | { 134 | mWorld = world; 135 | } 136 | 137 | public Builder cooldown(double cooldown) 138 | { 139 | mCooldown = cooldown; 140 | return this; 141 | } 142 | 143 | /** 144 | * Store remainder of resources and add an extra 145 | * when the remainder "overflows" 146 | * @return This builder for chaining 147 | */ 148 | public Builder useRemainder() 149 | { 150 | mUseRemainder = true; 151 | return this; 152 | } 153 | 154 | /** 155 | * Discard remainder of resources when generating. 156 | * @return This builder for chaining 157 | */ 158 | public Builder discardRemainder() 159 | { 160 | mUseRemainder = false; 161 | return this; 162 | } 163 | 164 | /** 165 | * Sets the name for the generator 166 | * @param name Name for the generator 167 | * @return This builder for chaining 168 | */ 169 | public Builder name(String name) 170 | { 171 | mName = name; 172 | return this; 173 | } 174 | 175 | /** 176 | * Sets the multiplier for resource generation. This multiplier 177 | * is used in the formula (amount) = (base amount) * (multiplier) ^ (level) 178 | * @param multiplier Amount generation multiplier per level 179 | * @return This builder for chaining 180 | */ 181 | public Builder multiplier(double multiplier) 182 | { 183 | mAmountMultiplier = multiplier; 184 | return this; 185 | } 186 | 187 | /** 188 | * Sets the maximum allowed level for this generator. The max level must 189 | * be greated than zero. 190 | * @param maxLevel Maximum allowed level for this generator 191 | * @return This builder for chaining 192 | */ 193 | public Builder maxLevel(long maxLevel) 194 | { 195 | if(maxLevel <= 0) throw new IllegalArgumentException("Max level must be greater than 0"); 196 | mMaxLevel = maxLevel; 197 | return this; 198 | } 199 | 200 | /** 201 | * Sets the base amount of resources generated by this generator. 202 | * This is the amount the generator generates at level 1 and is used 203 | * as the base for the higher levels. 204 | * @param amount Base amount of resources generated at level 1 205 | * @return This builder for chaining 206 | */ 207 | public Builder baseAmount(BigInteger amount) 208 | { 209 | if(amount == null) throw new IllegalArgumentException("Base amount cannot be null"); 210 | mBaseAmount = amount; 211 | return this; 212 | } 213 | 214 | /** 215 | * Sets the base amount of resources generated by this generator. 216 | * This is the amount the generator generates at level 1 and is used 217 | * as the base for the higher levels. 218 | * @param amount Base amount of resources generated at level 1 219 | * @return This builder for chaining 220 | */ 221 | public Builder baseAmount(long amount) 222 | { 223 | mBaseAmount = new BigInteger("" + amount); 224 | return this; 225 | } 226 | 227 | /** 228 | * Sets the base amount of resources generated by this generator. 229 | * This is the amount the generator generates at level 1 and is used 230 | * as the base for the higher levels. 231 | * @param amount Base amount of resources generated at level 1 232 | * @return This builder for chaining 233 | */ 234 | public Builder baseAmount(int amount) 235 | { 236 | mBaseAmount = new BigInteger("" + amount); 237 | return this; 238 | } 239 | 240 | /** 241 | * Sets the currency that should be generated by the generator. 242 | * @param c Currency to generate 243 | * @return This builder for chaining 244 | * @throws IllegalArgumentException Thrown if the currency is null 245 | */ 246 | public Builder generate(Currency c) throws IllegalArgumentException 247 | { 248 | if(c == null) throw new IllegalArgumentException("Currency cannot be null"); 249 | mCurrency = c; 250 | return this; 251 | } 252 | 253 | /** 254 | * Sets a callback for the generator to be called when the generator 255 | * has finished its processing cycle (i.e. has generated something). 256 | * @param callback Callback to call after generating something 257 | * @return This builder for chaining 258 | */ 259 | public Builder callback(Callback callback) 260 | { 261 | mOnProcessed = callback; 262 | return this; 263 | } 264 | 265 | public Builder price(BigInteger price) 266 | { 267 | mBasePrice = price; 268 | return this; 269 | } 270 | 271 | public Builder price(long price) 272 | { 273 | mBasePrice = new BigInteger("" + price); 274 | return this; 275 | } 276 | 277 | public Builder price(int price) 278 | { 279 | mBasePrice = new BigInteger("" + price); 280 | return this; 281 | } 282 | 283 | public Builder priceMultiplier(double multiplier) 284 | { 285 | mPriceMultiplier = multiplier; 286 | return this; 287 | } 288 | 289 | /** 290 | * Set a probability for this generator to "work" when it's processed 291 | * @param probability Probability percentage (between 0.0 and 1.0) 292 | * @return This builder for chaining 293 | */ 294 | public Builder probability(double probability) 295 | { 296 | if(probability < 0 || probability > 1.0) throw new IllegalArgumentException("Probability should be between 0.0 and 1.0"); 297 | mProbability = probability; 298 | mProbabilitySet = true; 299 | return this; 300 | } 301 | 302 | /** 303 | * Constructs the generator based on the given parameters 304 | * @return The generator 305 | */ 306 | public Generator build() 307 | { 308 | Generator g = new Generator(mWorld, mName); 309 | g.mCallback = mOnProcessed; 310 | g.mCurrency = mCurrency; 311 | g.mAmountMultiplier = mAmountMultiplier; 312 | g.mBaseAmount = mBaseAmount; 313 | g.mMaxItemLevel = mMaxLevel; 314 | g.mBasePrice = mBasePrice; 315 | g.mPriceMultiplier = mPriceMultiplier; 316 | g.mProbability = mProbability; 317 | g.mUseProbability = mProbabilitySet; 318 | g.mRandom = new Random(); 319 | g.mRandom.setSeed(g.hashCode()); 320 | g.mUseRemainder = mUseRemainder; 321 | g.mCooldown = mCooldown; 322 | mWorld.addGenerator(g); 323 | return g; 324 | } 325 | } 326 | 327 | /** 328 | * Constructs a new generator 329 | */ 330 | private Generator(World world) 331 | { 332 | super(world); 333 | } 334 | 335 | /** 336 | * Constructs a new generator 337 | * @param name Name of this generator 338 | */ 339 | private Generator(World world, String name) 340 | { 341 | super(world, name); 342 | } 343 | 344 | /** 345 | * Upgrades this generator by one level 346 | */ 347 | public void upgrade() 348 | { 349 | if(mItemLevel < mMaxItemLevel) 350 | { 351 | mItemLevel++; 352 | } 353 | } 354 | 355 | /** 356 | * Downgrades this generator by one level 357 | */ 358 | public void downgrade() 359 | { 360 | if(mItemLevel > 0) 361 | { 362 | mItemLevel--; 363 | } 364 | } 365 | 366 | /** 367 | * Retrieves the amount this generator currently is generating per 368 | * processing cycle 369 | * @return Amount of resources generated by this generator 370 | */ 371 | public BigInteger getGeneratedAmount() 372 | { 373 | if(mItemLevel == 0) return BigInteger.ZERO; 374 | 375 | BigDecimal tmp = new BigDecimal(mBaseAmount); 376 | tmp = tmp.multiply(new BigDecimal(Math.pow(mAmountMultiplier, mItemLevel - 1))); 377 | if(mUseRemainder) 378 | { 379 | double tmpRem = tmp.remainder(BigDecimal.ONE).doubleValue(); 380 | mRemainder += tmpRem; 381 | if(mRemainder >= 0.999) 382 | { 383 | mRemainder -= 1.0; 384 | tmp = tmp.add(new BigDecimal(1)); 385 | } 386 | } 387 | 388 | tmp = processModifiers(tmp); 389 | 390 | return tmp.toBigInteger(); 391 | } 392 | 393 | private BigDecimal processModifiers(BigDecimal val) 394 | { 395 | if(mModifiers.size() == 0) return val; 396 | 397 | for(GeneratorModifier m : mModifiers) 398 | { 399 | double d = m.getMultiplier(); 400 | if(d != 1.0) 401 | { 402 | val = val.multiply(new BigDecimal(d)); 403 | } 404 | } 405 | 406 | return val; 407 | } 408 | 409 | /** 410 | * Determines if this generator should generate anything based on its 411 | * properties such as item level and probability. 412 | * 413 | * @return True if should work, false otherwise 414 | */ 415 | private boolean isWorking() 416 | { 417 | if(mItemLevel > 0) 418 | { 419 | if(!mUseProbability || mRandom.nextDouble() < mProbability) return true; 420 | } 421 | return false; 422 | } 423 | 424 | /** 425 | * Processes this generator, generating resources as per the rules 426 | * of this generator. 427 | */ 428 | public void process() 429 | { 430 | if(isWorking()) 431 | { 432 | mCurrency.add(getGeneratedAmount()); 433 | mTimesProcessed++; 434 | if(mCallback != null) mCallback.onProcessed(); 435 | } 436 | } 437 | 438 | /** 439 | * Retrieves the number of times this generator has done its processing 440 | * @return Number of times processed 441 | */ 442 | public long getTimesProcessed() 443 | { 444 | return mTimesProcessed; 445 | } 446 | 447 | void attachModifier(GeneratorModifier modifier) 448 | { 449 | if(modifier != null && !mModifiers.contains(modifier)) 450 | { 451 | mModifiers.add(modifier); 452 | } 453 | } 454 | 455 | void detachModifier(GeneratorModifier modifier) 456 | { 457 | if(modifier != null) 458 | { 459 | mModifiers.remove(modifier); 460 | } 461 | } 462 | } 463 | -------------------------------------------------------------------------------- /src/com/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 com.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.math.BigDecimal; 28 | import java.math.BigInteger; 29 | import java.util.ArrayList; 30 | 31 | /** 32 | * Base class for all the purchasable "items". 33 | * 34 | * @author Harri Pellikka 35 | */ 36 | public abstract class Item implements Serializable 37 | { 38 | /** 39 | * The base price of the item (i.e. the price of the first level of this item) 40 | */ 41 | protected BigInteger mBasePrice = BigInteger.ONE; 42 | 43 | /** 44 | * Name of this item 45 | */ 46 | protected String mName = "Nameless Item"; 47 | 48 | /** 49 | * Description text for this item 50 | */ 51 | protected String mDescription = "No description."; 52 | 53 | /** 54 | * Current level of this item 55 | */ 56 | protected long mItemLevel = 0; 57 | 58 | /** 59 | * Max. item level 60 | */ 61 | protected long mMaxItemLevel = Long.MAX_VALUE; 62 | 63 | /** 64 | * Price multiplier per level. This is used in the price formula 65 | * like this: price = (base price) * (price multiplier) ^ (item level) 66 | */ 67 | protected double mPriceMultiplier = 1.145; 68 | 69 | /** 70 | * World this item belongs to 71 | */ 72 | private final World mWorld; 73 | 74 | /** 75 | * Modifiers applied to this item 76 | */ 77 | final ArrayList mModifiers = new ArrayList<>(); 78 | 79 | /** 80 | * Constructs a new item 81 | * @param world World this item belongs to 82 | */ 83 | protected Item(World world) 84 | { 85 | mWorld = world; 86 | } 87 | 88 | /** 89 | * Constructs a new item 90 | * @param world World this item belongs to 91 | * @param name Name of this item 92 | */ 93 | protected Item(World world, String name) 94 | { 95 | mWorld = world; 96 | setName(name); 97 | } 98 | 99 | /** 100 | * Retrieves the name of this item 101 | * @return Name of this item 102 | */ 103 | public String getName() 104 | { 105 | return mName; 106 | } 107 | 108 | /** 109 | * Sets the name of this item 110 | * @param name New name for this item 111 | */ 112 | public void setName(String name) 113 | { 114 | if(name == null || name.isEmpty()) throw new RuntimeException("Item name cannot be null or empty"); 115 | mName = name; 116 | } 117 | 118 | public String getDescription() 119 | { 120 | return mDescription; 121 | } 122 | 123 | public void setDescription(String description) 124 | { 125 | mDescription = description; 126 | } 127 | 128 | /** 129 | * Retrieves the base price of this item 130 | * @return Base price of this item 131 | */ 132 | public BigInteger getBasePrice() 133 | { 134 | return mBasePrice; 135 | } 136 | 137 | public BigInteger getPrice() 138 | { 139 | BigDecimal tmp = new BigDecimal(mBasePrice); 140 | tmp = tmp.multiply(new BigDecimal(Math.pow(mPriceMultiplier, mItemLevel))); 141 | return tmp.toBigInteger(); 142 | } 143 | 144 | public PurchaseResult buyWith(Currency currency) 145 | { 146 | if(currency == null) throw new IllegalArgumentException("Currency cannot be null"); 147 | if(mItemLevel >= mMaxItemLevel) return PurchaseResult.MAX_LEVEL_REACHED; 148 | 149 | BigInteger price = getPrice(); 150 | BigInteger result = currency.getValue().subtract(price); 151 | if(result.signum() < 0) 152 | { 153 | return PurchaseResult.INSUFFICIENT_FUNDS; 154 | } 155 | currency.sub(price); 156 | upgrade(); 157 | return PurchaseResult.OK; 158 | } 159 | 160 | /** 161 | * Sets the base price of this item 162 | * @param basePrice New base price for this item 163 | */ 164 | public void setBasePrice(BigInteger basePrice) 165 | { 166 | if(basePrice == null) throw new RuntimeException("Base price cannot be null"); 167 | if(basePrice.equals(BigInteger.ZERO)) throw new RuntimeException("Base price cannot be zero"); 168 | mBasePrice = basePrice; 169 | } 170 | 171 | public void setBasePrice(long basePrice) 172 | { 173 | mBasePrice = new BigInteger("" + basePrice); 174 | } 175 | 176 | public void setBasePrice(int basePrice) 177 | { 178 | mBasePrice = new BigInteger("" + basePrice); 179 | } 180 | 181 | /** 182 | * Retrieves the price multiplier 183 | * @return Price multiplier 184 | */ 185 | public double getPriceMultiplier() 186 | { 187 | return mPriceMultiplier; 188 | } 189 | 190 | /** 191 | * Sets the price multiplier of this item 192 | * @param multiplier Price multiplier 193 | */ 194 | public void setPriceMultiplier(double multiplier) 195 | { 196 | mPriceMultiplier = multiplier; 197 | } 198 | 199 | public long getMaxItemLevel() 200 | { 201 | return mMaxItemLevel; 202 | } 203 | 204 | public void setMaxItemLevel(long maxLvl) 205 | { 206 | if(maxLvl <= 0) throw new RuntimeException("Max item level cannot be zero or negative"); 207 | mMaxItemLevel = maxLvl; 208 | } 209 | 210 | public long getItemLevel() 211 | { 212 | return mItemLevel; 213 | } 214 | 215 | public void setItemLevel(long lvl) 216 | { 217 | mItemLevel = lvl < 0 ? 0 : lvl > mMaxItemLevel ? mMaxItemLevel : lvl; 218 | } 219 | 220 | public void upgrade() 221 | { 222 | if(mItemLevel < mMaxItemLevel) 223 | { 224 | mItemLevel++; 225 | } 226 | } 227 | 228 | public void downgrade() 229 | { 230 | if(mItemLevel > 0) 231 | { 232 | mItemLevel--; 233 | } 234 | } 235 | 236 | public void maximize() 237 | { 238 | mItemLevel = mMaxItemLevel; 239 | } 240 | 241 | protected World getWorld() 242 | { 243 | return mWorld; 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/com/manabreak/libclicker/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 com.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | 28 | /** 29 | * A base class for all the modifiers. 30 | * 31 | * A modifier does "something" to a component (generator, automator, the 32 | * world etc), for example speeds up, slows down, increases production 33 | * or something similar. 34 | * 35 | * @author Harri Pellikka 36 | */ 37 | public abstract class Modifier extends Item implements Serializable 38 | { 39 | private boolean mEnabled = false; 40 | 41 | /** 42 | * Modifier for worlds 43 | */ 44 | static class WorldModifier extends Modifier 45 | { 46 | private double mSpeedMultiplier; 47 | private boolean mDisableActivators; 48 | 49 | private double mSpeedMultiplierBefore; 50 | private double mSpeedMultiplierAfter; 51 | 52 | WorldModifier(World world) 53 | { 54 | super(world); 55 | } 56 | 57 | @Override 58 | protected void onEnable() 59 | { 60 | if(mSpeedMultiplier != 1.0) 61 | { 62 | mSpeedMultiplierBefore = getWorld().getSpeedMultiplier(); 63 | mSpeedMultiplierAfter = mSpeedMultiplier * mSpeedMultiplierBefore; 64 | getWorld().setSpeedMultiplier(mSpeedMultiplierAfter); 65 | } 66 | 67 | if(mDisableActivators) 68 | { 69 | getWorld().disableAutomators(); 70 | } 71 | } 72 | 73 | @Override 74 | protected void onDisable() 75 | { 76 | if(mSpeedMultiplier != 1.0) 77 | { 78 | double d = getWorld().getSpeedMultiplier(); 79 | d /= mSpeedMultiplier; 80 | getWorld().setSpeedMultiplier(d); 81 | } 82 | 83 | if(mDisableActivators) 84 | { 85 | getWorld().enableAutomators(); 86 | } 87 | } 88 | } 89 | 90 | /** 91 | * Modifier for generators. 92 | */ 93 | static class GeneratorModifier extends Modifier 94 | { 95 | private final Generator mGenerator; 96 | private double mMultiplier = 1.0; 97 | 98 | GeneratorModifier(Generator generator) 99 | { 100 | super(generator.getWorld()); 101 | mGenerator = generator; 102 | } 103 | 104 | @Override 105 | protected void onEnable() 106 | { 107 | mGenerator.attachModifier(this); 108 | } 109 | 110 | @Override 111 | protected void onDisable() 112 | { 113 | mGenerator.detachModifier(this); 114 | } 115 | 116 | double getMultiplier() 117 | { 118 | return mMultiplier; 119 | } 120 | } 121 | 122 | /** 123 | * Builder class for the modifiers 124 | */ 125 | public static class Builder 126 | { 127 | /** 128 | * A modifier settings class for world modifiers. 129 | * Keeps track of all the parameters the modifier should 130 | * modify. 131 | */ 132 | public static class WorldTarget 133 | { 134 | World mWorld; 135 | private double mSpeedMultiplier = 1.0; 136 | private boolean mDisableActivators = false; 137 | 138 | WorldTarget(World w) 139 | { 140 | mWorld = w; 141 | } 142 | 143 | /** 144 | * Speeds up all the processing by the given multiplier. 145 | * @param multiplier Multiplier for advancing the time 146 | * @return This target for chaining 147 | */ 148 | public WorldTarget speedBy(double multiplier) 149 | { 150 | mSpeedMultiplier = multiplier; 151 | return this; 152 | } 153 | 154 | /** 155 | * Disables all the activators 156 | * @return This target for chaining 157 | */ 158 | public WorldTarget disableActivators() 159 | { 160 | mDisableActivators = true; 161 | return this; 162 | } 163 | 164 | /** 165 | * Creates the actual modifier based on the given settings 166 | * @return Modifier 167 | */ 168 | public Modifier build() 169 | { 170 | WorldModifier m = new WorldModifier(mWorld); 171 | m.mSpeedMultiplier = mSpeedMultiplier; 172 | m.mDisableActivators = mDisableActivators; 173 | return m; 174 | } 175 | } 176 | 177 | /** 178 | * A modifier settings class for generator modifiers. 179 | * Keeps track of all the parameters the modifier should 180 | * modify. 181 | */ 182 | public static class GeneratorTarget 183 | { 184 | private Generator mGenerator; 185 | private double mMultiplier = 1.0; 186 | 187 | GeneratorTarget(Generator gen) 188 | { 189 | mGenerator = gen; 190 | } 191 | 192 | /** 193 | * Multiplies the production of the generator. 194 | * 195 | * @param multiplier Multiplier 196 | * @return This target for chaining 197 | */ 198 | public GeneratorTarget multiplier(double multiplier) 199 | { 200 | mMultiplier = multiplier; 201 | return this; 202 | } 203 | 204 | /** 205 | * Constructs the actual modifier with the given settings 206 | * @return Modifier as per the given settings 207 | */ 208 | public Modifier build() 209 | { 210 | GeneratorModifier m = new GeneratorModifier(mGenerator); 211 | m.mMultiplier = mMultiplier; 212 | return m; 213 | } 214 | } 215 | 216 | /** 217 | * Constructs a new modifier builder 218 | */ 219 | public Builder() 220 | { 221 | 222 | } 223 | 224 | /** 225 | * Apply the modifier to a world 226 | * @param world World to modify 227 | * @return A world target to set the modification details 228 | */ 229 | public final WorldTarget modify(World world) 230 | { 231 | return new WorldTarget(world); 232 | } 233 | 234 | /** 235 | * Apply the modifier to a generator 236 | * @param gen Generator to modify 237 | * @return A generator target to set the modification details 238 | */ 239 | public final GeneratorTarget modify(Generator gen) 240 | { 241 | return new GeneratorTarget(gen); 242 | } 243 | } 244 | 245 | private Modifier(World world) 246 | { 247 | super(world); 248 | } 249 | 250 | protected abstract void onEnable(); 251 | protected abstract void onDisable(); 252 | 253 | /** 254 | * Enables this modifier, i.e. makes it active 255 | */ 256 | public void enable() 257 | { 258 | if(!mEnabled) 259 | { 260 | mEnabled = true; 261 | getWorld().addModifier(this); 262 | onEnable(); 263 | } 264 | } 265 | 266 | /** 267 | * Disables this modifier, i.e. makes it inactive 268 | */ 269 | public void disable() 270 | { 271 | if(mEnabled) 272 | { 273 | onDisable(); 274 | getWorld().removeModifier(this); 275 | mEnabled = false; 276 | } 277 | } 278 | 279 | /** 280 | * Checks whether or not this modifier is enabled 281 | * @return True if enabled, false otherwise 282 | */ 283 | public boolean isEnabled() 284 | { 285 | return mEnabled; 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /src/com/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 com.manabreak.libclicker; 25 | 26 | /** 27 | * A purchase result enumeration. Denotes the result when trying to 28 | * purchase an item. 29 | * 30 | * @author Harri Pellikka 31 | */ 32 | public enum PurchaseResult 33 | { 34 | OK, 35 | INSUFFICIENT_FUNDS, 36 | MAX_LEVEL_REACHED 37 | } 38 | -------------------------------------------------------------------------------- /src/com/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 com.manabreak.libclicker; 25 | 26 | import java.io.Serializable; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | /** 31 | * A container for all the clicker objects 32 | * 33 | * @author Harri Pellikka 34 | */ 35 | public class World implements Serializable 36 | { 37 | /** 38 | * Active generators 39 | */ 40 | private ArrayList mGenerators = new ArrayList<>(); 41 | 42 | /** 43 | * Active automators 44 | */ 45 | private ArrayList mAutomators = new ArrayList<>(); 46 | 47 | /** 48 | * Currencies in use 49 | */ 50 | private ArrayList mCurrencies = new ArrayList<>(); 51 | 52 | /** 53 | * Modifiers in use 54 | */ 55 | private ArrayList mModifiers = new ArrayList<>(); 56 | 57 | /** 58 | * Speed multiplier - used to multiply the time the world advances 59 | */ 60 | private double mSpeedMultiplier = 1.0; 61 | 62 | /** 63 | * Should automators be updated? 64 | */ 65 | private boolean mUpdateAutomators = true; 66 | 67 | /** 68 | * Constructs a new world. All the other components require an existing 69 | * "world" to function. A world is a container for the whole system. 70 | */ 71 | public World() 72 | { 73 | 74 | } 75 | 76 | /** 77 | * Adds a new generator to this world 78 | * @param generator Generator to add 79 | */ 80 | void addGenerator(Generator generator) 81 | { 82 | if(generator != null && !mGenerators.contains(generator)) 83 | { 84 | mGenerators.add(generator); 85 | } 86 | } 87 | 88 | /** 89 | * Returns the number of generators in this world 90 | * @return The number of generators in this world 91 | */ 92 | public int getGeneratorCount() 93 | { 94 | return mGenerators.size(); 95 | } 96 | 97 | /** 98 | * Removes a generator 99 | * @param generator Generator to remove 100 | */ 101 | void removeGenerator(Generator generator) 102 | { 103 | if(generator != null && mGenerators.contains(generator)) 104 | { 105 | mGenerators.remove(generator); 106 | } 107 | } 108 | 109 | /** 110 | * Removes all the generators from this world 111 | */ 112 | void removeAllGenerators() 113 | { 114 | mGenerators.clear(); 115 | } 116 | 117 | void addCurrency(Currency c) 118 | { 119 | if(c != null && !mCurrencies.contains(c)) 120 | { 121 | mCurrencies.add(c); 122 | } 123 | } 124 | 125 | void removeCurrency(Currency c) 126 | { 127 | if(c != null) 128 | { 129 | mCurrencies.remove(c); 130 | } 131 | } 132 | 133 | Currency getCurrency(int index) 134 | { 135 | return mCurrencies.get(index); 136 | } 137 | 138 | List getCurrencies() 139 | { 140 | return mCurrencies; 141 | } 142 | 143 | void removeAllCurrencies() 144 | { 145 | mCurrencies.clear(); 146 | } 147 | 148 | /** 149 | * Advances the world state by the given amount of seconds. 150 | * Useful when calculating away-from-keyboard income etc. 151 | * 152 | * @param seconds Seconds to advance 153 | */ 154 | public void update(double seconds) 155 | { 156 | seconds *= mSpeedMultiplier; 157 | 158 | if(mUpdateAutomators) 159 | { 160 | for(Automator a : mAutomators) 161 | { 162 | a.update(seconds); 163 | } 164 | } 165 | } 166 | 167 | void addAutomator(Automator automator) 168 | { 169 | if(automator != null && !mAutomators.contains(automator)) 170 | { 171 | mAutomators.add(automator); 172 | } 173 | } 174 | 175 | void addModifier(Modifier modifier) 176 | { 177 | if(modifier != null && !mModifiers.contains(modifier)) 178 | { 179 | mModifiers.add(modifier); 180 | } 181 | } 182 | 183 | double getSpeedMultiplier() 184 | { 185 | return mSpeedMultiplier; 186 | } 187 | 188 | void setSpeedMultiplier(double multiplier) 189 | { 190 | mSpeedMultiplier = multiplier; 191 | } 192 | 193 | void disableAutomators() 194 | { 195 | mUpdateAutomators = false; 196 | } 197 | 198 | void enableAutomators() 199 | { 200 | mUpdateAutomators = true; 201 | } 202 | 203 | void removeAutomator(Automator automator) 204 | { 205 | if(automator != null) 206 | { 207 | mAutomators.remove(automator); 208 | } 209 | } 210 | 211 | List getAutomators() 212 | { 213 | return mAutomators; 214 | } 215 | 216 | List getModifiers() 217 | { 218 | return mModifiers; 219 | } 220 | 221 | void removeModifier(Modifier modifier) 222 | { 223 | if(modifier != null) 224 | { 225 | mModifiers.remove(modifier); 226 | } 227 | } 228 | 229 | boolean isAutomationEnabled() 230 | { 231 | return mUpdateAutomators; 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | import static org.junit.Assert.*; 28 | 29 | /** 30 | * 31 | * @author Harri 32 | */ 33 | public class AutomatorTest 34 | { 35 | @Test 36 | public void testUpdate() 37 | { 38 | World world = new World(); 39 | 40 | System.out.println("update()"); 41 | Currency c = new Currency.Builder(world) 42 | .build(); 43 | Generator g = new Generator.Builder(world) 44 | .generate(c) 45 | .build(); 46 | g.upgrade(); 47 | 48 | Automator a = new Automator.Builder(world) 49 | .automate(g) 50 | .every(1.0) 51 | .build(); 52 | a.upgrade(); 53 | 54 | world.update(1.0); 55 | assertEquals(1, g.getTimesProcessed()); 56 | 57 | world.update(9.0); 58 | assertEquals(10, g.getTimesProcessed()); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | 27 | import java.math.BigInteger; 28 | import org.junit.After; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | import static org.junit.Assert.*; 32 | 33 | /** 34 | * Unit tests for the currency formatter 35 | * 36 | * @author Harri Pellikka 37 | */ 38 | public class CurrencyFormatterTest 39 | { 40 | World w; 41 | Currency c; 42 | Formatter cf; 43 | 44 | @Before 45 | public void setUp() 46 | { 47 | w = new World(); 48 | c = new Currency.Builder(w).name("Gold").build(); 49 | cf = null; 50 | } 51 | 52 | @After 53 | public void tearDown() 54 | { 55 | w = null; 56 | c = null; 57 | cf = null; 58 | } 59 | 60 | @Test 61 | public void testDigitGrouping() 62 | { 63 | System.out.println("toString()"); 64 | 65 | // Test the 66 | cf = new Formatter.ForCurrency(c) 67 | .groupDigits() 68 | .showFully() 69 | .build(); 70 | 71 | assertEquals("0", cf.toString()); 72 | 73 | c.set(new BigInteger("1")); 74 | assertEquals("1", cf.toString()); 75 | 76 | c.set(new BigInteger("12")); 77 | assertEquals("12", cf.toString()); 78 | 79 | c.set(new BigInteger("123")); 80 | assertEquals("123", cf.toString()); 81 | 82 | c.set(new BigInteger("1234")); 83 | assertEquals("1,234", cf.toString()); 84 | 85 | c.set(new BigInteger("12345")); 86 | assertEquals("12,345", cf.toString()); 87 | 88 | c.set(new BigInteger("123456")); 89 | assertEquals("123,456", cf.toString()); 90 | 91 | c.set(new BigInteger("1234567")); 92 | assertEquals("1,234,567", cf.toString()); 93 | 94 | c.set(new BigInteger("12345678")); 95 | assertEquals("12,345,678", cf.toString()); 96 | } 97 | 98 | @Test 99 | public void testRaw() throws Exception 100 | { 101 | cf = new Formatter.ForCurrency(c) 102 | .dontGroupDigits() 103 | .showFully() 104 | .build(); 105 | 106 | assertEquals("0", cf.toString()); 107 | 108 | c.set(new BigInteger("1")); 109 | assertEquals("1", cf.toString()); 110 | 111 | c.set(new BigInteger("12")); 112 | assertEquals("12", cf.toString()); 113 | 114 | c.set(new BigInteger("123")); 115 | assertEquals("123", cf.toString()); 116 | 117 | c.set(new BigInteger("1234")); 118 | assertEquals("1234", cf.toString()); 119 | 120 | c.set(new BigInteger("12345")); 121 | assertEquals("12345", cf.toString()); 122 | 123 | c.set(new BigInteger("123456")); 124 | assertEquals("123456", cf.toString()); 125 | 126 | c.set(new BigInteger("1234567")); 127 | assertEquals("1234567", cf.toString()); 128 | 129 | c.set(new BigInteger("12345678")); 130 | assertEquals("12345678", cf.toString()); 131 | } 132 | 133 | @Test 134 | public void testCutAtHighestWithDecimals() throws Exception 135 | { 136 | cf = new Formatter.ForCurrency(c) 137 | .showHighestThousand() 138 | .showDecimals(2, ".") 139 | .build(); 140 | 141 | assertEquals("0", cf.toString()); 142 | 143 | c.set(new BigInteger("1")); 144 | assertEquals("1", cf.toString()); 145 | 146 | c.set(new BigInteger("123")); 147 | assertEquals("123", cf.toString()); 148 | 149 | c.set(new BigInteger("1234")); 150 | assertEquals("1.23", cf.toString()); 151 | 152 | c.set(new BigInteger("12345")); 153 | assertEquals("12.34", cf.toString()); 154 | 155 | c.set(new BigInteger("123456")); 156 | assertEquals("123.45", cf.toString()); 157 | 158 | c.set(new BigInteger("1234567")); 159 | assertEquals("1.23", cf.toString()); 160 | } 161 | 162 | @Test 163 | public void testCutAtHighestNoDecimals() throws Exception 164 | { 165 | cf = new Formatter.ForCurrency(c) 166 | .showHighestThousand() 167 | .dontShowDecimals() 168 | .build(); 169 | 170 | assertEquals("0", cf.toString()); 171 | 172 | c.set(new BigInteger("1")); 173 | assertEquals("1", cf.toString()); 174 | 175 | c.set(new BigInteger("12")); 176 | assertEquals("12", cf.toString()); 177 | 178 | c.set(new BigInteger("123")); 179 | assertEquals("123", cf.toString()); 180 | 181 | c.set(new BigInteger("1234")); 182 | assertEquals("1", cf.toString()); 183 | 184 | c.set(new BigInteger("5432")); 185 | assertEquals("5", cf.toString()); 186 | 187 | c.set(new BigInteger("54321")); 188 | assertEquals("54", cf.toString()); 189 | 190 | c.set(new BigInteger("123456")); 191 | assertEquals("123", cf.toString()); 192 | 193 | c.set(new BigInteger("98712345")); 194 | assertEquals("98", cf.toString()); 195 | } 196 | 197 | @Test 198 | public void testSeparators() throws Exception 199 | { 200 | cf = new Formatter.ForCurrency(c) 201 | .groupDigits() 202 | .showFully() 203 | .build(); 204 | 205 | // Default thousands separator ',' 206 | c.set(new BigInteger("123456789")); 207 | assertEquals("123,456,789", cf.toString()); 208 | 209 | // Set a single space as thousands separator 210 | cf = new Formatter.ForCurrency(c) 211 | .groupDigits(" ") 212 | .showFully() 213 | .build(); 214 | assertEquals("123 456 789", cf.toString()); 215 | 216 | // Default decimal separator '.' 217 | cf = new Formatter.ForCurrency(c) 218 | .showDecimals() 219 | .showHighestThousand() 220 | .build(); 221 | assertEquals("123.45", cf.toString()); 222 | 223 | // Custom separator '#' 224 | cf = new Formatter.ForCurrency(c) 225 | .showDecimals("#") 226 | .showHighestThousand() 227 | .build(); 228 | assertEquals("123#45", cf.toString()); 229 | 230 | // Show more decimals 231 | cf = new Formatter.ForCurrency(c) 232 | .showDecimals(3) 233 | .showHighestThousand() 234 | .build(); 235 | assertEquals("123.456", cf.toString()); 236 | 237 | // Show just one decimal 238 | cf = new Formatter.ForCurrency(c) 239 | .showDecimals(1) 240 | .showHighestThousand() 241 | .build(); 242 | assertEquals("123.4", cf.toString()); 243 | 244 | } 245 | 246 | @Test 247 | public void testNames() 248 | { 249 | cf = new Formatter.ForCurrency(c) 250 | .showDecimals(2) 251 | .showHighestThousand() 252 | .useAbbreviations(new String[]{"K", "M", "B", "T", "aa"}) 253 | .build(); 254 | 255 | c.set(new BigInteger("123")); 256 | assertEquals("123", cf.toString()); 257 | 258 | c.set(new BigInteger("1234")); 259 | assertEquals("1.23K", cf.toString()); 260 | 261 | c.set(new BigInteger("12345")); 262 | assertEquals("12.34K", cf.toString()); 263 | 264 | c.set(new BigInteger("123456")); 265 | assertEquals("123.45K", cf.toString()); 266 | 267 | c.set(new BigInteger("1234567")); 268 | assertEquals("1.23M", cf.toString()); 269 | 270 | c.set(new BigInteger("12345678")); 271 | assertEquals("12.34M", cf.toString()); 272 | 273 | c.set(new BigInteger("123456789")); 274 | assertEquals("123.45M", cf.toString()); 275 | 276 | c.set(new BigInteger("1234567890")); 277 | assertEquals("1.23B", cf.toString()); 278 | 279 | c.set(new BigInteger("12312312312")); 280 | assertEquals("12.31B", cf.toString()); 281 | 282 | c.set(new BigInteger("123123123123")); 283 | assertEquals("123.12B", cf.toString()); 284 | 285 | c.set(new BigInteger("1231231231231")); 286 | assertEquals("1.23T", cf.toString()); 287 | 288 | c.set(new BigInteger("12312312312312")); 289 | assertEquals("12.31T", cf.toString()); 290 | 291 | c.set(new BigInteger("123123123123123")); 292 | assertEquals("123.12T", cf.toString()); 293 | 294 | c.set(new BigInteger("1231231231231231")); 295 | assertEquals("1.23aa", cf.toString()); 296 | 297 | c.set(new BigInteger("12312312312312312")); 298 | assertEquals("12.31aa", cf.toString()); 299 | 300 | c.set(new BigInteger("123123123123123123")); 301 | assertEquals("123.12aa", cf.toString()); 302 | 303 | c.set(new BigInteger("1231231231231231231")); 304 | assertEquals("1.23", cf.toString()); 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import java.math.BigInteger; 27 | import org.junit.Test; 28 | import static org.junit.Assert.*; 29 | 30 | /** 31 | * 32 | * @author Harri Pellikka 33 | */ 34 | public class CurrencyTest 35 | { 36 | 37 | /** 38 | * Test of getName method, of class Currency. 39 | */ 40 | @Test 41 | public void testGetName() 42 | { 43 | World world = new World(); 44 | System.out.println("getName()"); 45 | Currency instance = new Currency.Builder(world).name("TestCurrency").build(); 46 | String expResult = "TestCurrency"; 47 | String result = instance.getName(); 48 | assertEquals(expResult, result); 49 | } 50 | 51 | /** 52 | * Test of add method, of class Currency. 53 | */ 54 | @Test 55 | public void testArithmetic() 56 | { 57 | World world = new World(); 58 | 59 | System.out.println("testArithmetic()"); 60 | Currency c = new Currency.Builder(world).build(); 61 | assertEquals(BigInteger.ZERO, c.getValue()); 62 | 63 | c.add(new BigInteger("1")); 64 | assertEquals(BigInteger.ONE, c.getValue()); 65 | 66 | c.add(new BigInteger("12344")); 67 | assertEquals(new BigInteger("12345"), c.getValue()); 68 | 69 | c.sub(new BigInteger("300")); 70 | assertEquals(new BigInteger("12045"), c.getValue()); 71 | 72 | c.set(new BigInteger("100")); 73 | assertEquals(new BigInteger("100"), c.getValue()); 74 | 75 | c.multiply(2.0); 76 | assertEquals(new BigInteger("200"), c.getValue()); 77 | 78 | c.multiply(1.145); 79 | int targetVal = (int)(1.145 * 200); 80 | assertEquals(new BigInteger("" + targetVal), c.getValue()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import com.manabreak.libclicker.Formatter.CurrencyFormatter; 27 | import java.math.BigInteger; 28 | import org.junit.Test; 29 | import static org.junit.Assert.*; 30 | 31 | /** 32 | * 33 | * @author Harri Pellikka 34 | */ 35 | public class GeneratorTest 36 | { 37 | 38 | @Test 39 | public void testGeneration() throws Exception 40 | { 41 | World w = new World(); 42 | Currency c = new Currency.Builder(w).name("Gold").build(); 43 | 44 | Formatter cf = new Formatter.ForCurrency(c) 45 | .showHighestThousand() 46 | .showDecimals() 47 | .build(); 48 | 49 | Generator g = new Generator.Builder(w) 50 | .baseAmount(100) 51 | .multiplier(1.2) 52 | .generate(c) 53 | .build(); 54 | 55 | assertEquals(BigInteger.ZERO, g.getGeneratedAmount()); 56 | g.process(); 57 | assertEquals(BigInteger.ZERO, c.getValue()); 58 | 59 | g.upgrade(); 60 | assertEquals(new BigInteger("" + 100), g.getGeneratedAmount()); 61 | g.process(); 62 | assertEquals(new BigInteger("" + 100), c.getValue()); 63 | 64 | BigInteger amount = g.getGeneratedAmount(); 65 | g.upgrade(); 66 | g.process(); 67 | amount = amount.add(g.getGeneratedAmount()); 68 | // assertEquals(amount, c.getValue()); 69 | assertEquals(amount, c.getValue()); 70 | } 71 | 72 | @Test 73 | public void testRemainderUsage() throws Exception 74 | { 75 | World w = new World(); 76 | 77 | Currency c = new Currency.Builder(w) 78 | .name("Gold") 79 | .build(); 80 | 81 | Generator g = new Generator.Builder(w) 82 | .baseAmount(1) 83 | .multiplier(1.2) 84 | .useRemainder() 85 | .generate(c) 86 | .build(); 87 | 88 | // Set to level 2 89 | g.setItemLevel(2); 90 | 91 | assertEquals(BigInteger.ZERO, c.getValue()); 92 | 93 | g.process(); 94 | assertEquals(new BigInteger("1"), c.getValue()); 95 | 96 | g.process(); 97 | assertEquals(new BigInteger("2"), c.getValue()); 98 | 99 | g.process(); 100 | assertEquals(new BigInteger("3"), c.getValue()); 101 | 102 | g.process(); 103 | assertEquals(new BigInteger("4"), c.getValue()); 104 | 105 | g.process(); 106 | assertEquals(new BigInteger("6"), c.getValue()); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import java.math.BigInteger; 27 | import org.junit.After; 28 | import org.junit.AfterClass; 29 | import org.junit.Before; 30 | import org.junit.BeforeClass; 31 | import org.junit.Test; 32 | import static org.junit.Assert.*; 33 | 34 | /** 35 | * Unit tests for the Item class. 36 | * 37 | * @author Harri Pellikka 38 | */ 39 | public class ItemTest 40 | { 41 | 42 | /** 43 | * Test of getName method, of class Item. 44 | */ 45 | @Test 46 | public void testName() 47 | { 48 | Item item = new ItemImpl(); 49 | item.setName("Test"); 50 | assertEquals("Test", item.getName()); 51 | } 52 | 53 | /** 54 | * Test of getDescription method, of class Item. 55 | */ 56 | @Test 57 | public void testDescription() 58 | { 59 | Item item = new ItemImpl(); 60 | item.setDescription("Description text here."); 61 | assertEquals("Description text here.", item.getDescription()); 62 | } 63 | 64 | /** 65 | * Test of getBasePrice method, of class Item. 66 | */ 67 | @Test 68 | public void testBasePrice() 69 | { 70 | Item item = new ItemImpl(); 71 | item.setBasePrice(10); 72 | assertEquals(new BigInteger("10"), item.getBasePrice()); 73 | } 74 | 75 | /** 76 | * Test of getPrice method, of class Item. 77 | */ 78 | @Test 79 | public void testPrice() 80 | { 81 | Item item = new ItemImpl(); 82 | 83 | item.setBasePrice(10); 84 | item.setPriceMultiplier(1.5); 85 | 86 | assertEquals(new BigInteger("10"), item.getPrice()); 87 | 88 | item.upgrade(); 89 | 90 | assertEquals(new BigInteger("15"), item.getPrice()); 91 | } 92 | 93 | /** 94 | * Test of buyWith method, of class Item. 95 | */ 96 | @Test 97 | public void testPurchase() 98 | { 99 | World world = new World(); 100 | Currency c = new Currency.Builder(world) 101 | .name("Gold") 102 | .build(); 103 | 104 | Generator g = new Generator.Builder(world) 105 | .baseAmount(1000) 106 | .price(500) 107 | .generate(c) 108 | .build(); 109 | 110 | assertEquals(BigInteger.ZERO, c.getValue()); 111 | 112 | PurchaseResult pr = g.buyWith(c); 113 | assertEquals(PurchaseResult.INSUFFICIENT_FUNDS, pr); 114 | 115 | g.upgrade(); 116 | g.process(); 117 | 118 | assertEquals(1, g.getItemLevel()); 119 | 120 | pr = g.buyWith(c); 121 | assertEquals(PurchaseResult.OK, pr); 122 | assertEquals(2, g.getItemLevel()); 123 | 124 | g.setMaxItemLevel(2); 125 | 126 | g.process(); 127 | pr = g.buyWith(c); 128 | assertEquals(PurchaseResult.MAX_LEVEL_REACHED, pr); 129 | assertEquals(2, g.getItemLevel()); 130 | } 131 | 132 | /** 133 | * Test of setBasePrice method, of class Item. 134 | */ 135 | @Test 136 | public void testSetBasePrice_BigInteger() 137 | { 138 | Item item = new ItemImpl(); 139 | item.setBasePrice(new BigInteger("1234")); 140 | assertEquals(new BigInteger("1234"), item.getBasePrice()); 141 | } 142 | 143 | /** 144 | * Test of setBasePrice method, of class Item. 145 | */ 146 | @Test 147 | public void testSetBasePrice_long() 148 | { 149 | Item item = new ItemImpl(); 150 | long price = 1234; 151 | item.setBasePrice(1234); 152 | assertEquals(new BigInteger("1234"), item.getBasePrice()); 153 | } 154 | 155 | /** 156 | * Test of setBasePrice method, of class Item. 157 | */ 158 | @Test 159 | public void testSetBasePrice_int() 160 | { 161 | Item item = new ItemImpl(); 162 | int price = 1234; 163 | item.setBasePrice(1234); 164 | assertEquals(new BigInteger("1234"), item.getBasePrice()); 165 | } 166 | 167 | /** 168 | * Test of getPriceMultiplier method, of class Item. 169 | */ 170 | @Test 171 | public void testPriceMultiplier() 172 | { 173 | Item item = new ItemImpl(); 174 | item.setPriceMultiplier(1.23); 175 | assertEquals(1.23, item.getPriceMultiplier(), 0.001); 176 | 177 | } 178 | 179 | /** 180 | * Test of getMaxItemLevel method, of class Item. 181 | */ 182 | @Test 183 | public void testMaxItemLevel() 184 | { 185 | Item item = new ItemImpl(); 186 | item.setMaxItemLevel(12); 187 | 188 | // Try to set the level greater than max level 189 | item.setItemLevel(14); 190 | assertEquals(12, item.getItemLevel()); 191 | 192 | item.setItemLevel(5); 193 | assertEquals(5, item.getItemLevel()); 194 | 195 | item.setItemLevel(12); 196 | assertEquals(12, item.getItemLevel()); 197 | 198 | item.upgrade(); 199 | assertEquals(12, item.getItemLevel()); 200 | 201 | item.setMaxItemLevel(13); 202 | assertEquals(12, item.getItemLevel()); 203 | 204 | item.upgrade(); 205 | assertEquals(13, item.getItemLevel()); 206 | } 207 | 208 | /** 209 | * Test of upgrade method, of class Item. 210 | */ 211 | @Test 212 | public void testUpgradeDowngradeMaximize() 213 | { 214 | Item item = new ItemImpl(); 215 | assertEquals(0, item.getItemLevel()); 216 | item.upgrade(); 217 | assertEquals(1, item.getItemLevel()); 218 | item.upgrade(); 219 | assertEquals(2, item.getItemLevel()); 220 | item.downgrade(); 221 | assertEquals(1, item.getItemLevel()); 222 | item.downgrade(); 223 | assertEquals(0, item.getItemLevel()); 224 | item.downgrade(); 225 | assertEquals(0, item.getItemLevel()); 226 | 227 | item.setMaxItemLevel(10); 228 | item.maximize(); 229 | assertEquals(item.getMaxItemLevel(), item.getItemLevel()); 230 | } 231 | 232 | public class ItemImpl extends Item 233 | { 234 | 235 | public ItemImpl() 236 | { 237 | super(null); 238 | } 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import java.math.BigInteger; 27 | import org.junit.Test; 28 | import static org.junit.Assert.*; 29 | 30 | /** 31 | * Unit tests for modifiers 32 | * 33 | * @author Harri Pellikka 34 | */ 35 | public class ModifierTest 36 | { 37 | /** 38 | * Test of enable method, of class Modifier. 39 | */ 40 | @Test 41 | public void testSingleWorldSpeedModifier() 42 | { 43 | System.out.println("testWorldModifier()"); 44 | World w = new World(); 45 | assertEquals(1.0, w.getSpeedMultiplier(), 0.01); 46 | 47 | Modifier m = new Modifier.Builder() 48 | .modify(w) 49 | .speedBy(2.0) 50 | .build(); 51 | 52 | m.enable(); 53 | 54 | assertEquals(1.0 * 2.0, w.getSpeedMultiplier(), 0.01); 55 | 56 | m.disable(); 57 | 58 | assertEquals(1.0, w.getSpeedMultiplier(), 0.01); 59 | } 60 | 61 | @Test 62 | public void testMultipleWorldSpeedModifiers() 63 | { 64 | System.out.println("test multiple speed by"); 65 | World w = new World(); 66 | 67 | Modifier m = new Modifier.Builder() 68 | .modify(w) 69 | .speedBy(2.0) 70 | .build(); 71 | 72 | Modifier m2 = new Modifier.Builder() 73 | .modify(w) 74 | .speedBy(3.0) 75 | .build(); 76 | 77 | m.enable(); 78 | m2.enable(); 79 | 80 | assertEquals(1.0 * 2.0 * 3.0, w.getSpeedMultiplier(), 0.01); 81 | 82 | m.disable(); 83 | 84 | assertEquals(1.0 * 3.0, w.getSpeedMultiplier(), 0.01); 85 | 86 | m2.disable(); 87 | 88 | assertEquals(1.0, w.getSpeedMultiplier(), 0.01); 89 | } 90 | 91 | @Test 92 | public void testDisableAllAutomators() 93 | { 94 | World w = new World(); 95 | 96 | Currency c = new Currency.Builder(w) 97 | .name("Gold") 98 | .build(); 99 | 100 | Generator g = new Generator.Builder(w) 101 | .generate(c) 102 | .baseAmount(1) 103 | .build(); 104 | g.upgrade(); 105 | 106 | Automator a = new Automator.Builder(w) 107 | .automate(g) 108 | .every(1.0) 109 | .build(); 110 | a.upgrade(); 111 | 112 | assertEquals(BigInteger.ZERO, c.getValue()); 113 | 114 | w.update(10.0); 115 | 116 | assertEquals(new BigInteger("10"), c.getValue()); 117 | 118 | Modifier m = new Modifier.Builder() 119 | .modify(w) 120 | .disableActivators() 121 | .build(); 122 | 123 | m.enable(); 124 | 125 | w.update(10.0); 126 | 127 | assertEquals(new BigInteger("10"), c.getValue()); 128 | 129 | m.disable(); 130 | 131 | w.update(10.0); 132 | 133 | assertEquals(new BigInteger("20"), c.getValue()); 134 | } 135 | 136 | @Test 137 | public void testSpeedGenerators() 138 | { 139 | World w = new World(); 140 | Currency c = new Currency.Builder(w) 141 | .name("Gold") 142 | .build(); 143 | 144 | Generator g = new Generator.Builder(w) 145 | .baseAmount(1) 146 | .generate(c) 147 | .build(); 148 | g.upgrade(); 149 | 150 | g.process(); 151 | 152 | assertEquals(BigInteger.ONE, c.getValue()); 153 | 154 | Modifier m = new Modifier.Builder() 155 | .modify(g) 156 | .multiplier(2.0) 157 | .build(); 158 | m.enable(); 159 | 160 | g.process(); 161 | assertEquals(new BigInteger("3"), c.getValue()); 162 | 163 | m.disable(); 164 | g.process(); 165 | assertEquals(new BigInteger("4"), c.getValue()); 166 | } 167 | 168 | /** 169 | * Test of isEnabled method, of class Modifier. 170 | */ 171 | @Test 172 | public void testIsEnabled() 173 | { 174 | System.out.println("isEnabled"); 175 | 176 | World w = new World(); 177 | 178 | Modifier m = new Modifier.Builder() 179 | .modify(w) 180 | .build(); 181 | 182 | assertFalse(m.isEnabled()); 183 | m.enable(); 184 | assertTrue(m.isEnabled()); 185 | m.disable(); 186 | assertFalse(m.isEnabled()); 187 | } 188 | 189 | } 190 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import org.junit.Test; 27 | import static org.junit.Assert.*; 28 | 29 | /** 30 | * 31 | * @author Harri 32 | */ 33 | public class NumberFormatterTest 34 | { 35 | 36 | public NumberFormatterTest() 37 | { 38 | } 39 | 40 | @Test 41 | public void testBigIntegerFormatting() 42 | { 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/com/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 com.manabreak.libclicker; 25 | 26 | import java.io.ByteArrayInputStream; 27 | import java.io.ByteArrayOutputStream; 28 | import java.io.IOException; 29 | import java.io.ObjectInputStream; 30 | import java.io.ObjectOutputStream; 31 | import java.math.BigInteger; 32 | import org.junit.Test; 33 | import static org.junit.Assert.*; 34 | 35 | /** 36 | * 37 | * @author Harri 38 | */ 39 | public class SerializationTest 40 | { 41 | 42 | @Test 43 | public void testSerialization() throws IOException, ClassNotFoundException 44 | { 45 | String currencyName = "Serialized Gold"; 46 | String generatorName = "Serialized Gold Generator"; 47 | int genBaseAmount = 1234; 48 | double genMultiplier = 1.34; 49 | int genMaxLevel = 42; 50 | int genLevel = 13; 51 | 52 | World world = new World(); 53 | Currency gold = new Currency.Builder(world) 54 | .name(currencyName) 55 | .build(); 56 | 57 | Generator gen = new Generator.Builder(world) 58 | .baseAmount(genBaseAmount) 59 | .multiplier(genMultiplier) 60 | .maxLevel(genMaxLevel) 61 | .generate(gold) 62 | .build(); 63 | 64 | for(int i = 0; i < genLevel; ++i) 65 | { 66 | gen.upgrade(); 67 | } 68 | 69 | Automator a = new Automator.Builder(world) 70 | .automate(gen) 71 | .every(2.3) 72 | .build(); 73 | 74 | gen.process(); 75 | 76 | Modifier mWorld = new Modifier.Builder() 77 | .modify(world) 78 | .disableActivators() 79 | .speedBy(3.5) 80 | .build(); 81 | mWorld.enable(); 82 | 83 | Modifier mGen = new Modifier.Builder() 84 | .modify(gen) 85 | .multiplier(4.2) 86 | .build(); 87 | mGen.enable(); 88 | 89 | BigInteger goldBeforeSerialization = gold.getValue(); 90 | 91 | /* SERIALIZATION */ 92 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 93 | ObjectOutputStream oos = new ObjectOutputStream(bos); 94 | oos.writeObject(world); 95 | 96 | byte[] bytes = bos.toByteArray(); 97 | oos.close(); 98 | 99 | /* DESERIALIZATION */ 100 | ByteArrayInputStream bis = new ByteArrayInputStream(bytes); 101 | ObjectInputStream ois = new ObjectInputStream(bis); 102 | World newWorld = (World)ois.readObject(); 103 | 104 | assertEquals(world.getGeneratorCount(), newWorld.getGeneratorCount()); 105 | assertEquals(world.getCurrencies().size(), newWorld.getCurrencies().size()); 106 | assertEquals(world.getAutomators().size(), newWorld.getAutomators().size()); 107 | assertEquals(world.getModifiers().size(), newWorld.getModifiers().size()); 108 | assertEquals(world.getSpeedMultiplier(), newWorld.getSpeedMultiplier(), 0.001); 109 | assertEquals(world.isAutomationEnabled(), newWorld.isAutomationEnabled()); 110 | 111 | for(int i = 0; i < world.getCurrencies().size(); ++i) 112 | { 113 | assertEquals(world.getCurrency(i).getName(), newWorld.getCurrency(i).getName()); 114 | assertEquals(world.getCurrency(i).getValue(), newWorld.getCurrency(i).getValue()); 115 | } 116 | 117 | for(int i = 0; i < world.getAutomators().size(); ++i) 118 | { 119 | Automator a0 = world.getAutomators().get(i); 120 | Automator a1 = newWorld.getAutomators().get(i); 121 | assertEquals(a0.getBasePrice(), a1.getBasePrice()); 122 | assertEquals(a0.getDescription(), a1.getDescription()); 123 | assertEquals(a0.getItemLevel(), a1.getItemLevel()); 124 | assertEquals(a0.getMaxItemLevel(), a1.getMaxItemLevel()); 125 | assertEquals(a0.getName(), a1.getName()); 126 | assertEquals(a0.getPrice(), a1.getPrice()); 127 | assertEquals(a0.getPriceMultiplier(), a1.getPriceMultiplier(), 0.001); 128 | assertEquals(a0.getTickRate(), a1.getTickRate(), 0.001); 129 | assertEquals(a0.getTimerPercentage(), a1.getTimerPercentage(), 0.001); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /test/com/manabreak/libclicker/WorldTest.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 com.manabreak.libclicker; 25 | 26 | import static junit.framework.Assert.assertEquals; 27 | import org.junit.Test; 28 | import static org.junit.Assert.*; 29 | 30 | /** 31 | * 32 | * @author Harri Pellikka 33 | */ 34 | public class WorldTest 35 | { 36 | /** 37 | * Test of addGenerator method, of class World. 38 | */ 39 | @Test 40 | public void testGenerators() 41 | { 42 | System.out.println("Add / remove generators"); 43 | 44 | 45 | } 46 | 47 | } 48 | --------------------------------------------------------------------------------