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