Parcourir la source

Merge remote-tracking branch 'origin/main' into main

# Conflicts:
#	common/common-core/src/main/java/com/iohao/mmo/common/config/GameCode.java
#	one-client/src/main/java/com/iohao/mmo/client/CommonClient.java
toby il y a 1 an
Parent
commit
d15b4012ae
37 fichiers modifiés avec 878 ajouts et 249 suppressions
  1. 2 2
      common/common-core/src/main/java/com/iohao/mmo/common/config/GameCode.java
  2. 46 0
      common/common-core/src/main/java/com/iohao/mmo/common/core/flow/internal/DebugActionMethodExceptionProcess.java
  3. 5 0
      common/common-core/src/main/java/com/iohao/mmo/common/logic/server/LogicServerKit.java
  4. 0 6
      logic/all-logic/pom.xml
  5. 22 6
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/action/BagAction.java
  6. 54 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/action/ItemAction.java
  7. 23 3
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/config/ItemCommandLineRunner.java
  8. 6 30
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/ItemMapper.java
  9. 63 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/UseItemMapper.java
  10. 0 1
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/pojo/UseItemPOJO.java
  11. 5 2
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/ItemConfigRegion.java
  12. 43 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/SceneConst.java
  13. 3 2
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/UseContext.java
  14. 11 1
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/UseProcess.java
  15. 18 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/UseRegion.java
  16. 11 8
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/internal/DefaultUseProcess.java
  17. 134 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/internal/equip/BuildEquipParse.java
  18. 110 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/internal/equip/BuildEquipUseProcess.java
  19. 21 4
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/service/BagService.java
  20. 0 38
      logic/item-logic/.gitignore
  21. 0 34
      logic/item-logic/pom.xml
  22. 5 1
      one-client/src/main/java/com/iohao/mmo/client/CommonClient.java
  23. 0 2
      pom.xml
  24. 0 6
      provide/all-provide/pom.xml
  25. 9 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/ItemIdConst.java
  26. 30 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/ItemIdTypeConst.java
  27. 77 18
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagInputCommandRegion.java
  28. 54 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/ItemInputCommandRegion.java
  29. 6 11
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/ext/ClientBagAttr.java
  30. 52 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/ext/ItemMessageMap.java
  31. 2 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/cmd/BagCmd.java
  32. 4 9
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/cmd/ItemCmd.java
  33. 42 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/ItemMessage.java
  34. 5 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/UseMessage.java
  35. 15 0
      provide/common-provide/src/main/java/com/iohao/mmo/common/provide/kit/JsonKit.java
  36. 0 38
      provide/item-provide/.gitignore
  37. 0 27
      provide/item-provide/pom.xml

+ 2 - 2
common/common-core/src/main/java/com/iohao/mmo/common/config/GameCode.java

