diff --git a/pom.xml b/pom.xml
index e78e55a..ff21d27 100644
--- a/pom.xml
+++ b/pom.xml
@@ -153,8 +153,8 @@
org.apache.maven.pluginsmaven-compiler-plugin
- 14
- 14
+ 15
+ 15
diff --git a/src/main/java/com/alterdekim/game/component/GameServer.java b/src/main/java/com/alterdekim/game/component/GameServer.java
index d25f33f..9ebf320 100644
--- a/src/main/java/com/alterdekim/game/component/GameServer.java
+++ b/src/main/java/com/alterdekim/game/component/GameServer.java
@@ -104,6 +104,7 @@ public class GameServer {
switch (UserCommandType.fromString(message.getCommandType())) {
case GetUserInitData:
String r = xmlMapper.writeValueAsString(users.getUserInitInfoByUserId(playerId));
+ log.info("GetUserInitData: {}", r);
this.sendResult(playerId, message.getTransactionId(), r);
break;
case UserFriendsGet: // todo: implement
diff --git a/src/main/java/com/alterdekim/game/component/game/avatar/InitMagicAbility.java b/src/main/java/com/alterdekim/game/component/game/avatar/InitMagicAbility.java
index cc7ac86..9bf60e9 100644
--- a/src/main/java/com/alterdekim/game/component/game/avatar/InitMagicAbility.java
+++ b/src/main/java/com/alterdekim/game/component/game/avatar/InitMagicAbility.java
@@ -6,14 +6,14 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
-@Getter
-@AllArgsConstructor
-public class InitMagicAbility {
+
+public interface InitMagicAbility {
@JacksonXmlProperty(localName = "Id", isAttribute = true)
- private Integer id;
+ Integer getId();
+
@JacksonXmlProperty(localName = "ExpirationDate", isAttribute = true)
- private String expirationDate;
+ String getExpirationDate();
+
@JacksonXmlProperty(localName = "IsLimited", isAttribute = true)
- @JsonSerialize(using= NumericBooleanSerializer.class)
- private Boolean isLimited;
+ Integer getIsLimited();
}
diff --git a/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java b/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java
index 640b056..f8bc220 100644
--- a/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java
+++ b/src/main/java/com/alterdekim/game/repository/AvatarInventoryRepository.java
@@ -3,8 +3,10 @@ package com.alterdekim.game.repository;
import com.alterdekim.game.component.game.AvatarInventoryType;
import com.alterdekim.game.component.game.avatar.IBodyAvatarItem;
import com.alterdekim.game.component.game.avatar.GoodClothType;
+import com.alterdekim.game.component.game.avatar.InitMagicAbility;
import com.alterdekim.game.component.game.inventory.InventoryItem;
import com.alterdekim.game.entity.AvatarInventory;
+import com.alterdekim.game.entity.Smile;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
@@ -33,18 +35,107 @@ public interface AvatarInventoryRepository extends JpaRepository 0) then true else false end) AS isUsed, false AS isColorable, 0 AS color, false AS isLimited, g.publish_date AS date, 0 AS pollution, false AS isBodyPart, 0 AS phoneId FROM avatar_inventory AS a JOIN goods AS g ON a.good_id = g.id WHERE a.user_id = :uid AND a.type = 'Clothes' AND g.good_type_id = :#{#goodTypeId.getVal()}", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ a.good_id AS id,
+ g.trid AS textResourceId,
+ 0 AS bodyPartId,
+ g.mrid AS mediaResourceId,
+ (case when (a.is_used > 0) then true else false end) AS isUsed,
+ false AS isColorable,
+ 0 AS color,
+ false AS isLimited,
+ g.publish_date AS date,
+ 0 AS pollution,
+ false AS isBodyPart,
+ 0 AS phoneId
+ FROM avatar_inventory AS a
+ JOIN goods AS g
+ ON a.good_id = g.id
+ WHERE a.user_id = :uid AND a.type = 'Clothes' AND g.good_type_id = :#{#goodTypeId.getVal()}""", nativeQuery = true)
List findInventoryItems(@Param("uid") Long userId, @Param("goodTypeId") GoodClothType goodClothType);
- @Query(value = "SELECT b.id AS id, 0 AS textResourceId, 0 AS bodyPartId, 0 AS mediaResourceId, (case when (a.is_used > 0) then true else false end) AS isUsed, false AS isColorable, 0 AS color, false AS isLimited, '' AS date, 0 AS pollution, false AS isBodyPart, 0 AS phoneId FROM backgrounds b JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Backgrounds' AND a.user_id = :uid) AS a ON a.good_id = b.id", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ b.id AS id,
+ 0 AS textResourceId,
+ 0 AS bodyPartId,
+ 0 AS mediaResourceId,
+ (case when (a.is_used > 0) then true else false end) AS isUsed,
+ false AS isColorable,
+ 0 AS color,
+ false AS isLimited,
+ '' AS date,
+ 0 AS pollution,
+ false AS isBodyPart,
+ 0 AS phoneId
+ FROM backgrounds b
+ JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Backgrounds' AND a.user_id = :uid) AS a
+ ON a.good_id = b.id""", nativeQuery = true)
List findBackgrounds(@Param("uid") Long userId);
- @Query(value = "SELECT p.id AS id, 0 AS textResourceId, 0 AS bodyPartId, 0 AS mediaResourceId, (case when (a.is_used > 0) then true else false end) AS isUsed, false AS isColorable, 0 AS color, false AS isLimited, '' AS date, 0 AS pollution, false AS isBodyPart, p.id AS phoneId FROM phone_icons p JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Phones' AND a.user_id = :uid) AS a ON a.good_id = p.id", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ p.id AS id,
+ 0 AS textResourceId,
+ 0 AS bodyPartId,
+ 0 AS mediaResourceId,
+ (case when (a.is_used > 0) then true else false end) AS isUsed,
+ false AS isColorable,
+ 0 AS color,
+ false AS isLimited,
+ '' AS date,
+ 0 AS pollution,
+ false AS isBodyPart,
+ p.id AS phoneId
+ FROM phone_icons p
+ JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Phones' AND a.user_id = :uid) AS a
+ ON a.good_id = p.id""", nativeQuery = true)
List findPhones(@Param("uid") Long userId);
- @Query(value = "SELECT b.`type` AS bodyPartTypeId, b.id AS id, a.color AS color, 1 AS isBodyPart, b.id AS bodyPartId, 0 AS goodId, b.media_resource_id AS mediaResourceId, b.`type` AS layerId, 0 AS goodTypeId FROM bodyparts b JOIN (SELECT a.color, a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'BodyParts' AND a.is_used = true) AS a ON a.good_id = b.id", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ b.`type` AS bodyPartTypeId,
+ b.id AS id,
+ a.color AS color,
+ 1 AS isBodyPart,
+ b.id AS bodyPartId,
+ 0 AS goodId,
+ b.media_resource_id AS mediaResourceId,
+ b.`type` AS layerId,
+ 0 AS goodTypeId
+ FROM bodyparts b
+ JOIN (SELECT a.color, a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'BodyParts' AND a.is_used = true) AS a
+ ON a.good_id = b.id""", nativeQuery = true)
List findUsedBodyPartsByUserId(@Param("uid") Long userId);
- @Query(value = "SELECT 0 AS bodyPartTypeId, g.id AS id, 0 AS color, 0 AS isBodyPart, 0 AS bodyPartId, g.id AS goodId, g.mrid AS mediaResourceId, g.layer_id AS layerId, g.good_type_id AS goodTypeId FROM goods g JOIN (SELECT a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'Clothes' AND a.is_used = true) AS a ON a.good_id = g.id", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ 0 AS bodyPartTypeId,
+ g.id AS id,
+ 0 AS color,
+ 0 AS isBodyPart,
+ 0 AS bodyPartId,
+ g.id AS goodId,
+ g.mrid AS mediaResourceId,
+ g.layer_id AS layerId,
+ g.good_type_id AS goodTypeId
+ FROM goods g
+ JOIN (SELECT a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'Clothes' AND a.is_used = true) AS a
+ ON a.good_id = g.id""", nativeQuery = true)
List findUsedClothesByUserId(@Param("uid") Long userId);
+
+
+ @Query(value = """
+ SELECT
+ g.magic_ability_id AS id,
+ '' AS expirationDate,
+ 0 AS isLimited
+ FROM gms g
+ JOIN (SELECT a.good_id FROM avatar_inventory a WHERE a.`type` = 'Magic' AND a.user_id = :uid) a
+ ON g.id = a.good_id""", nativeQuery = true)
+ List findMagicAbilitiesByUserId(@Param("uid") Long userId);
+
+ @Query(value = "SELECT s FROM Smile s WHERE s.id IN (SELECT a.goodId FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = 'Smile')")
+ List findSmilesByUserId(@Param("uid") Long userId);
}
diff --git a/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java b/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java
index b44c0e3..dcec6ec 100644
--- a/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java
+++ b/src/main/java/com/alterdekim/game/repository/BodyPartRepository.java
@@ -18,6 +18,44 @@ public interface BodyPartRepository extends JpaRepository {
@Query(value = "SELECT b FROM BodyPart b WHERE b.type = :type")
List findByBodyPartType(@Param("type") BodyPartType type);
- @Query(value = "SELECT a.id AS id, 0 AS textResourceId, a.id AS bodyPartId, a.media_resource_id AS mediaResourceId, (case when (MAX(a.is_used) > 0) then 1 else 0 end) AS isUsed, (case when (a.is_colorable > 0) then 1 else 0 end) AS isColorable, MAX(a.color) AS color, 0 AS isLimited, '' AS date, 0 AS pollution, 1 AS isBodyPart, 0 AS phoneId FROM (SELECT b.id, b.is_colorable, b.media_resource_id, b.`type`, 0 AS is_used, 0 AS color FROM bodyparts AS b UNION (SELECT b.id, b.is_colorable, b.media_resource_id, b.`type`, a.is_used, a.color FROM bodyparts AS b JOIN avatar_inventory AS a ON b.id = a.good_id WHERE a.`type` = 'BodyParts' AND a.user_id = :uid)) AS a WHERE a.`type` = :#{#type.name()} GROUP BY a.id, a.`type`, a.media_resource_id, a.is_colorable", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ a.id AS id,
+ 0 AS textResourceId,
+ a.id AS bodyPartId,
+ a.media_resource_id AS mediaResourceId,
+ (case when (MAX(a.is_used) > 0) then 1 else 0 end) AS isUsed,
+ (case when (a.is_colorable > 0) then 1 else 0 end) AS isColorable,
+ MAX(a.color) AS color,
+ 0 AS isLimited,
+ '' AS date,
+ 0 AS pollution,
+ 1 AS isBodyPart,
+ 0 AS phoneId
+ FROM (
+ SELECT
+ b.id,
+ b.is_colorable,
+ b.media_resource_id,
+ b.`type`,
+ 0 AS is_used,
+ 0 AS color
+ FROM bodyparts AS b
+ UNION (
+ SELECT
+ b.id,
+ b.is_colorable,
+ b.media_resource_id,
+ b.`type`,
+ a.is_used,
+ a.color
+ FROM bodyparts AS b
+ JOIN avatar_inventory AS a
+ ON b.id = a.good_id
+ WHERE a.`type` = 'BodyParts' AND a.user_id = :uid
+ )
+ ) AS a
+ WHERE a.`type` = :#{#type.name()}
+ GROUP BY a.id, a.`type`, a.media_resource_id, a.is_colorable""", nativeQuery = true)
List findInventoryItems(@Param("uid") Long userId, @Param("type") BodyPartType type);
}
\ No newline at end of file
diff --git a/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java b/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java
index 4630f1f..5e51aac 100644
--- a/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java
+++ b/src/main/java/com/alterdekim/game/service/AvatarInventoryService.java
@@ -87,24 +87,11 @@ public class AvatarInventoryService {
}
public List getMagicAbilitiesItemsByUserId(Long userId) {
- return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Magic)
- .stream()
- .map(AvatarInventory::getGoodId)
- .map(id -> goodMagicRepository.findById(id))
- .filter(Optional::isPresent)
- .map(Optional::get)
- .map(g -> new InitMagicAbility(g.getMagicAbilityId(), "", false)) // todo: implement expiration ability
- .collect(Collectors.toList());
+ return this.inventoryRepository.findMagicAbilitiesByUserId(userId); // todo: implement expiration ability
}
public List getSmilesByUserId(Long userId) {
- return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Smile)
- .stream()
- .map(AvatarInventory::getGoodId)
- .map(id -> smileService.findById(id))
- .filter(Optional::isPresent)
- .map(Optional::get)
- .collect(Collectors.toList());
+ return this.inventoryRepository.findSmilesByUserId(userId);
}
public List getBackgroundsByUserId(Long userId) {
@@ -158,10 +145,7 @@ public class AvatarInventoryService {
public String getAchievementsByUserId(Long userId) {
return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Achievments)
.stream()
- .map(a -> achievementService.findById(a.getGoodId()))
- .filter(Optional::isPresent)
- .map(Optional::get)
- .map(a -> a.getId().toString())
+ .map(a -> a.getGoodId().toString())
.collect(Collectors.joining(","));
}