渔民小镇 1 tahun lalu
induk
melakukan
30973c9144

+ 17 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/internal/equip/BuildEquipUseProcess.java

@@ -34,10 +34,13 @@ import com.iohao.mmo.equip.proto.CreateEquipMessage;
 import com.iohao.mmo.equip.proto.NewEquipMessage;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.bson.types.ObjectId;
 import org.springframework.stereotype.Component;
 
+import java.time.LocalTime;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * 打造装备 - 物品使用逻辑处理类
@@ -99,6 +102,8 @@ public class BuildEquipUseProcess implements UseProcess {
         createEquipMessage.itemTypeId = equipItemTypeId;
 
         NewEquipMessage newEquipMessage = EquipExchange.createEquip(createEquipMessage, flowContext);
+        newEquipMessage = tempNewEquipMessage(createEquipMessage, newEquipMessage);
+
         String equipId = newEquipMessage.equipId;
 
         // 将新装备放到背包中
@@ -109,4 +114,16 @@ public class BuildEquipUseProcess implements UseProcess {
 
         return bagItem;
     }
+
+    private NewEquipMessage tempNewEquipMessage(CreateEquipMessage createEquipMessage, NewEquipMessage newEquipMessage) {
+        // 临时代码
+        if (Objects.isNull(newEquipMessage)) {
+            String newEquipId = createEquipMessage.itemTypeId + "_" + LocalTime.now().getMinute() + "_" + new ObjectId();
+            newEquipMessage = new NewEquipMessage();
+            newEquipMessage.equipId = newEquipId;
+            newEquipMessage.itemTypeId = createEquipMessage.itemTypeId;
+        }
+
+        return newEquipMessage;
+    }
 }

+ 1 - 1
logic/mail-logic/src/main/java/com/iohao/mmo/mail/mapper/MailAttachmentMapper.java