@@ -35,8 +35,8 @@ public enum GameCode implements MsgExceptionInfo {
     mapNotExist(1, "地图不存在"),
     /** 升级错误,经验值不足 */
     upLevelError(2, "升级错误,经验值不足"),
-    /** 数量不足 */
-    quantityNotEnough(3, "数量不足"),
+    /** 背包物品数量不足 */
+    quantityNotEnough(3, "背包物品数量不足"),
     /** 操作对象错误 */
     objNotFound(4, "操作对象错误"),
     /** 可分配属性点不足 */

+ 46 - 0
common/common-core/src/main/java/com/iohao/mmo/common/core/flow/internal/DebugActionMethodExceptionProcess.java

@@ -0,0 +1,46 @@
+/*
+ * 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.core.flow.internal;
+
+import com.iohao.game.action.skeleton.core.exception.ActionErrorEnum;
+import com.iohao.game.action.skeleton.core.exception.MsgException;
+import com.iohao.game.action.skeleton.core.flow.ActionMethodExceptionProcess;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 增加触发验证时,打印异常栈信息
+ *
+ * @author 渔民小镇
+ * @date 2023-08-09
+ */
+@Slf4j
+public class DebugActionMethodExceptionProcess implements ActionMethodExceptionProcess {
+    @Override
+    public MsgException processException(final Throwable e) {
+
+        log.error(e.getMessage(), e);
+
+        if (e instanceof MsgException msgException) {
+            return msgException;
+        }
+
+        // 到这里,一般不是用户自定义的错误,很可能是开发者引入的第三方包或自身未捕获的错误等情况
+        return new MsgException(ActionErrorEnum.systemOtherErrCode);
+    }
+}

+ 5 - 0
common/common-core/src/main/java/com/iohao/mmo/common/logic/server/LogicServerKit.java

@@ -27,6 +27,7 @@ import com.iohao.game.bolt.broker.core.common.processor.hook.ClientProcessorHook
 import com.iohao.mmo.common.config.GameCode;
 import com.iohao.mmo.common.core.flow.MyFlowContext;
 import com.iohao.mmo.common.core.flow.internal.DebugActionAfter;
+import com.iohao.mmo.common.core.flow.internal.DebugActionMethodExceptionProcess;
 import com.iohao.mmo.common.processor.hook.MyRequestMessageClientProcessorHook;
 import lombok.experimental.UtilityClass;
 
@@ -45,8 +46,12 @@ public class LogicServerKit {
                 .addErrorCode(GameCode.values());
 
         BarSkeletonBuilder builder = LogicServerCreateKit.createBuilder(config);
+
         // 重写业务框架 ActionAfter
         builder.setActionAfter(new DebugActionAfter());
+        // 重写业务框架 ActionMethodExceptionProcess
+        builder.setActionMethodExceptionProcess(new DebugActionMethodExceptionProcess());
+
         // 使用自定义 FlowContext
         builder.setFlowContextFactory(MyFlowContext::new);
 

+ 0 - 6
logic/all-logic/pom.xml

@@ -43,12 +43,6 @@
             <version>${project.parent.version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>com.iohao.mmo</groupId>
-            <artifactId>item-logic</artifactId>
-            <version>${project.parent.version}</version>
-        </dependency>
-
         <dependency>
             <groupId>com.iohao.mmo</groupId>
             <artifactId>bag-logic</artifactId>

+ 22 - 6
logic/bag-logic/src/main/java/com/iohao/mmo/bag/action/BagAction.java

@@ -22,16 +22,16 @@ import com.iohao.game.action.skeleton.annotation.ActionController;
 import com.iohao.game.action.skeleton.annotation.ActionMethod;
 import com.iohao.game.action.skeleton.core.exception.ActionErrorEnum;
 import com.iohao.game.action.skeleton.core.flow.FlowContext;
-import com.iohao.game.common.kit.SafeKit;
 import com.iohao.mmo.bag.cmd.BagCmd;
 import com.iohao.mmo.bag.entity.Bag;
 import com.iohao.mmo.bag.entity.BagItem;
 import com.iohao.mmo.bag.mapper.BagMapper;
-import com.iohao.mmo.bag.mapper.ItemMapper;
+import com.iohao.mmo.bag.mapper.UseItemMapper;
 import com.iohao.mmo.bag.pojo.UsePOJO;
 import com.iohao.mmo.bag.proto.BagItemMessage;
 import com.iohao.mmo.bag.proto.BagMessage;
 import com.iohao.mmo.bag.proto.UseMessage;
+import com.iohao.mmo.bag.region.SceneConst;
 import com.iohao.mmo.bag.region.UseContext;
 import com.iohao.mmo.bag.region.UseRegion;
 import com.iohao.mmo.bag.service.BagService;
@@ -114,14 +114,32 @@ public class BagAction {
      */
     @ActionMethod(BagCmd.use)
     public boolean use(UseMessage useMessage, FlowContext flowContext) {
+        useMessage.scene = SceneConst.defaultScene;
+        useProcess(useMessage, flowContext);
+        return true;
+    }
+
+    /**
+     * 使用背包物品来打造装备
+     *
+     * @param useMessage  使用物品
+     * @param flowContext flowContext
+     */
+    @ActionMethod(BagCmd.useBuildEquip)
+    public boolean useBuildEquip(UseMessage useMessage, FlowContext flowContext) {
+        useMessage.scene = SceneConst.buildEquipScene;
+        useProcess(useMessage, flowContext);
+        return true;
+    }
+
+    private void useProcess(UseMessage useMessage, FlowContext flowContext) {
         ActionErrorEnum.validateErrCode.assertTrue(useMessage.verify());
         /*
          * 各物品的处理逻辑不相同
          * 如气血药,增加气血值;魔法药,增加魔法值;
          * 攻击符、增加临时攻击力;
          */
-        UsePOJO usePOJO = ItemMapper.ME.convert(useMessage);
-        usePOJO.scene = SafeKit.getString(usePOJO.scene, "default");
+        UsePOJO usePOJO = UseItemMapper.ME.convert(useMessage);
 
         // 使用上下文
         UseContext context = new UseContext();
@@ -132,7 +150,5 @@ public class BagAction {
         useRegion.process(context);
 
         log.info("usePOJO : {}", usePOJO);
-
-        return true;
     }
 }

+ 54 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/action/ItemAction.java

@@ -0,0 +1,54 @@
+/*
+ * 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.bag.action;
+
+import com.iohao.game.action.skeleton.annotation.ActionController;
+import com.iohao.game.action.skeleton.annotation.ActionMethod;
+import com.iohao.mmo.bag.cmd.ItemCmd;
+import com.iohao.mmo.bag.entity.ItemConfig;
+import com.iohao.mmo.bag.mapper.ItemMapper;
+import com.iohao.mmo.bag.proto.ItemMessage;
+import com.iohao.mmo.bag.region.ItemConfigRegion;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 物品配置相关
+ *
+ * @author 渔民小镇
+ * @date 2023-08-13
+ */
+@Slf4j
+@Component
+@ActionController(ItemCmd.cmd)
+public class ItemAction {
+    /**
+     * 物品列表
+     *
+     * @return 物品列表
+     */
+    @ActionMethod(ItemCmd.listItem)
+    public List<ItemMessage> listItem() {
+        Collection<ItemConfig> values = ItemConfigRegion.values();
+        return ItemMapper.ME.convert(values);
+    }
+}

+ 23 - 3
logic/bag-logic/src/main/java/com/iohao/mmo/bag/config/ItemCommandLineRunner.java

@@ -23,6 +23,7 @@ import com.iohao.mmo.bag.entity.ItemConfig;
 import com.iohao.mmo.bag.region.ItemConfigRegion;
 import com.iohao.mmo.bag.region.UseRegion;
 import com.iohao.mmo.bag.region.internal.DefaultUseProcess;
+import com.iohao.mmo.bag.region.internal.equip.BuildEquipUseProcess;
 import jakarta.annotation.Resource;
 import lombok.AllArgsConstructor;
 import org.springframework.boot.CommandLineRunner;
@@ -41,10 +42,9 @@ import java.util.List;
 public class ItemCommandLineRunner implements CommandLineRunner {
     @Resource
     MongoTemplate mongoTemplate;
-
-    final DefaultUseProcess defaultUseProcess;
-
     final UseRegion useRegion;
+    final DefaultUseProcess defaultUseProcess;
+    final BuildEquipUseProcess buildEquipUseProcess;
 
     @Override
     public void run(String... args) {
@@ -52,6 +52,7 @@ public class ItemCommandLineRunner implements CommandLineRunner {
         itemConfigs.forEach(ItemConfigRegion::addItemConfig);
 
         useRegion.addUseProcess(defaultUseProcess);
+        useRegion.addUseProcess(buildEquipUseProcess);
     }
 
     private List<ItemConfig> initConfigExcel() {
@@ -64,11 +65,30 @@ public class ItemCommandLineRunner implements CommandLineRunner {
         config.setName("经验值道具");
         config.setDescription("增加经验值");
 
+        config = new ItemConfig();
+        configList.add(config);
         config.setItemId(ItemIdConst.hpId);
         config.setName("气血药");
         config.setDescription("增加气血值");
 
+        config = new ItemConfig();
+        configList.add(config);
+        config.setItemId(ItemIdConst.equipWeaponBook10);
+        config.setName("10级-武器书");
+        config.setDescription("装备制造书");
+
+        config = new ItemConfig();
+        configList.add(config);
+        config.setItemId(ItemIdConst.iron10);
+        config.setName("10级-铁");
+        config.setDescription("合成装备的精铁");
 
+        config = new ItemConfig();
+        configList.add(config);
+        config.setItemId(ItemIdConst.equipWeapon10);
+        config.setName("10级-飞龙在天");
+        config.setDescription("赵云的私房枪之一,因害怕被张飞拿错,而一直放在房内!");
+        // 临时配置
         return configList;
     }
 }

+ 6 - 30
logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/ItemMapper.java

@@ -18,47 +18,23 @@
  */
 package com.iohao.mmo.bag.mapper;
 
-import com.iohao.game.common.kit.CollKit;
-import com.iohao.mmo.bag.entity.BagItem;
-import com.iohao.mmo.bag.pojo.UseItemPOJO;
-import com.iohao.mmo.bag.pojo.UsePOJO;
-import com.iohao.mmo.bag.proto.UseItemMessage;
-import com.iohao.mmo.bag.proto.UseMessage;
+import com.iohao.mmo.bag.entity.ItemConfig;
+import com.iohao.mmo.bag.proto.ItemMessage;
 import org.mapstruct.Mapper;
-import org.mapstruct.Mapping;
 import org.mapstruct.factory.Mappers;
 
-import java.util.Collections;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author 渔民小镇
- * @date 2023-08-06
+ * @date 2023-08-12
  */
 @Mapper
 public interface ItemMapper {
     ItemMapper ME = Mappers.getMapper(ItemMapper.class);
 
-    BagItem convert(UseItemPOJO useItem);
+    ItemMessage convert(ItemConfig itemConfig);
 
-    @Mapping(target = "useItemMap", source = "useItems")
-    UsePOJO convert(UseMessage useMessage);
-
-    UseItemPOJO convert(UseItemMessage useItemMessage);
-
-    default Map<String, UseItemPOJO> convert(List<UseItemMessage> useItems) {
-        if (CollKit.isEmpty(useItems)) {
-            return Collections.emptyMap();
-        }
-
-        Map<String, UseItemPOJO> map = new HashMap<>();
-        for (UseItemMessage useItem : useItems) {
-            UseItemPOJO convert = convert(useItem);
-            map.put(useItem.itemId, convert);
-        }
-
-        return map;
-    }
+    List<ItemMessage> convert(Collection<ItemConfig> itemConfigs);
 }

+ 63 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/UseItemMapper.java

@@ -0,0 +1,63 @@
+/*
+ * 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.bag.mapper;
+
+import com.iohao.game.common.kit.CollKit;
+import com.iohao.mmo.bag.entity.BagItem;
+import com.iohao.mmo.bag.pojo.UseItemPOJO;
+import com.iohao.mmo.bag.pojo.UsePOJO;
+import com.iohao.mmo.bag.proto.UseItemMessage;
+import com.iohao.mmo.bag.proto.UseMessage;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+import java.util.*;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@Mapper
+public interface UseItemMapper {
+    UseItemMapper ME = Mappers.getMapper(UseItemMapper.class);
+
+    BagItem convert(UseItemPOJO useItem);
+
+    List<BagItem> convertToBagItem(Collection<UseItemPOJO> useItem);
+
+    @Mapping(target = "useItemMap", source = "useItems")
+    UsePOJO convert(UseMessage useMessage);
+
+    UseItemPOJO convert(UseItemMessage useItemMessage);
+
+    default Map<String, UseItemPOJO> convert(List<UseItemMessage> useItems) {
+        if (CollKit.isEmpty(useItems)) {
+            return Collections.emptyMap();
+        }
+
+        Map<String, UseItemPOJO> map = new HashMap<>();
+        for (UseItemMessage useItem : useItems) {
+            UseItemPOJO convert = convert(useItem);
+            map.put(useItem.itemId, convert);
+        }
+
+        return map;
+    }
+}

+ 0 - 1
logic/bag-logic/src/main/java/com/iohao/mmo/bag/pojo/UseItemPOJO.java

@@ -35,5 +35,4 @@ public class UseItemPOJO {
     String itemId;
     /** 使用数量 */
     int quantity;
-
 }

+ 5 - 2
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/ItemConfigRegion.java

@@ -22,6 +22,7 @@ import com.iohao.mmo.bag.entity.ItemConfig;
 import lombok.NonNull;
 import lombok.experimental.UtilityClass;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -32,7 +33,7 @@ import java.util.Map;
 @UtilityClass
 public class ItemConfigRegion {
 
-    public Map<String, ItemConfig> map = new HashMap<>();
+    private final Map<String, ItemConfig> map = new HashMap<>();
 
     public void addItemConfig(@NonNull ItemConfig itemConfig) {
         map.put(itemConfig.getItemId(), itemConfig);
@@ -46,5 +47,7 @@ public class ItemConfigRegion {
         return map.get(itemId);
     }
 
-
+    public Collection<ItemConfig> values() {
+        return map.values();
+    }
 }

+ 43 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/SceneConst.java

@@ -0,0 +1,43 @@
+/*
+ * 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.bag.region;
+
+/**
+ * 物品使用的业务场景
+ *
+ * @author 渔民小镇
+ * @date 2023-08-08
+ */
+public interface SceneConst {
+    /**
+     * 业务场景 - 简单的使用背包物品
+     * <pre>
+     *     通常是使用同一种背包物品,如
+     *     增加 hp 的药品、增加经验值的道具...等
+     * </pre>
+     */
+    String defaultScene = "default";
+    /**
+     * 业务场景 - 打造装备
+     * <pre>
+     *     使用多种不同的背包物品来打造装备,如打造书、材料铁...等
+     * </pre>
+     */
+    String buildEquipScene = "buildEquip";
+}

+ 3 - 2
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/UseContext.java

@@ -33,9 +33,10 @@ import lombok.experimental.FieldDefaults;
 @Setter
 @FieldDefaults(level = AccessLevel.PRIVATE)
 public class UseContext {
+    /** 物品使用 pojo */
     UsePOJO usePOJO;
+    /** flowContext */
     FlowContext flowContext;
+    /** 物品使用的业务场景 */
     String scene;
-
-    boolean success;
 }

+ 11 - 1
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/UseProcess.java

@@ -19,13 +19,23 @@
 package com.iohao.mmo.bag.region;
 
 /**
- * 物品处理
+ * 物品使用逻辑处理接口
  *
  * @author 渔民小镇
  * @date 2023-08-06
  */
 public interface UseProcess {
+    /**
+     * 执行处理
+     *
+     * @param context context
+     */
     void process(UseContext context);
 
+    /**
+     * 业务场景
+     *
+     * @return 业务场景
+     */
     String getScene();
 }

+ 18 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/UseRegion.java

@@ -32,18 +32,36 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 @Component
 public class UseRegion {
+    /**
+     * <pre>
+     *     key : 业务场景
+     *     value : 物品使用逻辑处理实现类
+     * </pre>
+     */
     Map<String, UseProcess> map = new ConcurrentHashMap<>();
 
+    /**
+     * 添加物品使用逻辑处理类
+     *
+     * @param useProcess 物品使用逻辑处理实现类
+     */
     public void addUseProcess(@NonNull UseProcess useProcess) {
         String scene = useProcess.getScene();
         Objects.requireNonNull(scene);
         map.put(scene, useProcess);
     }
 
+    /**
+     * 执行物品使用逻辑
+     *
+     * @param context context
+     */
     public void process(UseContext context) {
+        // 通过业务场景,得到对应的物品使用逻辑处理实现类
         String scene = context.getScene();
         UseProcess useProcess = map.get(scene);
         ActionErrorEnum.classNotExist.assertNonNull(useProcess);
+        // 开始处理
         useProcess.process(context);
     }
 }

+ 11 - 8
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/internal/DefaultUseProcess.java

@@ -22,15 +22,17 @@ import com.iohao.game.action.skeleton.core.exception.ActionErrorEnum;
 import com.iohao.game.action.skeleton.core.flow.FlowContext;
 import com.iohao.mmo.bag.ItemIdConst;
 import com.iohao.mmo.bag.entity.BagItem;
-import com.iohao.mmo.bag.mapper.ItemMapper;
+import com.iohao.mmo.bag.mapper.UseItemMapper;
 import com.iohao.mmo.bag.pojo.UseItemPOJO;
 import com.iohao.mmo.bag.pojo.UsePOJO;
+import com.iohao.mmo.bag.region.SceneConst;
 import com.iohao.mmo.bag.region.UseContext;
 import com.iohao.mmo.bag.region.UseProcess;
 import com.iohao.mmo.bag.service.BagService;
 import com.iohao.mmo.level.client.LevelExchange;
 import com.iohao.mmo.level.proto.ExpMessage;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
 import java.util.Map;
@@ -45,12 +47,18 @@ import java.util.Map;
  * @author 渔民小镇
  * @date 2023-08-06
  */
+@Slf4j
 @Component
 @AllArgsConstructor
 public class DefaultUseProcess implements UseProcess {
 
     final BagService bagService;
 
+    @Override
+    public String getScene() {
+        return SceneConst.defaultScene;
+    }
+
     @Override
     public void process(UseContext context) {
         UsePOJO usePOJO = context.getUsePOJO();
@@ -63,7 +71,7 @@ public class DefaultUseProcess implements UseProcess {
         UseItemPOJO useItem = usePOJO.getUseItem();
 
         // 减少物品
-        BagItem bagItem = ItemMapper.ME.convert(useItem);
+        BagItem bagItem = UseItemMapper.ME.convert(useItem);
         bagService.decrementItem(bagItem, userId);
 
         /*
@@ -80,7 +88,7 @@ public class DefaultUseProcess implements UseProcess {
         }
     }
 
-    private static void extractedExp(UseItemPOJO useItem, FlowContext flowContext) {
+    private void extractedExp(UseItemPOJO useItem, FlowContext flowContext) {
         ExpMessage expMessage = new ExpMessage();
         expMessage.id = flowContext.getUserId();
         // 暂时写死
@@ -88,9 +96,4 @@ public class DefaultUseProcess implements UseProcess {
         // 调用添加经验值 api
         LevelExchange.addExpPerson(expMessage, flowContext);
     }
-
-    @Override
-    public String getScene() {
-        return "default";
-    }
 }

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

@@ -0,0 +1,134 @@
+/*
+ * 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.bag.region.internal.equip;
+
+import com.iohao.game.action.skeleton.core.exception.ActionErrorEnum;
+import com.iohao.game.external.client.kit.SplitParam;
+import com.iohao.mmo.bag.ItemIdTypeConst;
+import com.iohao.mmo.bag.pojo.UseItemPOJO;
+import com.iohao.mmo.common.config.GameCode;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.experimental.FieldDefaults;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 装备制造所需物品解析
+ *
+ * @author 渔民小镇
+ * @date 2023-08-08
+ */
+@FieldDefaults(level = AccessLevel.PRIVATE)
+class BuildEquipParse {
+    final Map<String, BuildParam> paramMap = new HashMap<>();
+
+    BuildEquipParse(Map<String, UseItemPOJO> useItemMap) {
+        for (Map.Entry<String, UseItemPOJO> entry : useItemMap.entrySet()) {
+            UseItemPOJO value = entry.getValue();
+            // 物品 id
+            String itemId = value.itemId;
+
+            var param = new BuildParam(itemId, value);
+            paramMap.put(param.getItemType(), param);
+        }
+    }
+
+    /**
+     * 所需物品校验
+     */
+    void verify() {
+        /*
+         * 装备的制造最少需要两样物品
+         * 1 装备制造书
+         * 2 装备制造材料
+         */
+        ActionErrorEnum validateErrCode = ActionErrorEnum.validateErrCode;
+
+        // 装备打造业务,目前只支持使用两样物品
+        validateErrCode.assertTrue(paramMap.size() == 2);
+
+        // 校验制造书相关
+        BuildParam equipBuildParam = getEquipBuildParam();
+        validateErrCode.assertNonNull(equipBuildParam, "没有使用装备制造书");
+        GameCode.quantityNotEnough
+                .assertTrue(equipBuildParam.useItem.quantity == 1, "制造书数量错误");
+
+        // 校验制造材料相关
+        BuildParam ironBuildParam = getIronBuildParam();
+        validateErrCode.assertNonNull(ironBuildParam, "没有使用装备制造材料");
+        GameCode.quantityNotEnough
+                .assertTrue(ironBuildParam.useItem.quantity == 1, "制造材料数量错误");
+
+        // 校验材料匹配相关
+        boolean result = equipBuildParam.getLevel() > ironBuildParam.getLevel();
+        validateErrCode.assertTrueThrows(result, "装备制造错误,材料不匹配");
+    }
+
+    /**
+     * 得到装备制造书
+     *
+     * @return 装备制造书
+     */
+    BuildParam getEquipBuildParam() {
+        // 得到装备
+        return paramMap.get(ItemIdTypeConst.equip);
+    }
+
+    /**
+     * 得到装备制造材料 - 铁
+     *
+     * @return 装备制造材料 - 铁
+     */
+    BuildParam getIronBuildParam() {
+        // 得到装备制造材料 - 铁
+        return paramMap.get(ItemIdTypeConst.iron);
+    }
+
+    @Getter
+    @FieldDefaults(level = AccessLevel.PRIVATE)
+    static class BuildParam extends SplitParam {
+        final UseItemPOJO useItem;
+
+        public BuildParam(String itemId, UseItemPOJO useItem) {
+            super(itemId, "_");
+            this.useItem = useItem;
+        }
+
+        String getItemType() {
+            return this.getString(0);
+        }
+
+        int getLevel() {
+            // 约定最后一个参数是等级
+            int length = length();
+            return this.getInt(length - 1, 0);
+        }
+
+        int length() {
+            return this.getSplit().length;
+        }
+
+        String getEquipItemId() {
+            String itemId = useItem.itemId;
+            return itemId.replace("book_", "");
+        }
+    }
+}

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

@@ -0,0 +1,110 @@
+/*
+ * 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.bag.region.internal.equip;
+
+import com.iohao.game.action.skeleton.core.exception.ActionErrorEnum;
+import com.iohao.game.action.skeleton.core.flow.FlowContext;
+import com.iohao.game.common.kit.TimeKit;
+import com.iohao.mmo.bag.entity.BagItem;
+import com.iohao.mmo.bag.mapper.UseItemMapper;
+import com.iohao.mmo.bag.pojo.UseItemPOJO;
+import com.iohao.mmo.bag.pojo.UsePOJO;
+import com.iohao.mmo.bag.region.SceneConst;
+import com.iohao.mmo.bag.region.UseContext;
+import com.iohao.mmo.bag.region.UseProcess;
+import com.iohao.mmo.bag.service.BagService;
+import com.iohao.mmo.common.config.GameCode;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 打造装备 - 物品使用逻辑处理类
+ * <pre>
+ *     1. 将物品从背包中减少(打造书、打造材料)
+ *     2. 调用装备模块的 【打造装备 action】,得到新的装备 id。
+ *     3. 将装备 id 关联到背包物品中。
+ * </pre>
+ *
+ * @author 渔民小镇
+ * @date 2023-08-08
+ */
+@Slf4j
+@Component
+@AllArgsConstructor
+public class BuildEquipUseProcess implements UseProcess {
+    final BagService bagService;
+
+    @Override
+    public String getScene() {
+        return SceneConst.buildEquipScene;
+    }
+
+    @Override
+    public void process(UseContext context) {
+        UsePOJO usePOJO = context.getUsePOJO();
+        Map<String, UseItemPOJO> useItemMap = usePOJO.useItemMap;
+        ActionErrorEnum.dataNotExist.assertTrueThrows(useItemMap.isEmpty());
+        FlowContext flowContext = context.getFlowContext();
+        long userId = flowContext.getUserId();
+
+        // 校验物品合法性
+        BuildEquipParse buildEquipParse = new BuildEquipParse(useItemMap);
+        buildEquipParse.verify();
+
+        // 物品数量检测
+        List<BagItem> bagItems = UseItemMapper.ME.convertToBagItem(useItemMap.values());
+        boolean contains = bagService.contains(bagItems, userId);
+        GameCode.quantityNotEnough.assertTrue(contains);
+
+        // 减少背包的物品
+        for (BagItem bagItem : bagItems) {
+            bagService.decrementItem(bagItem, userId);
+        }
+
+        // 调用【装备模块】的打造 api
+        BuildEquipParse.BuildParam equipBuildParam = buildEquipParse.getEquipBuildParam();
+        BagItem equip = createEquip(equipBuildParam);
+
+        // 将新装备添加到背包中
+        bagService.incrementItem(equip, userId);
+    }
+
+    private BagItem createEquip(BuildEquipParse.BuildParam buildParam) {
+        // TODO 这里后续调用【装备模块】生成装备的 action,目前先暂时写假数据。
+        // 得到对应装备的 itemId
+        String equipItemId = buildParam.getEquipItemId();
+
+        // 为了方便观察数据,这里生成有规律的装备id
+        String formatter = TimeKit.formatter(System.currentTimeMillis());
+        String equipId = equipItemId + "_" + formatter;
+
+        BagItem bagItem = new BagItem();
+        bagItem.setId(equipId);
+        bagItem.setItemId(equipItemId);
+        bagItem.setQuantity(1);
+
+        log.info("调用【装备模块-api】开始打造装备 : {}", bagItem);
+
+        return bagItem;
+    }
+}

+ 21 - 4
logic/bag-logic/src/main/java/com/iohao/mmo/bag/service/BagService.java

@@ -28,10 +28,7 @@ import lombok.AllArgsConstructor;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 
 /**
  * @author 渔民小镇
@@ -109,6 +106,26 @@ public class BagService {
         return bagItem;
     }
 
+    public boolean contains(List<BagItem> itemList, long userId) {
+        Bag bag = ofBag(userId);
+        Map<String, BagItem> itemMap = bag.getItemMap();
+
+        for (BagItem item : itemList) {
+            String bagItemId = item.getId();
+            BagItem bagItem = itemMap.get(bagItemId);
+            if (Objects.isNull(bagItem)) {
+                return false;
+            }
+
+            // 数量检测
+            if (bagItem.getQuantity() < item.getQuantity()) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     public void use(UseContext context) {
 
     }

+ 0 - 38
logic/item-logic/.gitignore

@@ -1,38 +0,0 @@
-target/
-!.mvn/wrapper/maven-wrapper.jar
-!**/src/main/**/target/
-!**/src/test/**/target/
-
-### IntelliJ IDEA ###
-.idea/modules.xml
-.idea/jarRepositories.xml
-.idea/compiler.xml
-.idea/libraries/
-*.iws
-*.iml
-*.ipr
-
-### Eclipse ###
-.apt_generated
-.classpath
-.factorypath
-.project
-.settings
-.springBeans
-.sts4-cache
-
-### NetBeans ###
-/nbproject/private/
-/nbbuild/
-/dist/
-/nbdist/
-/.nb-gradle/
-build/
-!**/src/main/**/build/
-!**/src/test/**/build/
-
-### VS Code ###
-.vscode/
-
-### Mac OS ###
-.DS_Store

+ 0 - 34
logic/item-logic/pom.xml

@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>com.iohao.mmo</groupId>
-        <artifactId>game</artifactId>
-        <version>1.0-SNAPSHOT</version>
-        <relativePath>../../pom.xml</relativePath>
-    </parent>
-
-    <artifactId>item-logic</artifactId>
-
-    <properties>
-        <maven.compiler.source>17</maven.compiler.source>
-        <maven.compiler.target>17</maven.compiler.target>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    </properties>
-    <dependencies>
-        <!-- 游戏逻辑服通用模块 -->
-        <dependency>
-            <groupId>com.iohao.mmo</groupId>
-            <artifactId>a-logic-common</artifactId>
-            <version>${project.parent.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.iohao.mmo</groupId>
-            <artifactId>item-provide</artifactId>
-            <version>${project.parent.version}</version>
-        </dependency>
-    </dependencies>
-</project>

+ 5 - 1
one-client/src/main/java/com/iohao/mmo/client/CommonClient.java

@@ -23,6 +23,7 @@ import com.iohao.game.external.client.join.ClientRunOne;
 import com.iohao.game.external.client.user.ClientUser;
 import com.iohao.game.external.client.user.DefaultClientUser;
 import com.iohao.mmo.bag.client.BagInputCommandRegion;
+import com.iohao.mmo.bag.client.ItemInputCommandRegion;
 import com.iohao.mmo.equip.client.EquipInputCommandRegion;
 import com.iohao.mmo.level.client.LevelInputCommandRegion;
 import com.iohao.mmo.login.client.LoginInputCommandRegion;
@@ -56,6 +57,7 @@ public class CommonClient {
         PersonInputCommandRegion personInputCommandRegion = new PersonInputCommandRegion();
         LevelInputCommandRegion levelInputCommandRegion = new LevelInputCommandRegion();
         BagInputCommandRegion bagInputCommandRegion = new BagInputCommandRegion();
+        ItemInputCommandRegion itemInputCommandRegion = new ItemInputCommandRegion();
         EquipInputCommandRegion equipInputCommandRegion = new EquipInputCommandRegion();
 
         // 模拟请求数据
@@ -63,11 +65,13 @@ public class CommonClient {
                 // 登录
                 loginInputCommandRegion
                 // 地图
-                , mapInputCommandRegion
+//                , mapInputCommandRegion
                 // 人物、英雄
 //                , personInputCommandRegion
                 // 等级相关
                 , levelInputCommandRegion
+                // 物品
+                , itemInputCommandRegion
                 // 背包
                 , bagInputCommandRegion
                 // 装备相关

+ 0 - 2
pom.xml

@@ -39,8 +39,6 @@
         <module>provide/map-provide</module>
         <module>logic/level-logic</module>
         <module>provide/level-provide</module>
-        <module>logic/item-logic</module>
-        <module>provide/item-provide</module>
         <module>logic/bag-logic</module>
         <module>provide/bag-provide</module>
         <module>logic/equip-logic</module>

+ 0 - 6
provide/all-provide/pom.xml

@@ -49,12 +49,6 @@
             <version>${project.parent.version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>com.iohao.mmo</groupId>
-            <artifactId>item-provide</artifactId>
-            <version>${project.parent.version}</version>
-        </dependency>
-
         <dependency>
             <groupId>com.iohao.mmo</groupId>
             <artifactId>bag-provide</artifactId>

+ 9 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/ItemIdConst.java

@@ -19,10 +19,19 @@
 package com.iohao.mmo.bag;
 
 /**
+ * 物品 id - itemId
+ *
  * @author 渔民小镇
  * @date 2023-08-06
  */
 public interface ItemIdConst {
     String expId = "exp";
     String hpId = "hp";
+    /** 装备 - 武器书 - 10 级 */
+    String equipWeaponBook10 = ItemIdTypeConst.equip + "_weapon_book_10";
+    /** 铁 - 10 级 */
+    String iron10 = ItemIdTypeConst.iron + "_10";
+    /** 装备 - 武器 - 10 级 */
+    String equipWeapon10 = ItemIdTypeConst.equip + "_weapon_10";
+
 }

+ 30 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/ItemIdTypeConst.java

@@ -0,0 +1,30 @@
+/*
+ * 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.bag;
+
+/**
+ * 物品大类
+ *
+ * @author 渔民小镇
+ * @date 2023-08-08
+ */
+public interface ItemIdTypeConst {
+    String equip = "equip";
+    String iron = "iron";
+}

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

@@ -18,16 +18,17 @@
  */
 package com.iohao.mmo.bag.client;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.iohao.game.action.skeleton.protocol.wrapper.BoolValue;
 import com.iohao.game.external.client.AbstractInputCommandRegion;
 import com.iohao.game.external.client.command.InputRequestData;
 import com.iohao.game.external.client.kit.ScannerKit;
 import com.iohao.game.external.client.kit.SplitParam;
 import com.iohao.mmo.bag.ItemIdConst;
+import com.iohao.mmo.bag.client.ext.ClientBagAttr;
+import com.iohao.mmo.bag.client.ext.ItemMessageMap;
 import com.iohao.mmo.bag.cmd.BagCmd;
-import com.iohao.mmo.bag.proto.BagItemMessage;
-import com.iohao.mmo.bag.proto.BagMessage;
-import com.iohao.mmo.bag.proto.UseMessage;
+import com.iohao.mmo.bag.proto.*;
 import com.iohao.mmo.common.provide.kit.JsonKit;
 import com.iohao.mmo.common.snow.SnowKit;
 import lombok.extern.slf4j.Slf4j;
@@ -50,16 +51,38 @@ public class BagInputCommandRegion extends AbstractInputCommandRegion {
     @Override
     public void loginSuccessCallback() {
         // 添加一些经验值道具
-        var bagItemMessage = BagInternalHelper.ofBagItemMessage(ItemIdConst.expId);
+        BagItemMessage bagItemMessage = BagInternalHelper.ofBagItemMessage(ItemIdConst.expId);
         bagItemMessage.quantity = 10;
         log.info("添加 {} 个经验值道具 {}", bagItemMessage.quantity, bagItemMessage);
         ofRequestCommand(BagCmd.incrementItem).request(bagItemMessage);
+
+        // 添加一些装备制造书材料
+        bagItemMessage = BagInternalHelper.ofBagItemMessage(ItemIdConst.equipWeaponBook10);
+        bagItemMessage.quantity = 1;
+        log.info("添加 {} 【装备-武器】制造书材料 {}", bagItemMessage.quantity, bagItemMessage);
+        ofRequestCommand(BagCmd.incrementItem).request(bagItemMessage);
+
+        // 添加一些装备制造书材料
+        bagItemMessage = BagInternalHelper.ofBagItemMessage(ItemIdConst.iron10);
+        bagItemMessage.quantity = 1;
+        log.info("添加 {} 装备-制造材料-铁 {}", bagItemMessage.quantity, bagItemMessage);
+        ofRequestCommand(BagCmd.incrementItem).request(bagItemMessage);
     }
 
     private void request() {
         ofCommand(BagCmd.bag).callback(BagMessage.class, result -> {
+            ItemMessageMap itemMessageMap = clientUser.option(ClientBagAttr.itemMessageMapAttrOption);
+
             BagMessage value = result.getValue();
-            log.info("{}", JsonKit.toJsonString(value));
+
+            List<JSONObject> list = value.itemMap.values().stream().map(bagItemMessage -> {
+                String itemId = bagItemMessage.itemId;
+                JSONObject bagItemMessageJson = JSONObject.from(bagItemMessage);
+                JSONObject itemMessageJson = itemMessageMap.getItemMessageJSON(itemId);
+                return JsonKit.merge(bagItemMessageJson, itemMessageJson);
+            }).toList();
+
+            log.info("查询玩家背包 {}", JsonKit.toJsonString(list));
         }).setDescription("查询玩家背包");
 
         InputRequestData inputRequestData = () -> {
@@ -114,24 +137,13 @@ public class BagInputCommandRegion extends AbstractInputCommandRegion {
             // 重新查询一次背包
             ofRequestCommand(BagCmd.bag).request();
         }).setDescription("从背包减少物品").setInputRequestData(inputRequestData);
-
-
     }
 
     private void useRequest() {
         InputRequestData inputRequestData = () -> {
-            ScannerKit.log(() -> log.info("输入需要使用的背包物品,格式 [背包物品id-数量]"));
-            String inputType = ScannerKit.nextLine("1-1");
-
-            SplitParam param = new SplitParam(inputType);
-            String id = param.getString(0);
-            int quantity = param.getInt(1, 1);
-
-            var useItemMessage = BagInternalHelper.ofUseItemMessage(id);
-            useItemMessage.quantity = quantity;
-
             UseMessage useMessage = new UseMessage();
-            useMessage.useItems = List.of(useItemMessage);
+            useMessage.useItems = sceneDefault();
+            ScannerKit.log(() -> log.info("当前所使用的物品信息 : {}", JsonKit.toJsonString(useMessage)));
             return useMessage;
         };
 
@@ -139,5 +151,52 @@ public class BagInputCommandRegion extends AbstractInputCommandRegion {
             var value = result.getValue();
             log.info("value : {}", value);
         }).setDescription("使用背包物品").setInputRequestData(inputRequestData);
+
+        InputRequestData buildEquipInputRequestData = () -> {
+            UseMessage useMessage = new UseMessage();
+            useMessage.useItems = sceneBuildEquip();
+            ScannerKit.log(() -> log.info("打造装备-所使用物品 : {}", JsonKit.toJsonString(useMessage)));
+            return useMessage;
+        };
+
+        ofCommand(BagCmd.useBuildEquip).callback(BoolValue.class, result -> {
+            var value = result.getValue();
+            log.info("value : {}", value);
+        }).setDescription("打造装备").setInputRequestData(buildEquipInputRequestData);
+    }
+
+    private List<UseItemMessage> sceneBuildEquip() {
+        ScannerKit.log(() -> {
+            log.info("装备的制造最少需要使用两样背包物品,1.装备制造书、2.装备制造材料");
+            log.info("格式 [制造书物品id-制造铁物品id]");
+        });
+
+        String defaultValue = ItemIdConst.equipWeaponBook10 + "-" + ItemIdConst.iron10;
+        String inputType = defaultValue;
+//         inputType = ScannerKit.nextLine(defaultValue);
+        SplitParam param = new SplitParam(inputType);
+
+        String equipWeaponBook = param.getString(0, ItemIdConst.equipWeaponBook10);
+        UseItemMessage useItemMessageEquip = BagInternalHelper.ofUseItemMessage(equipWeaponBook);
+
+        String iron = param.getString(1, ItemIdConst.iron10);
+        UseItemMessage useItemMessageIron = BagInternalHelper.ofUseItemMessage(iron);
+
+        return List.of(useItemMessageEquip, useItemMessageIron);
+    }
+
+    private List<UseItemMessage> sceneDefault() {
+        ScannerKit.log(() -> log.info("输入需要使用的背包物品,格式 [背包物品id-数量]"));
+        String inputType = ScannerKit.nextLine("1-1");
+        SplitParam param = new SplitParam(inputType);
+        // 得到下标 0 的值
+        String id = param.getString(0);
+        // 得到下标 1 的值,如果值不存在,则使用默认的 1 代替
+        int quantity = param.getInt(1, 1);
+
+        var useItemMessage = BagInternalHelper.ofUseItemMessage(id);
+        useItemMessage.quantity = quantity;
+
+        return List.of(useItemMessage);
     }
 }

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

@@ -0,0 +1,54 @@
+/*
+ * 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.bag.client;
+
+import com.iohao.game.action.skeleton.protocol.wrapper.ByteValueList;
+import com.iohao.game.common.kit.attr.AttrOption;
+import com.iohao.game.external.client.AbstractInputCommandRegion;
+import com.iohao.mmo.bag.client.ext.ClientBagAttr;
+import com.iohao.mmo.bag.client.ext.ItemMessageMap;
+import com.iohao.mmo.bag.cmd.ItemCmd;
+import com.iohao.mmo.bag.proto.ItemMessage;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-13
+ */
+@Slf4j
+public class ItemInputCommandRegion extends AbstractInputCommandRegion {
+    @Override
+    public void initInputCommand() {
+        this.inputCommandCreate.cmd = ItemCmd.cmd;
+
+        ofCommand(ItemCmd.listItem).callback(ByteValueList.class, result -> {
+            List<ItemMessage> list = result.toList(ItemMessage.class);
+            AttrOption<ItemMessageMap> itemMessageMapAttrOption = ClientBagAttr.itemMessageMapAttrOption;
+            ItemMessageMap itemMessageMap = new ItemMessageMap(list);
+            clientUser.option(itemMessageMapAttrOption, itemMessageMap);
+        }).setDescription("物品配置列表");
+    }
+
+    @Override
+    public void loginSuccessCallback() {
+        ofRequestCommand(ItemCmd.listItem).request();
+    }
+}

+ 6 - 11
logic/bag-logic/src/main/java/com/iohao/mmo/bag/region/internal/ExpItemProcess.java → provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/ext/ClientBagAttr.java

@@ -16,20 +16,15 @@
  * 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.bag.region.internal;
+package com.iohao.mmo.bag.client.ext;
 
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.experimental.FieldDefaults;
+import com.iohao.game.common.kit.attr.AttrOption;
 
 /**
  * @author 渔民小镇
- * @date 2023-08-06
+ * @date 2023-08-13
  */
-@Getter
-@Setter
-@FieldDefaults(level = AccessLevel.PRIVATE)
-public class ExpItemProcess {
+public interface ClientBagAttr {
+    AttrOption<ItemMessageMap> itemMessageMapAttrOption = AttrOption.valueOf("itemMessageMapAttrOption");
 
-}
+}

+ 52 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/ext/ItemMessageMap.java

@@ -0,0 +1,52 @@
+/*
+ * 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.bag.client.ext;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.iohao.mmo.bag.proto.ItemMessage;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-13
+ */
+@ToString
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class ItemMessageMap {
+    final Map<String, ItemMessage> map = new HashMap<>();
+
+    public ItemMessageMap(List<ItemMessage> itemMessageList) {
+        itemMessageList.forEach(itemMessage -> map.put(itemMessage.itemId, itemMessage));
+    }
+
+    public ItemMessage getItemMessage(String itemId) {
+        return map.get(itemId);
+    }
+
+    public JSONObject getItemMessageJSON(String itemId) {
+        ItemMessage itemMessage = getItemMessage(itemId);
+        return JSONObject.from(itemMessage);
+    }
+}

+ 2 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/cmd/BagCmd.java

@@ -38,6 +38,8 @@ public interface BagCmd {
 
     /** 使用物品 */
     int use = 5;
+    /** 打造装备 */
+    int useBuildEquip = 6;
 
     static CmdInfo of(int subCmd) {
         return CmdInfo.of(cmd, subCmd);

+ 4 - 9
provide/item-provide/src/main/java/com/iohao/mmo/item/cmd/ItemCmd.java → provide/bag-provide/src/main/java/com/iohao/mmo/bag/cmd/ItemCmd.java

@@ -16,21 +16,16 @@
  * 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.item.cmd;
+package com.iohao.mmo.bag.cmd;
 
-import com.iohao.game.action.skeleton.core.CmdInfo;
 import com.iohao.mmo.common.provide.cmd.CmdModule;
 
 /**
  * @author 渔民小镇
- * @date 2023-08-04
+ * @date 2023-08-12
  */
 public interface ItemCmd {
     int cmd = CmdModule.itemCmd;
-    /** 使用物品 */
-    int use = 1;
-
-    static CmdInfo of(int subCmd) {
-        return CmdInfo.of(cmd, subCmd);
-    }
+    /** 物品配置列表 */
+    int listItem = 1;
 }

+ 42 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/ItemMessage.java

@@ -0,0 +1,42 @@
+/*
+ * 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.bag.proto;
+
+import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+/**
+ * 物品信息
+ *
+ * @author 渔民小镇
+ * @date 2023-08-13
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class ItemMessage {
+    /** itemId */
+    String itemId;
+    /** 物品名 */
+    String name;
+    /** 物品描述 */
+    String description;
+}

+ 5 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/UseMessage.java

@@ -19,6 +19,7 @@
 package com.iohao.mmo.bag.proto;
 
 import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
+import com.iohao.game.common.kit.CollKit;
 import lombok.AccessLevel;
 import lombok.ToString;
 import lombok.experimental.FieldDefaults;
@@ -47,6 +48,10 @@ public class UseMessage {
      */
     public boolean verify() {
 
+        if (CollKit.isEmpty(this.useItems)) {
+            return false;
+        }
+
         for (UseItemMessage useItem : useItems) {
             if (!useItem.verify()) {
                 return false;

+ 15 - 0
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/kit/JsonKit.java

@@ -19,9 +19,12 @@
 package com.iohao.mmo.common.provide.kit;
 
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONWriter;
 import lombok.experimental.UtilityClass;
 
+import java.util.Objects;
+
 /**
  * @author 渔民小镇
  * @date 2023-08-01
@@ -37,4 +40,16 @@ public class JsonKit {
     public String toJsonString(Object value) {
         return JSON.toJSONString(value, JSONWriter.Feature.PrettyFormat);
     }
+
+    public JSONObject merge(JSONObject... jsonObjects) {
+        JSONObject json = new JSONObject();
+
+        for (JSONObject jsonObject : jsonObjects) {
+            if (Objects.nonNull(jsonObject)) {
+                json.putAll(jsonObject);
+            }
+        }
+
+        return json;
+    }
 }

+ 0 - 38
provide/item-provide/.gitignore

@@ -1,38 +0,0 @@
-target/
-!.mvn/wrapper/maven-wrapper.jar
-!**/src/main/**/target/
-!**/src/test/**/target/
-
-### IntelliJ IDEA ###
-.idea/modules.xml
-.idea/jarRepositories.xml
-.idea/compiler.xml
-.idea/libraries/
-*.iws
-*.iml
-*.ipr
-
-### Eclipse ###
-.apt_generated
-.classpath
-.factorypath
-.project
-.settings
-.springBeans
-.sts4-cache
-
-### NetBeans ###
-/nbproject/private/
-/nbbuild/
-/dist/
-/nbdist/
-/.nb-gradle/
-build/
-!**/src/main/**/build/
-!**/src/test/**/build/
-
-### VS Code ###
-.vscode/
-
-### Mac OS ###
-.DS_Store

+ 0 - 27
provide/item-provide/pom.xml

@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>com.iohao.mmo</groupId>
-        <artifactId>game</artifactId>
-        <version>1.0-SNAPSHOT</version>
-        <relativePath>../../pom.xml</relativePath>
-    </parent>
-
-    <artifactId>item-provide</artifactId>
-
-    <properties>
-        <maven.compiler.source>17</maven.compiler.source>
-        <maven.compiler.target>17</maven.compiler.target>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    </properties>
-    <dependencies>
-        <dependency>
-            <groupId>com.iohao.mmo</groupId>
-            <artifactId>common-provide</artifactId>
-            <version>${project.parent.version}</version>
-        </dependency>
-    </dependencies>
-</project>