diff --git a/src/main/java/com/alterdekim/game/component/GameServer.java b/src/main/java/com/alterdekim/game/component/GameServer.java index f0d68e1..ff01f18 100644 --- a/src/main/java/com/alterdekim/game/component/GameServer.java +++ b/src/main/java/com/alterdekim/game/component/GameServer.java @@ -57,6 +57,9 @@ public class GameServer { @Autowired private GoodsService goodsService; + @Autowired + private MiniGameService miniGameService; + private final Map players; private final ObjectMapper xmlMapper; @@ -103,7 +106,7 @@ public class GameServer { private void setPlayerAvatarPosition(int playerId, SetPlayerAvatarPosition message) { if( message.getCoordinates() != null ) { players.get(playerId).setX(message.getCoordinates().get("x").getDouble()); - players.get(playerId).setY(message.getCoordinates().get("y").getDouble()); + players.get(playerId).setY(message.getCoordinates().containsKey("y") ? message.getCoordinates().get("y").getDouble() : -100); } this.sendInPlayersLocation(playerId, CommandType.SetUserAvatarPosition, new SetPlayerPosition( @@ -239,7 +242,7 @@ public class GameServer { phoneMessageService.markAsRead(messageId); } case DeletePhoneMessage -> { - Long messageId1 = message.getArguments().get(0).getLong(); + long messageId1 = message.getArguments().get(0).getLong(); phoneMessageService.removeById(messageId1); } case CardMessage -> { @@ -266,9 +269,23 @@ public class GameServer { } case BuyBatch -> buySomething(playerId, message.getArguments().get(0), message); case LockHouse -> lockSomething(playerId, message.getArguments().get(0).getInt(), message.getArguments().get(1).getBoolean(), message); + case GetGame -> getGame(playerId, message.getArguments().get(0).getLong(), message.getTransactionId()); + case GameScore -> processGameScore(playerId, message.getTransactionId(), message.getArguments().get(1).getInt()); + case SendGameClose, GameStatistics -> { + this.sendResult(playerId, message.getTransactionId(), "0"); + } } } + private void processGameScore(int playerId, double transactionId, int amount) { + this.addUsualTickets(playerId, amount); + this.sendResult(playerId, transactionId, ""); + } + + private void getGame(int playerId, long gameId, double transactionId) throws JsonProcessingException { + this.sendResult(playerId, transactionId, xmlMapper.writeValueAsString(miniGameService.findGameById(gameId).get())); + } + private void lockSomething(int playerId, int what2Lock, Boolean state, UserMessage message) { if( what2Lock == -2 ) { this.users.pushUserProperty(playerId, PlayerProperties.IsClubLocked, state); @@ -312,6 +329,13 @@ public class GameServer { this.sendResult(playerId, message.getTransactionId(), new BuyGoodResultGood(new BuyGoodResultGood.BuyGoodBody(false, new ArrayList<>()))); } + private void addUsualTickets(int userId, int amount) { + int val = this.users.getUsualTickets(userId); + val += amount; + this.users.setUsualTickets(userId, val); + this.call(userId, CommandType.UpdateTickets, new UpdateTickets(val, this.users.getMagicTickets(userId))); + } + private boolean subtractUsualTickets(int userId, int amount) { int val = this.users.getUsualTickets(userId); if ( val >= amount ) { diff --git a/src/main/java/com/alterdekim/game/component/StartUpListener.java b/src/main/java/com/alterdekim/game/component/StartUpListener.java index d9c184f..3e566d1 100644 --- a/src/main/java/com/alterdekim/game/component/StartUpListener.java +++ b/src/main/java/com/alterdekim/game/component/StartUpListener.java @@ -137,6 +137,9 @@ public class StartUpListener { @Autowired private PromotionBannerService promotionBannerService; + @Autowired + private MiniGameService miniGameService; + @EventListener public void onApplicationEvent(ContextRefreshedEvent event) { this.startTime = System.currentTimeMillis(); @@ -184,12 +187,34 @@ public class StartUpListener { pushLocations(); pushLocationObjects(); + pushMiniGames(); + pushHouseLocations(); pushPhoneSkins(); log.info("Initialization complete"); } + private void pushMiniGames() { + miniGameService.save(new MiniGame(0L, "Рентген", 0, 0, 4250, 1d, 2, true, true, false, 0L, 0L, "1", "")); + miniGameService.save(new MiniGame(1L, "Дары леса", 10120, 1291, 1749, 10d, 1, true, false, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(2L, "Катер", 10089, 516, 4265, 100d, 1, true, true, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(3L, "Волейбол", 10087, 513, 301, 100d, 1, true, true, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(4L, "Кафе", 10088, 515, 310, 1d, 0, true, true, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(5L, "Труба", 10084, 1104, 11763, 1d, 0, false, true, true, 0L, 0L, "1", "")); + miniGameService.save(new MiniGame(6L, "Секретики", 10097, 806, 763, 1d, 0, true, false, true, 1000L, 10000L, "1", "")); + miniGameService.save(new MiniGame(7L, "Смешарики", 10086, 510, 3126, 1d, 1, true, true, true, 1000L, 10000L, "0", "")); + miniGameService.save(new MiniGame(8L, "Модельер", 10101, 948, 4300, 5d, 0, false, false, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(9L, "Горки", 10095, 557, 341, 40d, 1, true, true, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(10L, "Скачки", 10093, 518, 319, 1d, 0, true, true, true, 1000L, 10000L, "0", "")); + miniGameService.save(new MiniGame(11L, "Футбол", 10112, 1212, 4247, 1d, 3, true, true, true, 1000L, 30000L, "0", "")); + miniGameService.save(new MiniGame(12L, "Няня", 10083, 505, 4241, 30d, 0, false, true, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(13L, "Двигатель", 10094, 519, 322, 5d, 0, false, true, true, 0L, 0L, "0", "")); + miniGameService.save(new MiniGame(14L, "Шарабудка", 8054, 3218, 1127, 1d, 0, false, true, true, 0L, 0L, "1", "")); + miniGameService.save(new MiniGame(92L, "Трасса", 0, 0, 4267, 1d, 1, false, false, true, 0L, 0L, "1", "")); + miniGameService.save(new MiniGame(206L, "Муравей", 2148, 2148, 3170, 1d, 0, true, false, true, 0L, 0L, "1", "")); + } + private void pushPhoneSkins() { phoneIconService.findAll() .stream() @@ -487,7 +512,6 @@ public class StartUpListener { ); } - // todo: implement other stuff from base.swf private void processBase(String swf) throws IOException { log.info("Processing base"); diff --git a/src/main/java/com/alterdekim/game/component/game/UserCommandType.java b/src/main/java/com/alterdekim/game/component/game/UserCommandType.java index f20200b..771fd7b 100644 --- a/src/main/java/com/alterdekim/game/component/game/UserCommandType.java +++ b/src/main/java/com/alterdekim/game/component/game/UserCommandType.java @@ -39,6 +39,10 @@ public enum UserCommandType { DeleteCardMessage("_MCD"), LockHouse("_LL"), BuyBatch("_BGB"), + GetGame("_GG"), + GameScore("_GS"), + SendGameClose("_GC"), + GameStatistics("_GT"), Unknown(""); private final String value; diff --git a/src/main/java/com/alterdekim/game/entity/MiniGame.java b/src/main/java/com/alterdekim/game/entity/MiniGame.java new file mode 100644 index 0000000..ea2f180 --- /dev/null +++ b/src/main/java/com/alterdekim/game/entity/MiniGame.java @@ -0,0 +1,80 @@ +package com.alterdekim.game.entity; + +import com.alterdekim.flash.decompiler.mapper.FlashValue; +import com.alterdekim.flash.decompiler.mapper.FlashValueType; +import com.alterdekim.game.xml.NumericBooleanSerializer; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "minigames") +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class MiniGame { + @Id + @JacksonXmlProperty(isAttribute = true, localName = "ID") + private Long id; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "GameName") + private String gameName; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "NameTRId") + private Integer nameTRId; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "TextResourceID") + private Integer textResourceID; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "MediaResourceID") + private Integer mediaResourceID; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "ScoreDivisor") + private Double scoreDivisor; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "AvatarType") + private Integer avatarType; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "IsPromptUsed") + @JsonSerialize(using = NumericBooleanSerializer.class) + private Boolean isPromptUsed; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "IsFullscreen") + @JsonSerialize(using = NumericBooleanSerializer.class) + private Boolean isFullscreen; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "IsShowPoints") + @JsonSerialize(using = NumericBooleanSerializer.class) + private Boolean isShowPoints; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "StartFullTime") + private Long startFullTime; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "StartLackTime") + private Long startLackTime; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "Options") + private String options; + + @Column(nullable = false) + @JacksonXmlProperty(isAttribute = true, localName = "Token") + private String token; +} diff --git a/src/main/java/com/alterdekim/game/repository/MiniGameRepository.java b/src/main/java/com/alterdekim/game/repository/MiniGameRepository.java new file mode 100644 index 0000000..7997c37 --- /dev/null +++ b/src/main/java/com/alterdekim/game/repository/MiniGameRepository.java @@ -0,0 +1,9 @@ +package com.alterdekim.game.repository; + +import com.alterdekim.game.entity.MiniGame; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MiniGameRepository extends JpaRepository { +} diff --git a/src/main/java/com/alterdekim/game/service/MiniGameService.java b/src/main/java/com/alterdekim/game/service/MiniGameService.java new file mode 100644 index 0000000..776ffa7 --- /dev/null +++ b/src/main/java/com/alterdekim/game/service/MiniGameService.java @@ -0,0 +1,23 @@ +package com.alterdekim.game.service; + +import com.alterdekim.game.entity.MiniGame; +import com.alterdekim.game.repository.MiniGameRepository; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +public class MiniGameService { + @Autowired + private MiniGameRepository repository; + + public void save(MiniGame game) { + this.repository.save(game); + } + + public Optional findGameById(Long id) { + return this.repository.findById(id); + } +}