@@ -34,7 +34,7 @@ import java.util.List;
 public interface MailAttachmentMapper {
     MailAttachmentMapper ME = Mappers.getMapper(MailAttachmentMapper.class);
 
-    @Mapping(source = "getItemTypeId", target = "id")
+    @Mapping(source = "itemTypeId", target = "id")
     BagItemMessage convert(MailAttachment mailAttachment);
 
     List<BagItemMessage> convertBagItems(List<MailAttachment> mailAttachments);

+ 2 - 2
provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagInputCommandRegion.java

@@ -32,7 +32,7 @@ import com.iohao.mmo.bag.proto.BagItemMessage;
 import com.iohao.mmo.bag.proto.BagMessage;
 import com.iohao.mmo.bag.proto.UseItemMessage;
 import com.iohao.mmo.bag.proto.UseMessage;
-import com.iohao.mmo.common.provide.kit.ItemKit;
+import com.iohao.mmo.common.provide.kit.ItemTypeNodeKit;
 import com.iohao.mmo.common.provide.kit.JsonKit;
 import com.iohao.mmo.common.snow.SnowKit;
 import lombok.extern.slf4j.Slf4j;
@@ -97,7 +97,7 @@ public class BagInputCommandRegion extends AbstractInputCommandRegion {
             List<JSONObject> list = value.itemMap.values().stream().map(bagItemMessage -> {
                 String itemTypeId = bagItemMessage.itemTypeId;
                 JSONObject bagItemMessageJson = JsonKit.toJSON(bagItemMessage);
-                JSONObject itemMessageJson = ItemKit.toJSON(itemTypeId);
+                JSONObject itemMessageJson = ItemTypeNodeKit.toJSON(itemTypeId);
                 return JsonKit.merge(bagItemMessageJson, itemMessageJson);
             }).toList();
 

+ 2 - 2
provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/ItemInputCommandRegion.java

@@ -22,7 +22,7 @@ import com.iohao.game.action.skeleton.protocol.wrapper.ByteValueList;
 import com.iohao.game.external.client.AbstractInputCommandRegion;
 import com.iohao.mmo.bag.cmd.ItemCmd;
 import com.iohao.mmo.bag.proto.ItemMessage;
-import com.iohao.mmo.common.provide.kit.ItemKit;
+import com.iohao.mmo.common.provide.kit.ItemTypeNodeKit;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.List;
@@ -39,7 +39,7 @@ public class ItemInputCommandRegion extends AbstractInputCommandRegion {
 
         ofCommand(ItemCmd.listItem).callback(ByteValueList.class, result -> {
             List<ItemMessage> list = result.toList(ItemMessage.class);
-            list.forEach(itemMessage -> ItemKit.itemNodeMap.add(itemMessage.itemTypeId, itemMessage.name, itemMessage.description));
+            list.forEach(itemMessage -> ItemTypeNodeKit.itemNodeMap.add(itemMessage.itemTypeId, itemMessage.name, itemMessage.description));
         }).setDescription("物品配置列表");
     }
 

+ 2 - 2
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/client/CommonInputCommandRegion.java

@@ -21,7 +21,7 @@ package com.iohao.mmo.common.provide.client;
 import com.iohao.game.action.skeleton.protocol.wrapper.ByteValueList;
 import com.iohao.game.external.client.AbstractInputCommandRegion;
 import com.iohao.mmo.common.provide.cmd.CommonCmd;
-import com.iohao.mmo.common.provide.kit.ItemKit;
+import com.iohao.mmo.common.provide.kit.ItemTypeNodeKit;
 import com.iohao.mmo.common.provide.kit.ItemNode;
 import com.iohao.mmo.common.provide.proto.ShowItemMessage;
 import lombok.extern.slf4j.Slf4j;
@@ -43,7 +43,7 @@ public class CommonInputCommandRegion extends AbstractInputCommandRegion {
             String collect = result.toList(ShowItemMessage.class)
                     .stream()
                     .map(this::convert)
-                    .map(ItemKit::toString)
+                    .map(ItemTypeNodeKit::toString)
                     .collect(Collectors.joining());
 
             log.info("获得新物品 {}", collect);

+ 4 - 18
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/kit/ItemNodeMap.java

@@ -34,30 +34,16 @@ import java.util.Map;
 @Setter
 @FieldDefaults(level = AccessLevel.PRIVATE)
 public class ItemNodeMap {
-    final Map<String, TheItemInfo> map = new HashMap<>();
+    final Map<String, ItemTypeNode> map = new HashMap<>();
 
     public void add(String itemTypeId, String name, String description) {
-        TheItemInfo theItemInfo = new TheItemInfo(itemTypeId, name, description);
+        var itemTypeNode = new ItemTypeNode(itemTypeId, name, description);
 
-        map.put(itemTypeId, theItemInfo);
+        map.put(itemTypeId, itemTypeNode);
     }
 
-    public TheItemInfo getItem(String itemId) {
+    public ItemTypeNode getItem(String itemId) {
         return map.get(itemId);
     }
 
-    static class TheItemInfo {
-        /** itemId */
-        String itemId;
-        /** 物品名 */
-        String name;
-        /** 物品描述 */
-        String description;
-
-        public TheItemInfo(String itemId, String name, String description) {
-            this.itemId = itemId;
-            this.name = name;
-            this.description = description;
-        }
-    }
 }

+ 29 - 0
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/kit/ItemTypeNode.java

@@ -0,0 +1,29 @@
+/*
+ * ioGame
+ * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
+ * # iohao.com . 渔民小镇
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.iohao.mmo.common.provide.kit;
+
+/**
+ * @param itemTypeId  物品类型 id
+ * @param name        物品名
+ * @param description 物品描述
+ * @author 渔民小镇
+ * @date 2023-08-22
+ */
+public record ItemTypeNode(String itemTypeId, String name, String description) {
+}

+ 4 - 4
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/kit/ItemKit.java → provide/common-provide/src/main/java/com/iohao/mmo/common/provide/kit/ItemTypeNodeKit.java

@@ -28,7 +28,7 @@ import lombok.experimental.UtilityClass;
  * @date 2023-08-15
  */
 @UtilityClass
-public class ItemKit {
+public class ItemTypeNodeKit {
     public ItemNodeMap itemNodeMap = new ItemNodeMap();
 
     public String toString(ItemNode itemNode) {
@@ -36,14 +36,14 @@ public class ItemKit {
         String line = "\n物品信息:[%s x %s];物品描述:%s";
 
         return String.format(line
-                , node.name
+                , node.name()
                 , itemNode.quantity()
-                , node.description
+                , node.description()
         );
     }
 
     public JSONObject toJSON(String itemId) {
-        ItemNodeMap.TheItemInfo item = itemNodeMap.getItem(itemId);
+        var item = itemNodeMap.getItem(itemId);
         return JsonKit.toJSON(item);
     }
 }

+ 2 - 2
provide/mail-provide/src/main/java/com/iohao/mmo/mail/client/MailInputCommandRegion.java

@@ -26,7 +26,7 @@ import com.iohao.game.common.kit.TimeKit;
 import com.iohao.game.external.client.AbstractInputCommandRegion;
 import com.iohao.game.external.client.kit.ScannerKit;
 import com.iohao.mmo.bag.ItemTypeIdConst;
-import com.iohao.mmo.common.provide.kit.ItemKit;
+import com.iohao.mmo.common.provide.kit.ItemTypeNodeKit;
 import com.iohao.mmo.common.provide.kit.ItemNode;
 import com.iohao.mmo.mail.cmd.MailCmd;
 import com.iohao.mmo.mail.kit.InternalMailBuilder;
@@ -127,7 +127,7 @@ public class MailInputCommandRegion extends AbstractInputCommandRegion {
             String mailAttachmentStr = mailMessage.mailAttachments
                     .stream()
                     .map(this::convert)
-                    .map(ItemKit::toString)
+                    .map(ItemTypeNodeKit::toString)
                     .collect(Collectors.joining());
 
             List<Object> list = new ArrayList<>();