From c2eb9b17236eef6f9a7d6a709e63451e1be56f9a Mon Sep 17 00:00:00 2001 From: Leonard <Leonard@Leonard.Leo> Date: Fri, 29 May 2020 18:31:07 +0300 Subject: [PATCH] added services, modified trader in model --- .../Model/Map/Planet.java | 4 + .../Model/Map/Trader.java | 32 +++++- .../Exception/DuplicateTraderException.java | 4 + .../Exception/TraderNotFoundException.java | 4 + .../Server/Persistence/TraderDAO.java | 43 ++++++++ .../Server/Services/BattleService.java | 4 + .../Server/Services/PlanetEventService.java | 22 +++-- .../Server/Services/RewardService.java | 75 +++++++++++--- .../Server/Services/TraderService.java | 97 +++++++++++++++++++ 9 files changed, 256 insertions(+), 29 deletions(-) create mode 100644 core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/DuplicateTraderException.java create mode 100644 core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/TraderNotFoundException.java create mode 100644 core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Persistence/TraderDAO.java create mode 100644 core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TraderService.java diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Planet.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Planet.java index 9c0973c8..7e51cccf 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Planet.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Planet.java @@ -52,4 +52,8 @@ public class Planet implements Serializable { @DatabaseField(foreign = true, columnName = "ships") @NonNull private List<Ship> ships; + + /** Trader */ + @DatabaseField(foreign = true) + private Trader trader; } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Trader.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Trader.java index ceaad3b8..71dcf63f 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Trader.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Model/Map/Trader.java @@ -1,23 +1,47 @@ package com.galaxytrucker.galaxytruckerreloaded.Model.Map; import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.galaxytrucker.galaxytruckerreloaded.Model.Crew.Crew; import com.galaxytrucker.galaxytruckerreloaded.Model.Weapons.Weapon; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; +import lombok.*; import java.io.Serializable; @Getter @Setter -@DatabaseTable +@DatabaseTable(tableName = "trader") +@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +@NoArgsConstructor(access = AccessLevel.PUBLIC) public class Trader extends Planet implements Serializable { + /** ID */ + @DatabaseField(id = true) + private int id; + + /** Associated user */ + @DatabaseField + private String associatedUser; + /** Weapons for sale */ @DatabaseField(foreign = true) @NonNull private List<Weapon> weaponsForSale; + /** Rockets for sale */ + @DatabaseField + @NonNull + private int rocketStock; + + /** Fuel for sale */ + @DatabaseField + @NonNull + private int fuelStock; + + /** Crew for sale */ + @DatabaseField(foreign = true) + @NonNull + private List<Crew> crewStock; + } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/DuplicateTraderException.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/DuplicateTraderException.java new file mode 100644 index 00000000..958f43bb --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/DuplicateTraderException.java @@ -0,0 +1,4 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Exception; + +public class DuplicateTraderException extends Exception { +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/TraderNotFoundException.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/TraderNotFoundException.java new file mode 100644 index 00000000..5c86808a --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Exception/TraderNotFoundException.java @@ -0,0 +1,4 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Exception; + +public class TraderNotFoundException extends Exception { +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Persistence/TraderDAO.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Persistence/TraderDAO.java new file mode 100644 index 00000000..473bcede --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Persistence/TraderDAO.java @@ -0,0 +1,43 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Persistence; + +import com.galaxytrucker.galaxytruckerreloaded.Model.Map.Trader; +import com.galaxytrucker.galaxytruckerreloaded.Server.Exception.DuplicateTraderException; +import com.galaxytrucker.galaxytruckerreloaded.Server.Exception.TraderNotFoundException; + +/** + * This class handles trader objects in the database + */ +public class TraderDAO extends ObjectDAO<Trader> { + + /** + * Add a new trader to the database + * + * @param t - the trader to add + * @throws DuplicateTraderException if the trader already exists in the database + */ + @Override + public void persist(Trader t) throws DuplicateTraderException { + + } + + /** + * Edit an existing trader in the database + * + * @param t - the trader to edit + * @throws TraderNotFoundException if the trader cannot be found in the database + */ + public void edit(Trader t) throws TraderNotFoundException { + + } + + /** + * Remove an existing trader from the database + * + * @param t - the trader to remove + * @throws TraderNotFoundException if the trader cannot be found in the database + */ + @Override + public void remove(Trader t) throws TraderNotFoundException { + + } +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java index 30d86500..d925996d 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java @@ -42,6 +42,10 @@ public class BattleService { /** Disabled system round counter */ private int disabledSystemCounter = 3; + /** Reward service */ + @NonNull + private RewardService rewardService; + /** Change the ship which's round it is */ public void nextRound(){} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java index bcce1d13..80721faa 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java @@ -1,6 +1,7 @@ package com.galaxytrucker.galaxytruckerreloaded.Server.Services; import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.galaxytrucker.galaxytruckerreloaded.Model.Crew.Crew; import com.galaxytrucker.galaxytruckerreloaded.Model.Map.PlanetEvent; import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; import com.galaxytrucker.galaxytruckerreloaded.Model.Weapons.Weapon; @@ -10,6 +11,7 @@ import lombok.*; @Getter @Setter @RequiredArgsConstructor(access = AccessLevel.PUBLIC) +@NoArgsConstructor(access = AccessLevel.PUBLIC) public class PlanetEventService { /** Type of planet event currently happening */ @@ -20,6 +22,9 @@ public class PlanetEventService { @NonNull private ShipDAO shipDAO; + /** RewardService */ + private RewardService rewardService; + /** Round counter (meteorShower/Nebula) */ private int roundCounter = 0; @@ -33,18 +38,17 @@ public class PlanetEventService { * @param amount - the amount of coins to remove */ public void removeCoins(Ship s,int amount){} - /** Give the player a weapon as loot + /** Give the player some loot * @param s - the ship to give the reward to - * @param weapons - list of possible drops */ - public void giveWeapon(Ship s, List<Weapon> weapons){} - - /** Trader shop - * @return a list of all available stock */ - public List<Weapon> getTraderStock(){ - return null; - } + * @param dropTable - list of possible drops + * @param crewDropTable - list of possible crew drops */ + public void giveLoot(Ship s, List<Weapon> dropTable, List<Crew> crewDropTable){} /** MeteorShower damage * @param s - the player in the meteorShower */ private void meteorShower(Ship s){} + + /** Disable systems when in nebula + * @param s - the ship which's systems to disable */ + public void disableSystemsInNebula(Ship s, int duration){} } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java index d17afc87..b3e2df42 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java @@ -1,52 +1,95 @@ package com.galaxytrucker.galaxytruckerreloaded.Server.Services; import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.galaxytrucker.galaxytruckerreloaded.Model.Crew.Crew; import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; import com.galaxytrucker.galaxytruckerreloaded.Model.Weapons.Weapon; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.CrewDAO; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.RoomDAO; import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.ShipDAO; import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.WeaponDAO; import lombok.*; -/** This class handles reward handing to players */ +/** + * This class handles reward handing to players + */ @RequiredArgsConstructor(access = AccessLevel.PUBLIC) @Getter @Setter public class RewardService { - /** ShipDAO */ + /** + * ShipDAO + */ @NonNull private ShipDAO shipDAO; - /** WeaponDAO */ + /** + * WeaponDAO + */ @NonNull private WeaponDAO weaponDAO; - /** Weapon reward - * @param s - the ship to give reward to + /** + * Room DAO + */ + @NonNull + private RoomDAO roomDAO; + + /** + * Crew DAO + */ + @NonNull + private CrewDAO crewDAO; + + /** + * Weapon reward + * + * @param s - the ship to give reward to * @param dropTable - possible weapon drops - * @return the weapon given */ - public Weapon weaponReward(Ship s, List<Weapon> dropTable){ + * @return the weapon given + */ + public Weapon weaponReward(Ship s, List<Weapon> dropTable) { return null; } - /** Coin reward + /** + * Coin reward + * * @param s - the ship to give reward to - * @param c - the coins to give it */ - public void coinsReward(Ship s, int c){ + * @param c - the coins to give it + */ + public void coinsReward(Ship s, int c) { } - /** Fuel reward + /** + * Fuel reward + * * @param s - the ship to give reward to - * @param f - the fuel to give it*/ - public void fuelReward(Ship s,int f){ + * @param f - the fuel to give it + */ + public void fuelReward(Ship s, int f) { } - /** Rocket reward + /** + * Rocket reward + * * @param s - the ship to give reward to - * @param r - the rockets to give it */ - public void rocketReward(Ship s,int r){ + * @param r - the rockets to give it + */ + public void rocketReward(Ship s, int r) { + + } + + /** + * Give the player a crew member as reward + * + * @param s - the ship to give the reward to + * @param crew - a list of possible crew member drops + */ + public void crewReward(Ship s, List<Crew> crew) { } } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TraderService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TraderService.java new file mode 100644 index 00000000..f24ad256 --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TraderService.java @@ -0,0 +1,97 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Services; + +import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.galaxytrucker.galaxytruckerreloaded.Model.Crew.Crew; +import com.galaxytrucker.galaxytruckerreloaded.Model.Map.PlanetEvent; +import com.galaxytrucker.galaxytruckerreloaded.Model.Map.Trader; +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; +import com.galaxytrucker.galaxytruckerreloaded.Model.Weapons.Weapon; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.CrewDAO; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.ShipDAO; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.TraderDAO; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.WeaponDAO; +import lombok.*; + +@Getter +@Setter +@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +public class TraderService extends PlanetEventService { + + /** + * Trader DAO + */ + @NonNull + private TraderDAO traderDAO; + + /** WeaponDAO */ + @NonNull + private WeaponDAO weaponDAO; + + /** CrewDAO */ + @NonNull + private CrewDAO crewDAO; + + /** + * Validate purchase by checking if the client has enough money + * + * @param ship - the ship which's purchase to validate + * @param price - the price to pay in coins + * @return true if the ship has enough money else false + */ + public boolean validatePurchase(Ship ship, int price) { + return false; + } + + /** + * Buy a weapon from the trader + * + * @param ship - the ship that wishes to buy the weapon + * @param trader - the trader to buy the weapon from + * @param weapon - the weapon to buy + */ + private void purchaseWeapon(Ship ship, Trader trader, Weapon weapon) { + + } + + /** + * Buy crew from a trader + * + * @param ship - the ship that wants to buy a crew member + * @param trader - the trader to buy from + * @param crew - the crew to buy + */ + public void purchaseCrew(Ship ship, Trader trader, Crew crew) { + } + + /** + * Buy rockets from the trader + * + * @param ship - the ship hat wishes to buy rockets + * @param trader - the trader to buy from + * @param amount - the amount of rockets to buy + */ + public void purchaseRockets(Ship ship, Trader trader, int amount) { + + } + + /** + * Buy fuel from the trader + * + * @param ship - the ship that wants to buy stuff + * @param trader - the trader to buy from + * @param amount - the amount of fuel to buy + */ + public void purchaseFuel(Ship ship, Trader trader, int amount) { + } + + /** + * Buy health from the trader + * + * @param ship - the ship that wishes to buy health + * @param trader - the trader to buy from + * @param amount - the amount to buy + */ + public void purchaseHP(Ship ship, Trader trader, int amount) { + + } +} -- GitLab