summaryrefslogtreecommitdiff
path: root/game-engine/src/main
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2018-07-07 16:27:47 +0200
committerjbion <joffrey.bion@amadeus.com>2018-07-07 23:40:44 +0200
commitb30630782ee35cfed275217324f28285ad39d715 (patch)
treebda9944ccf95b25c602408580b8c536cbeb009ab /game-engine/src/main
parentKotlin mig: Game class (diff)
downloadseven-wonders-b30630782ee35cfed275217324f28285ad39d715.tar.gz
seven-wonders-b30630782ee35cfed275217324f28285ad39d715.tar.bz2
seven-wonders-b30630782ee35cfed275217324f28285ad39d715.zip
Kotlin mig: effects package
Diffstat (limited to 'game-engine/src/main')
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java86
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java44
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java11
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java40
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java20
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java40
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java54
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java40
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java22
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java47
-rw-r--r--game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java26
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializer.kt14
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt2
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt2
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt2
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.kt4
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt33
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt19
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt (renamed from game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java)10
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt9
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt8
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt14
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt8
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt14
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt8
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt9
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt40
-rw-r--r--game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt10
28 files changed, 186 insertions, 450 deletions
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java
deleted file mode 100644
index e9f9fe5f..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.List;
-
-import org.luxons.sevenwonders.game.api.Table;
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.boards.BoardElementType;
-import org.luxons.sevenwonders.game.boards.RelativeBoardPosition;
-import org.luxons.sevenwonders.game.cards.Color;
-
-public class BonusPerBoardElement implements Effect {
-
- private List<RelativeBoardPosition> boards;
-
- private int gold;
-
- private int points;
-
- private BoardElementType type;
-
- // only relevant if type=CARD
- private List<Color> colors;
-
- public List<RelativeBoardPosition> getBoards() {
- return boards;
- }
-
- public void setBoards(List<RelativeBoardPosition> boards) {
- this.boards = boards;
- }
-
- public int getGold() {
- return gold;
- }
-
- public void setGold(int gold) {
- this.gold = gold;
- }
-
- public int getPoints() {
- return points;
- }
-
- public void setPoints(int points) {
- this.points = points;
- }
-
- public BoardElementType getType() {
- return type;
- }
-
- public void setType(BoardElementType type) {
- this.type = type;
- }
-
- public List<Color> getColors() {
- return colors;
- }
-
- public void setColors(List<Color> colors) {
- this.colors = colors;
- }
-
- @Override
- public void apply(Table table, int playerIndex) {
- int goldGain = gold * computeNbOfMatchingElementsIn(table, playerIndex);
- Board board = table.getBoard(playerIndex);
- board.addGold(goldGain);
- }
-
- @Override
- public int computePoints(Table table, int playerIndex) {
- return points * computeNbOfMatchingElementsIn(table, playerIndex);
- }
-
- private int computeNbOfMatchingElementsIn(Table table, int playerIndex) {
- return boards.stream()
- .map(pos -> table.getBoard(playerIndex, pos))
- .mapToInt(this::computeNbOfMatchingElementsIn)
- .sum();
- }
-
- private int computeNbOfMatchingElementsIn(Board board) {
- return type.getElementCount(board, colors);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java
deleted file mode 100644
index 976ebf35..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Discount.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.resources.Provider;
-import org.luxons.sevenwonders.game.resources.ResourceType;
-import org.luxons.sevenwonders.game.resources.TradingRules;
-
-public class Discount extends InstantOwnBoardEffect {
-
- private final List<ResourceType> resourceTypes = new ArrayList<>();
-
- private final List<Provider> providers = new ArrayList<>();
-
- private int discountedPrice = 1;
-
- public List<ResourceType> getResourceTypes() {
- return resourceTypes;
- }
-
- public List<Provider> getProviders() {
- return providers;
- }
-
- public int getDiscountedPrice() {
- return discountedPrice;
- }
-
- public void setDiscountedPrice(int discountedPrice) {
- this.discountedPrice = discountedPrice;
- }
-
- @Override
- public void apply(Board board) {
- TradingRules rules = board.getTradingRules();
- for (ResourceType type : resourceTypes) {
- for (Provider provider : providers) {
- rules.setCost(type, provider, discountedPrice);
- }
- }
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java
deleted file mode 100644
index 1bae16a6..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/EndGameEffect.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import org.luxons.sevenwonders.game.api.Table;
-
-public abstract class EndGameEffect implements Effect {
-
- @Override
- public void apply(Table table, int playerIndex) {
- // EndGameEffects don't do anything when applied to the board, they simply give more points in the end
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
deleted file mode 100644
index 4c1215d4..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.Objects;
-
-import org.luxons.sevenwonders.game.boards.Board;
-
-public class GoldIncrease extends InstantOwnBoardEffect {
-
- private final int amount;
-
- public GoldIncrease(int amount) {
- this.amount = amount;
- }
-
- public int getAmount() {
- return amount;
- }
-
- @Override
- public void apply(Board board) {
- board.addGold(amount);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- GoldIncrease that = (GoldIncrease) o;
- return amount == that.amount;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(amount);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java
deleted file mode 100644
index 8f4340cf..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import org.luxons.sevenwonders.game.api.Table;
-import org.luxons.sevenwonders.game.boards.Board;
-
-public abstract class InstantOwnBoardEffect implements Effect {
-
- @Override
- public void apply(Table table, int playerIndex) {
- apply(table.getBoard(playerIndex));
- }
-
- protected abstract void apply(Board board);
-
- @Override
- public int computePoints(Table table, int playerIndex) {
- // InstantEffects are only important when applied to the board, they don't give extra points in the end
- return 0;
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
deleted file mode 100644
index 7da112f5..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.Objects;
-
-import org.luxons.sevenwonders.game.boards.Board;
-
-public class MilitaryReinforcements extends InstantOwnBoardEffect {
-
- private final int count;
-
- public MilitaryReinforcements(int count) {
- this.count = count;
- }
-
- public int getCount() {
- return count;
- }
-
- @Override
- public void apply(Board board) {
- board.getMilitary().addShields(count);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- MilitaryReinforcements that = (MilitaryReinforcements) o;
- return count == that.count;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(count);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
deleted file mode 100644
index 514c65db..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.Objects;
-
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.resources.Production;
-
-public class ProductionIncrease extends InstantOwnBoardEffect {
-
- private Production production = new Production();
-
- private boolean sellable = true;
-
- public Production getProduction() {
- return production;
- }
-
- public void setProduction(Production production) {
- this.production = production;
- }
-
- public boolean isSellable() {
- return sellable;
- }
-
- public void setSellable(boolean sellable) {
- this.sellable = sellable;
- }
-
- @Override
- public void apply(Board board) {
- board.getProduction().addAll(production);
- if (sellable) {
- board.getPublicProduction().addAll(production);
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- ProductionIncrease that = (ProductionIncrease) o;
- return Objects.equals(production, that.production);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(production);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
deleted file mode 100644
index 9a5d66ed..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.Objects;
-
-import org.luxons.sevenwonders.game.api.Table;
-
-public class RawPointsIncrease extends EndGameEffect {
-
- private final int points;
-
- public RawPointsIncrease(int points) {
- this.points = points;
- }
-
- public int getPoints() {
- return points;
- }
-
- @Override
- public int computePoints(Table table, int playerIndex) {
- return points;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- RawPointsIncrease that = (RawPointsIncrease) o;
- return points == that.points;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(points);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java
deleted file mode 100644
index 4e6764ee..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/ScienceProgress.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.boards.Science;
-
-public class ScienceProgress extends InstantOwnBoardEffect {
-
- private Science science;
-
- public Science getScience() {
- return science;
- }
-
- public void setScience(Science science) {
- this.science = science;
- }
-
- @Override
- public void apply(Board board) {
- board.getScience().addAll(science);
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java
deleted file mode 100644
index cdf67f20..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbility.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import org.luxons.sevenwonders.game.api.Table;
-import org.luxons.sevenwonders.game.boards.Board;
-import org.luxons.sevenwonders.game.cards.Card;
-
-public enum SpecialAbility {
-
- /**
- * The player can play the last card of each age instead of discarding it. This card can be played by paying its
- * cost, discarded to gain 3 coins or used in the construction of his or her Wonder.
- */
- PLAY_LAST_CARD,
-
- /**
- * Once per age, a player can construct a building from his or her hand for free.
- */
- ONE_FREE_PER_AGE,
-
- /**
- * The player can look at all cards discarded since the beginning of the game, pick one and build it for free.
- */
- PLAY_DISCARDED,
-
- /**
- * The player can, at the end of the game, "copy" a Guild of his or her choice (purple card), built by one of his or
- * her two neighboring cities.
- */
- COPY_GUILD {
- @Override
- public int computePoints(Table table, int playerIndex) {
- Card copiedGuild = table.getBoard(playerIndex).getCopiedGuild();
- if (copiedGuild == null) {
- throw new IllegalStateException("The copied Guild has not been chosen, cannot compute points");
- }
- return copiedGuild.getEffects().stream().mapToInt(e -> e.computePoints(table, playerIndex)).sum();
- }
- };
-
- protected void apply(Board board) {
- board.addSpecial(this);
- }
-
- public int computePoints(Table table, int playerIndex) {
- return 0;
- }
-}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java b/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java
deleted file mode 100644
index a5953c2f..00000000
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import org.luxons.sevenwonders.game.api.Table;
-
-public class SpecialAbilityActivation implements Effect {
-
- private final SpecialAbility specialAbility;
-
- public SpecialAbilityActivation(SpecialAbility specialAbility) {
- this.specialAbility = specialAbility;
- }
-
- public SpecialAbility getSpecialAbility() {
- return specialAbility;
- }
-
- @Override
- public void apply(Table table, int playerIndex) {
- specialAbility.apply(table.getBoard(playerIndex));
- }
-
- @Override
- public int computePoints(Table table, int playerIndex) {
- return specialAbility.computePoints(table, playerIndex);
- }
-}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializer.kt
index 578f816b..112c0adc 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializer.kt
@@ -29,20 +29,16 @@ class ProductionIncreaseSerializer : JsonSerializer<ProductionIncrease>, JsonDes
typeOfT: Type,
context: JsonDeserializationContext
): ProductionIncrease {
- var json = json
- val productionIncrease = ProductionIncrease()
+ var prodJson = json
- var resourcesStr = json.asString
+ var resourcesStr = prodJson.asString
val isSellable = !resourcesStr.startsWith("(")
if (!isSellable) {
resourcesStr = unwrapBrackets(resourcesStr)
- json = JsonPrimitive(resourcesStr)
+ prodJson = JsonPrimitive(resourcesStr)
}
- productionIncrease.isSellable = isSellable
-
- val production = context.deserialize<Production>(json, Production::class.java)
- productionIncrease.production = production
- return productionIncrease
+ val production = context.deserialize<Production>(prodJson, Production::class.java)
+ return ProductionIncrease(production, isSellable)
}
private fun unwrapBrackets(str: String): String {
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt
index 1de9334a..74dee483 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializer.kt
@@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
-internal class ResourceTypeSerializer : JsonSerializer<ResourceType>, JsonDeserializer<ResourceType> {
+class ResourceTypeSerializer : JsonSerializer<ResourceType>, JsonDeserializer<ResourceType> {
override fun serialize(type: ResourceType, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
return JsonPrimitive(type.symbol!!)
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt
index 9ba21043..75fcabf0 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializer.kt
@@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
-internal class ResourceTypesSerializer : JsonSerializer<List<ResourceType>>, JsonDeserializer<List<ResourceType>> {
+class ResourceTypesSerializer : JsonSerializer<List<ResourceType>>, JsonDeserializer<List<ResourceType>> {
override fun serialize(
resources: List<ResourceType>,
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt
index 2baf7a35..0a60e4cf 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializer.kt
@@ -15,7 +15,7 @@ import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
-internal class ResourcesSerializer : JsonSerializer<Resources>, JsonDeserializer<Resources> {
+class ResourcesSerializer : JsonSerializer<Resources>, JsonDeserializer<Resources> {
override fun serialize(resources: Resources, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
val s = resources.asList().map { it.symbol }.joinToString("")
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.kt
index ed383d63..46ebeb25 100644
--- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.kt
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.kt
@@ -39,15 +39,13 @@ internal class ScienceProgressSerializer : JsonSerializer<ScienceProgress>, Json
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): ScienceProgress {
val s = json.asString
- val scienceProgress = ScienceProgress()
val science = Science()
if ("any" == s) {
science.addJoker(1)
} else {
science.add(deserializeScienceType(json, context), 1)
}
- scienceProgress.science = science
- return scienceProgress
+ return ScienceProgress(science)
}
private fun deserializeScienceType(json: JsonElement, context: JsonDeserializationContext): ScienceType {
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt
new file mode 100644
index 00000000..104dfc77
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElement.kt
@@ -0,0 +1,33 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.boards.Board
+import org.luxons.sevenwonders.game.boards.BoardElementType
+import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
+import org.luxons.sevenwonders.game.cards.Color
+
+data class BonusPerBoardElement (
+ val boards: List<RelativeBoardPosition>,
+ val type: BoardElementType,
+ val gold: Int = 0,
+ val points: Int = 0,
+ // only relevant if type=CARD
+ val colors: List<Color>? = null
+) : Effect {
+
+ override fun apply(table: Table, playerIndex: Int) {
+ val goldGain = gold * computeNbOfMatchingElementsIn(table, playerIndex)
+ val board = table.getBoard(playerIndex)
+ board.addGold(goldGain)
+ }
+
+ override fun computePoints(table: Table, playerIndex: Int): Int =
+ points * computeNbOfMatchingElementsIn(table, playerIndex)
+
+ private fun computeNbOfMatchingElementsIn(table: Table, playerIndex: Int): Int = boards
+ .map { pos -> table.getBoard(playerIndex, pos) }
+ .map(::computeNbOfMatchingElementsIn)
+ .sum()
+
+ private fun computeNbOfMatchingElementsIn(board: Board): Int = type.getElementCount(board, colors)
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt
new file mode 100644
index 00000000..b1455397
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Discount.kt
@@ -0,0 +1,19 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.boards.Board
+import org.luxons.sevenwonders.game.resources.Provider
+import org.luxons.sevenwonders.game.resources.ResourceType
+
+data class Discount(
+ val resourceTypes: List<ResourceType> = emptyList(),
+ val providers: List<Provider> = emptyList(),
+ val discountedPrice: Int = 1
+) : InstantOwnBoardEffect() {
+
+ public override fun apply(board: Board) {
+ val rules = board.tradingRules
+ for (type in resourceTypes) {
+ providers.forEach { rules.setCost(type, it, discountedPrice) }
+ }
+ }
+}
diff --git a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt
index 692eaea0..3bf48086 100644
--- a/game-engine/src/main/java/org/luxons/sevenwonders/game/effects/Effect.java
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/Effect.kt
@@ -1,15 +1,15 @@
-package org.luxons.sevenwonders.game.effects;
+package org.luxons.sevenwonders.game.effects
-import org.luxons.sevenwonders.game.api.Table;
+import org.luxons.sevenwonders.game.api.Table
/**
* Represents an effect than can be applied to a player's board when playing a card or building his wonder. The effect
* may affect (or depend on) the adjacent boards. It can have an instantaneous effect on the board, or be postponed to
* the end of game where point calculations take place.
*/
-public interface Effect {
+interface Effect {
- void apply(Table table, int playerIndex);
+ fun apply(table: Table, playerIndex: Int)
- int computePoints(Table table, int playerIndex);
+ fun computePoints(table: Table, playerIndex: Int): Int
}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt
new file mode 100644
index 00000000..392f53b9
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/EndGameEffect.kt
@@ -0,0 +1,9 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.api.Table
+
+abstract class EndGameEffect : Effect {
+
+ // EndGameEffects don't do anything when applied to the board, they simply give more points in the end
+ override fun apply(table: Table, playerIndex: Int) = Unit
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt
new file mode 100644
index 00000000..0d206231
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/GoldIncrease.kt
@@ -0,0 +1,8 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.boards.Board
+
+data class GoldIncrease(val amount: Int) : InstantOwnBoardEffect() {
+
+ public override fun apply(board: Board) = board.addGold(amount)
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt
new file mode 100644
index 00000000..fb26dcce
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.kt
@@ -0,0 +1,14 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.boards.Board
+
+abstract class InstantOwnBoardEffect : Effect {
+
+ override fun apply(table: Table, playerIndex: Int) = apply(table.getBoard(playerIndex))
+
+ protected abstract fun apply(board: Board)
+
+ // InstantEffects are only important when applied to the board, they don't give extra points in the end
+ override fun computePoints(table: Table, playerIndex: Int): Int = 0
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt
new file mode 100644
index 00000000..ad4d64eb
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.kt
@@ -0,0 +1,8 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.boards.Board
+
+data class MilitaryReinforcements(val count: Int) : InstantOwnBoardEffect() {
+
+ public override fun apply(board: Board) = board.military.addShields(count)
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt
new file mode 100644
index 00000000..aa56705e
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncrease.kt
@@ -0,0 +1,14 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.boards.Board
+import org.luxons.sevenwonders.game.resources.Production
+
+data class ProductionIncrease(val production: Production, val isSellable: Boolean) : InstantOwnBoardEffect() {
+
+ public override fun apply(board: Board) {
+ board.production.addAll(production)
+ if (isSellable) {
+ board.publicProduction.addAll(production)
+ }
+ }
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt
new file mode 100644
index 00000000..ed6eb332
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncrease.kt
@@ -0,0 +1,8 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.api.Table
+
+data class RawPointsIncrease(val points: Int) : EndGameEffect() {
+
+ override fun computePoints(table: Table, playerIndex: Int): Int = points
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt
new file mode 100644
index 00000000..850f8ec3
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgress.kt
@@ -0,0 +1,9 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.boards.Board
+import org.luxons.sevenwonders.game.boards.Science
+
+class ScienceProgress(val science: Science) : InstantOwnBoardEffect() {
+
+ public override fun apply(board: Board) = board.science.addAll(science)
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt
new file mode 100644
index 00000000..30d57e27
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbility.kt
@@ -0,0 +1,40 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.boards.Board
+import org.luxons.sevenwonders.game.cards.Card
+
+enum class SpecialAbility {
+
+ /**
+ * The player can play the last card of each age instead of discarding it. This card can be played by paying its
+ * cost, discarded to gain 3 coins or used in the construction of his or her Wonder.
+ */
+ PLAY_LAST_CARD,
+
+ /**
+ * Once per age, a player can construct a building from his or her hand for free.
+ */
+ ONE_FREE_PER_AGE,
+
+ /**
+ * The player can look at all cards discarded since the beginning of the game, pick one and build it for free.
+ */
+ PLAY_DISCARDED,
+
+ /**
+ * The player can, at the end of the game, "copy" a Guild of his or her choice (purple card), built by one of his or
+ * her two neighboring cities.
+ */
+ COPY_GUILD {
+ override fun computePoints(table: Table, playerIndex: Int): Int {
+ val copiedGuild = table.getBoard(playerIndex).copiedGuild
+ ?: throw IllegalStateException("The copied Guild has not been chosen, cannot compute points")
+ return copiedGuild.effects.stream().mapToInt { e -> e.computePoints(table, playerIndex) }.sum()
+ }
+ };
+
+ fun apply(board: Board) = board.addSpecial(this)
+
+ open fun computePoints(table: Table, playerIndex: Int): Int = 0
+}
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt
new file mode 100644
index 00000000..fd83d7fe
--- /dev/null
+++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivation.kt
@@ -0,0 +1,10 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.luxons.sevenwonders.game.api.Table
+
+data class SpecialAbilityActivation(val specialAbility: SpecialAbility) : Effect {
+
+ override fun apply(table: Table, playerIndex: Int) = specialAbility.apply(table.getBoard(playerIndex))
+
+ override fun computePoints(table: Table, playerIndex: Int): Int = specialAbility.computePoints(table, playerIndex)
+}
bgstack15