Эх сурвалжийг харах

Merge branch 'main' of https://codeup.aliyun.com/62c1add3e4166464dc314001/mmo/ioGameMMO

# Conflicts:
#	logic/all-logic/pom.xml
#	one-application/src/main/java/com/iohao/mmo/OneApplication.java
#	one-client/src/main/java/com/iohao/mmo/client/CommonClient.java
#	pom.xml
#	provide/all-provide/pom.xml
#	provide/common-provide/src/main/java/com/iohao/mmo/common/provide/cmd/CmdModule.java
tangbin 1 жил өмнө
parent
commit
4274d59ea3
49 өөрчлөгдсөн 1784 нэмэгдсэн , 22 устгасан
  1. 5 2
      common/common-core/src/main/java/com/iohao/mmo/common/config/GameCode.java
  2. 36 0
      common/common-core/src/main/java/com/iohao/mmo/common/kit/MessageKit.java
  3. 4 0
      common/common-core/src/main/java/com/iohao/mmo/common/snow/SnowKit.java
  4. 1 0
      logic/a-logic-common/src/main/java/com/iohao/mmo/config/MongoConfig.java
  5. 11 1
      logic/all-logic/pom.xml
  6. 38 0
      logic/bag-logic/.gitignore
  7. 34 0
      logic/bag-logic/pom.xml
  8. 54 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/BagLogicServer.java
  9. 128 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/action/BagAction.java
  10. 63 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/config/ItemCommandLineRunner.java
  11. 50 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/config/ItemConfigRegion.java
  12. 42 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/entity/Bag.java
  13. 72 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/entity/BagItem.java
  14. 43 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/entity/ItemConfig.java
  15. 44 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/BagMapper.java
  16. 61 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/ItemMapper.java
  17. 39 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/pojo/UseItemPOJO.java
  18. 52 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/pojo/UsePOJO.java
  19. 31 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/repository/BagRepository.java
  20. 110 0
      logic/bag-logic/src/main/java/com/iohao/mmo/bag/service/BagService.java
  21. 38 0
      logic/item-logic/.gitignore
  22. 34 0
      logic/item-logic/pom.xml
  23. 0 7
      logic/level-logic/src/main/java/com/iohao/mmo/level/LevelLogicServer.java
  24. 2 2
      logic/level-logic/src/main/java/com/iohao/mmo/level/action/LevelAction.java
  25. 2 2
      logic/map-logic/src/main/java/com/iohao/mmo/map/action/MapAction.java
  26. 1 1
      logic/person-logic/src/main/java/com/iohao/mmo/person/action/PersonAction.java
  27. 4 0
      one-application/src/main/java/com/iohao/mmo/OneApplication.java
  28. 3 2
      one-application/src/main/resources/logback-spring.xml
  29. 6 1
      one-client/src/main/java/com/iohao/mmo/client/CommonClient.java
  30. 5 1
      pom.xml
  31. 12 0
      provide/all-provide/pom.xml
  32. 38 0
      provide/bag-provide/.gitignore
  33. 33 0
      provide/bag-provide/pom.xml
  34. 28 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/ItemIdConst.java
  35. 57 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagExchange.java
  36. 143 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagInputCommandRegion.java
  37. 48 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagInternalHelper.java
  38. 45 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/cmd/BagCmd.java
  39. 42 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/BagItemMessage.java
  40. 40 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/BagMessage.java
  41. 64 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/UseItemMessage.java
  42. 58 0
      provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/UseMessage.java
  43. 6 0
      provide/common-provide/pom.xml
  44. 49 0
      provide/common-provide/src/main/java/com/iohao/mmo/common/provide/client/ExchangeKit.java
  45. 5 1
      provide/common-provide/src/main/java/com/iohao/mmo/common/provide/cmd/CmdModule.java
  46. 38 0
      provide/item-provide/.gitignore
  47. 27 0
      provide/item-provide/pom.xml
  48. 36 0
      provide/item-provide/src/main/java/com/iohao/mmo/item/cmd/ItemCmd.java
  49. 2 2
      provide/level-provide/src/main/java/com/iohao/mmo/level/cmd/LevelCmd.java

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

@@ -32,9 +32,12 @@ import lombok.experimental.FieldDefaults;
 public enum GameCode implements MsgExceptionInfo {
 
     /** 地图不存在 */
-    MAP_NOT_EXIST(1, "地图不存在"),
+    mapNotExist(1, "地图不存在"),
     /** 升级错误,经验值不足 */
-    UP_LEVEL_ERROR(2, "升级错误,经验值不足");
+    upLevelError(2, "升级错误,经验值不足"),
+    /** 数量不足 */
+    quantityNotEnough(3, "数量不足"),
+    ;
 
     /** 消息码 */
     final int code;

+ 36 - 0
common/common-core/src/main/java/com/iohao/mmo/common/kit/MessageKit.java

@@ -0,0 +1,36 @@
+/*
+ * 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.kit;
+
+import com.iohao.game.action.skeleton.core.DataCodecKit;
+import com.iohao.game.action.skeleton.protocol.ResponseMessage;
+import lombok.experimental.UtilityClass;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@UtilityClass
+public class MessageKit {
+    public <T> T getData(ResponseMessage responseMessage, Class<T> clazz) {
+        // 将字节解析成对象
+        byte[] dataContent = responseMessage.getData();
+        return DataCodecKit.decode(dataContent, clazz);
+    }
+}

+ 4 - 0
common/common-core/src/main/java/com/iohao/mmo/common/snow/SnowKit.java

@@ -41,4 +41,8 @@ public class SnowKit {
     public long next() throws IdGeneratorException {
         return idGenerator.next();
     }
+
+    public String nextToString() {
+        return String.valueOf(next());
+    }
 }

+ 1 - 0
logic/a-logic-common/src/main/java/com/iohao/mmo/config/MongoConfig.java

@@ -33,6 +33,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
  */
 @Configuration
 @EnableMongoAuditing
+//@EnableMongoRepositories
 public class MongoConfig extends AbstractMongoClientConfiguration {
 
     @Override

+ 11 - 1
logic/all-logic/pom.xml

@@ -31,7 +31,6 @@
             <version>${project.parent.version}</version>
         </dependency>
 
-
         <dependency>
             <groupId>com.iohao.mmo</groupId>
             <artifactId>map-logic</artifactId>
@@ -44,6 +43,17 @@
             <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>
+            <version>${project.parent.version}</version>
+        </dependency>
         <dependency>
             <groupId>com.iohao.mmo</groupId>
             <artifactId>equip-logic</artifactId>

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

@@ -0,0 +1,38 @@
+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

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

@@ -0,0 +1,34 @@
+<?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>bag-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>bag-provide</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+    </dependencies>
+</project>

+ 54 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/BagLogicServer.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;
+
+import com.iohao.game.action.skeleton.core.BarSkeleton;
+import com.iohao.game.action.skeleton.core.BarSkeletonBuilder;
+import com.iohao.game.bolt.broker.client.AbstractBrokerClientStartup;
+import com.iohao.game.bolt.broker.core.client.BrokerClientBuilder;
+import com.iohao.mmo.bag.action.BagAction;
+import com.iohao.mmo.common.logic.server.LogicServerKit;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+public class BagLogicServer extends AbstractBrokerClientStartup {
+    @Override
+    public BarSkeleton createBarSkeleton() {
+        // 业务框架构建器
+        BarSkeletonBuilder builder = LogicServerKit
+                .createBuilder(BagAction.class);
+
+        extractedSendDco(builder);
+
+        return builder.build();
+    }
+
+    @Override
+    public BrokerClientBuilder createBrokerClientBuilder() {
+        BrokerClientBuilder builder = LogicServerKit.newBrokerClientBuilder();
+        builder.appName("背包逻辑服");
+        return builder;
+    }
+
+    private void extractedSendDco(BarSkeletonBuilder builder) {
+
+    }
+}

+ 128 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/action/BagAction.java

@@ -0,0 +1,128 @@
+/*
+ * 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.game.action.skeleton.core.exception.ActionErrorEnum;
+import com.iohao.game.action.skeleton.core.flow.FlowContext;
+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.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.service.BagService;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * 背包
+ *
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Slf4j
+@Component
+@ActionController(BagCmd.cmd)
+public class BagAction {
+    @Resource
+    BagService bagService;
+
+    /**
+     * 查询玩家背包
+     *
+     * @return 背包
+     */
+    @ActionMethod(BagCmd.bag)
+    public BagMessage getBag(FlowContext flowContext) {
+        long userId = flowContext.getUserId();
+        Bag bag = bagService.ofBag(userId);
+
+        return BagMapper.ME.convert(bag);
+    }
+
+    /**
+     * 往背包添加(增加)物品
+     *
+     * @param bagItemMessage 物品
+     * @param flowContext    flowContext
+     * @return 当前物品的最新信息
+     */
+    @ActionMethod(BagCmd.incrementItem)
+    public BagItemMessage internalIncrementItem(BagItemMessage bagItemMessage, FlowContext flowContext) {
+        long userId = flowContext.getUserId();
+
+        BagItem bagItem = BagMapper.ME.convert(bagItemMessage);
+
+        bagItem = bagService.incrementItem(bagItem, userId);
+        BagMapper.ME.to(bagItem, bagItemMessage);
+
+        return bagItemMessage;
+    }
+
+    /**
+     * 从背包减少物品
+     *
+     * @param bagItemMessage 物品
+     * @param flowContext    flowContext
+     * @return 当前物品的最新信息
+     */
+    @ActionMethod(BagCmd.decrementItem)
+    public BagItemMessage internalDecrementItem(BagItemMessage bagItemMessage, FlowContext flowContext) {
+        long userId = flowContext.getUserId();
+
+        BagItem bagItem = BagMapper.ME.convert(bagItemMessage);
+
+        bagItem = bagService.decrementItem(bagItem, userId);
+        BagMapper.ME.to(bagItem, bagItemMessage);
+
+        return bagItemMessage;
+    }
+
+    /**
+     * 使用背包物品
+     *
+     * @param useMessage  使用物品
+     * @param flowContext flowContext
+     */
+    @ActionMethod(BagCmd.use)
+    public boolean use(UseMessage useMessage, FlowContext flowContext) {
+        long userId = flowContext.getUserId();
+        ActionErrorEnum.validateErrCode.assertTrue(useMessage.verify());
+
+        /*
+         * 各物品的处理逻辑不相同
+         * 如气血药,增加气血值;魔法药,增加魔法值;
+         * 攻击符、增加临时攻击力;
+         */
+
+        UsePOJO usePOJO = ItemMapper.ME.convert(useMessage);
+        log.info("usePOJO : {}", usePOJO);
+
+        // 减少背包物品
+        // 物品功效
+
+        return true;
+    }
+}

+ 63 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/config/ItemCommandLineRunner.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.config;
+
+import com.iohao.mmo.bag.ItemIdConst;
+import com.iohao.mmo.bag.entity.ItemConfig;
+import jakarta.annotation.Resource;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@Component
+public class ItemCommandLineRunner implements CommandLineRunner {
+    @Resource
+    MongoTemplate mongoTemplate;
+
+    @Override
+    public void run(String... args) {
+        List<ItemConfig> itemConfigs = initConfigExcel();
+        itemConfigs.forEach(ItemConfigRegion::addItemConfig);
+    }
+
+    private List<ItemConfig> initConfigExcel() {
+
+        List<ItemConfig> configList = new ArrayList<>();
+        ItemConfig config = new ItemConfig();
+        configList.add(config);
+
+        config.setItemId(ItemIdConst.expId);
+        config.setName("经验值道具");
+        config.setDescription("增加经验值");
+
+        config.setItemId(ItemIdConst.hpId);
+        config.setName("气血药");
+        config.setDescription("增加气血值");
+
+
+        return configList;
+    }
+}

+ 50 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/config/ItemConfigRegion.java

@@ -0,0 +1,50 @@
+/*
+ * 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.config;
+
+import com.iohao.mmo.bag.entity.ItemConfig;
+import lombok.NonNull;
+import lombok.experimental.UtilityClass;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@UtilityClass
+public class ItemConfigRegion {
+
+    public Map<String, ItemConfig> map = new HashMap<>();
+
+    public void addItemConfig(@NonNull ItemConfig itemConfig) {
+        map.put(itemConfig.getItemId(), itemConfig);
+    }
+
+    public boolean contains(String itemId) {
+        return map.containsKey(itemId);
+    }
+
+    public ItemConfig getItemConfig(String itemId) {
+        return map.get(itemId);
+    }
+
+
+}

+ 42 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/entity/Bag.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.entity;
+
+import lombok.AccessLevel;
+import lombok.Data;
+import lombok.experimental.FieldDefaults;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.Map;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Data
+@Document
+@FieldDefaults(level = AccessLevel.PRIVATE)
+public class Bag {
+    /** userId */
+    @Id
+    long id;
+    /** 背包物品 */
+    Map<String, BagItem> itemMap;
+}

+ 72 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/entity/BagItem.java

@@ -0,0 +1,72 @@
+/*
+ * 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.entity;
+
+import lombok.AccessLevel;
+import lombok.Data;
+import lombok.experimental.FieldDefaults;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.Objects;
+
+/**
+ * 背包物品
+ * <pre>
+ *
+ * </pre>
+ *
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Data
+@Document
+@FieldDefaults(level = AccessLevel.PRIVATE)
+public class BagItem {
+    /**
+     * 背包物品 id
+     * <pre>
+     *     如果 id 与 itemId 一致
+     *     表示物品可叠加,比如一些药品可叠加存放
+     *
+     *     如果 id 与 itemId 不一致
+     *     表示物品不可叠加,每一件物品都需要分开存放;
+     *     比如,装备、品质不同的药品等。
+     * </pre>
+     */
+    @Id
+    String id;
+    /** 物品 id */
+    String itemId;
+    /** 物品数量 */
+    int quantity;
+
+    public void addQuantity(int quantity) {
+        this.quantity += quantity;
+    }
+
+    /**
+     * 是否一个仓库
+     *
+     * @return true 表示类似仓库,物品可以叠加存放
+     */
+    public boolean isStash() {
+        return Objects.equals(id, itemId);
+    }
+}

+ 43 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/entity/ItemConfig.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.entity;
+
+import lombok.AccessLevel;
+import lombok.Data;
+import lombok.experimental.Accessors;
+import lombok.experimental.FieldDefaults;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@Data
+@Document
+@Accessors(chain = true)
+@FieldDefaults(level = AccessLevel.PRIVATE)
+public class ItemConfig {
+    @Id
+    String itemId;
+    /** 物品名 */
+    String name;
+    /** 物品描述 */
+    String description;
+}

+ 44 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/BagMapper.java

@@ -0,0 +1,44 @@
+/*
+ * 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.mmo.bag.entity.Bag;
+import com.iohao.mmo.bag.entity.BagItem;
+import com.iohao.mmo.bag.proto.BagItemMessage;
+import com.iohao.mmo.bag.proto.BagMessage;
+import org.mapstruct.Mapper;
+import org.mapstruct.MappingTarget;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Mapper
+public interface BagMapper {
+    BagMapper ME = Mappers.getMapper(BagMapper.class);
+
+    BagMessage convert(Bag bag);
+
+    BagItemMessage convert(BagItem bagItem);
+
+    BagItem convert(BagItemMessage bagItemMessage);
+
+    void to(BagItem bagItem, @MappingTarget BagItemMessage bagItemMessage);
+}

+ 61 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/mapper/ItemMapper.java

@@ -0,0 +1,61 @@
+/*
+ * 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.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.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@Mapper
+public interface ItemMapper {
+    ItemMapper ME = Mappers.getMapper(ItemMapper.class);
+
+    @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;
+    }
+}

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

@@ -0,0 +1,39 @@
+/*
+ * 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.pojo;
+
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@ToString
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class UseItemPOJO {
+    /** 背包物品 id */
+    String id;
+    /** 物品 id */
+    String itemId;
+    /** 使用数量 */
+    int quantity;
+
+}

+ 52 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/pojo/UsePOJO.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.pojo;
+
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+import java.util.Map;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@ToString
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class UsePOJO {
+    /** 业务操作 */
+    int operation;
+    /**
+     * 使用项
+     * <pre>
+     *     key 为 itemId;
+     *     比如我们在强化某个装备时,通常是需要两个物品
+     *     1 强化符
+     *     2 需要强化的装备
+     *
+     *     而这个 key,则为我们提供了查找对应类型的可能,
+     *     或者通过检测 key 是否存在,来做强化逻辑前的一些校验。
+     *
+     *     这里只举了一下例子,后期我们会扩展很多物品,而每种物品的使用效果是不同的,
+     *     而要实现效果的不同,就需要到不同的逻辑代码中做对应的处理。
+     * </pre>
+     */
+    Map<String, UseItemPOJO> useItemMap;
+}

+ 31 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/repository/BagRepository.java

@@ -0,0 +1,31 @@
+/*
+ * 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.repository;
+
+import com.iohao.mmo.bag.entity.Bag;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Repository
+public interface BagRepository extends CrudRepository<Bag, Long> {
+}

+ 110 - 0
logic/bag-logic/src/main/java/com/iohao/mmo/bag/service/BagService.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.service;
+
+import com.iohao.game.action.skeleton.core.exception.ActionErrorEnum;
+import com.iohao.mmo.bag.entity.Bag;
+import com.iohao.mmo.bag.entity.BagItem;
+import com.iohao.mmo.bag.repository.BagRepository;
+import com.iohao.mmo.common.config.GameCode;
+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;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Service
+@AllArgsConstructor
+public class BagService {
+    final MongoTemplate mongoTemplate;
+    final BagRepository bagRepository;
+
+    public Bag ofBag(long userId) {
+
+        Optional<Bag> bagOptional = bagRepository.findById(userId);
+        if (bagOptional.isPresent()) {
+            return bagOptional.get();
+        }
+
+        Bag bag = new Bag();
+        bag.setId(userId);
+        bag.setItemMap(new HashMap<>());
+
+        bagRepository.save(bag);
+
+        return bag;
+    }
+
+    public BagItem incrementItem(BagItem incrementItem, long userId) {
+        Bag bag = ofBag(userId);
+        Map<String, BagItem> itemMap = bag.getItemMap();
+
+        String bagItemId = incrementItem.getId();
+        BagItem bagItem = itemMap.get(bagItemId);
+
+        int quantity = incrementItem.getQuantity();
+        if (Objects.isNull(bagItem)) {
+            bagItem = incrementItem;
+            itemMap.put(bagItemId, bagItem);
+            bagItem.setQuantity(0);
+        }
+
+        // 通过 itemType 来判断,背包物品是否可叠加
+        if (bagItem.isStash()) {
+            bagItem.addQuantity(quantity);
+        } else {
+            bagItem.setQuantity(1);
+        }
+
+        bagRepository.save(bag);
+
+        return bagItem;
+    }
+
+    public BagItem decrementItem(BagItem decrementItem, long userId) {
+        Bag bag = ofBag(userId);
+        Map<String, BagItem> itemMap = bag.getItemMap();
+
+        // 查询背包物品
+        String bagItemId = decrementItem.getId();
+        BagItem bagItem = itemMap.get(bagItemId);
+        ActionErrorEnum.dataNotExist.assertNonNull(bagItem);
+
+        // 数量检测
+        int quantity = decrementItem.getQuantity();
+        GameCode.quantityNotEnough.assertTrue(bagItem.getQuantity() >= quantity);
+
+        bagItem.addQuantity(-quantity);
+
+        if (bagItem.getQuantity() == 0) {
+            itemMap.remove(bagItemId);
+        }
+
+        bagRepository.save(bag);
+
+        return bagItem;
+    }
+}

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

@@ -0,0 +1,38 @@
+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

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

@@ -0,0 +1,34 @@
+<?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>

+ 0 - 7
logic/level-logic/src/main/java/com/iohao/mmo/level/LevelLogicServer.java

@@ -24,18 +24,11 @@ import com.iohao.game.bolt.broker.client.AbstractBrokerClientStartup;
 import com.iohao.game.bolt.broker.core.client.BrokerClientBuilder;
 import com.iohao.mmo.common.logic.server.LogicServerKit;
 import com.iohao.mmo.level.action.LevelAction;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.experimental.FieldDefaults;
 
 /**
  * @author 渔民小镇
  * @date 2023-07-30
  */
-@Getter
-@Setter
-@FieldDefaults(level = AccessLevel.PRIVATE)
 public class LevelLogicServer extends AbstractBrokerClientStartup {
     @Override
     public BarSkeleton createBarSkeleton() {

+ 2 - 2
logic/level-logic/src/main/java/com/iohao/mmo/level/action/LevelAction.java

@@ -68,7 +68,7 @@ public class LevelAction {
         // 推送经验值给玩家
         LevelMessage levelMessage = LevelMapper.ME.convert(level);
         BroadcastContext broadcastContext = BrokerClientHelper.getBroadcastContext();
-        CmdInfo cmdInfo = LevelCmd.getCmdInfo(LevelCmd.personAddExp);
+        CmdInfo cmdInfo = LevelCmd.of(LevelCmd.personAddExp);
         broadcastContext.broadcast(cmdInfo, levelMessage, userId);
     }
 
@@ -117,7 +117,7 @@ public class LevelAction {
         // 检测经验是否足够
         int configExp = personLevelConfig.getExp();
         long exp = level.getExp();
-        GameCode.UP_LEVEL_ERROR.assertTrue(exp >= configExp);
+        GameCode.upLevelError.assertTrue(exp >= configExp);
 
         //  达到升级条件
         level.addExp(-configExp);

+ 2 - 2
logic/map-logic/src/main/java/com/iohao/mmo/map/action/MapAction.java

@@ -75,10 +75,10 @@ public class MapAction {
     @ActionMethod(MapCmd.enterMap)
     public EnterMapMessage enterMap(EnterMapReq enterMapReq, MyFlowContext flowContext) {
         long mapId = enterMapReq.mapId;
-        GameCode.MAP_NOT_EXIST.assertTrueThrows(mapId != 1);
+        GameCode.mapNotExist.assertTrueThrows(mapId != 1);
 
         MapRoom room = roomService.getRoom(mapId);
-        GameCode.MAP_NOT_EXIST.assertNonNull(room);
+        GameCode.mapNotExist.assertNonNull(room);
 
         long userId = flowContext.getUserId();
         MapPlayer player = room.getPlayerById(userId);

+ 1 - 1
logic/person-logic/src/main/java/com/iohao/mmo/person/action/PersonAction.java

@@ -77,7 +77,7 @@ public class PersonAction {
         // 等级
         CompletableFuture<LevelMessage> future = CompletableFuture.supplyAsync(() -> {
             // 路由:这个路由是将要访问逻辑服的路由(表示你将要去的地方)
-            CmdInfo ofLevelCmd = LevelCmd.getCmdInfo(LevelCmd.ofLevel);
+            CmdInfo ofLevelCmd = LevelCmd.of(LevelCmd.ofLevel);
             // 游戏逻辑服通讯上下文
             InvokeModuleContext invokeModuleContext = BrokerClientHelper.getInvokeModuleContext();
             // 根据路由信息来请求其他子服务器(其他逻辑服)的数据

+ 4 - 0
one-application/src/main/java/com/iohao/mmo/OneApplication.java

@@ -24,6 +24,7 @@ import com.iohao.game.bolt.broker.server.BrokerServer;
 import com.iohao.game.external.core.ExternalServer;
 import com.iohao.game.external.core.config.ExternalGlobalConfig;
 import com.iohao.game.external.core.netty.simple.NettyRunOne;
+import com.iohao.mmo.bag.BagLogicServer;
 import com.iohao.mmo.broker.MyBrokerServer;
 import com.iohao.mmo.equip.EquipLogicServer;
 import com.iohao.mmo.external.MyExternalServer;
@@ -76,6 +77,7 @@ public class OneApplication {
         PersonLogicServer personLogicServer = new PersonLogicServer();
         MapLogicServer mapLogicServer = new MapLogicServer();
         LevelLogicServer levelLogicServer = new LevelLogicServer();
+        BagLogicServer bagLogicServer = new BagLogicServer();
         EquipLogicServer equipLogicServer = new EquipLogicServer();
 
         // 游戏逻辑服列表
@@ -88,6 +90,8 @@ public class OneApplication {
                 , mapLogicServer
                 // 等级
                 , levelLogicServer
+                // 背包
+                , bagLogicServer
                 // 装备
                 , equipLogicServer
         );

+ 3 - 2
one-application/src/main/resources/logback-spring.xml

@@ -99,10 +99,11 @@
     </appender>
 
     <!-- 为某个包下的所有类的指定Appender 这里也可以指定类名称例如:com.aa.bb.ClassName -->
-    <logger name="com.iohao" additivity="false">
+    <logger name="com.iohao.mmo" additivity="false">
         <level value="${log.root.level}"/>
         <appender-ref ref="stdout"/>
-        <appender-ref ref="file.async"/><!-- 即com.iohao.game包下级别为 ${log.root.level}的才会使用file.async来打印 -->
+        <!-- 即com.iohao.mmo 包下级别为 ${log.root.level}的才会使用file.async来打印 -->
+        <appender-ref ref="file.async"/>
         <appender-ref ref="file.error"/>
     </logger>
 

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

@@ -22,6 +22,7 @@ import com.iohao.game.external.client.InputCommandRegion;
 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.equip.client.EquipInputCommandRegion;
 import com.iohao.mmo.level.client.LevelInputCommandRegion;
 import com.iohao.mmo.login.client.LoginInputCommandRegion;
@@ -54,6 +55,7 @@ public class CommonClient {
         MapInputCommandRegion mapInputCommandRegion = new MapInputCommandRegion();
         PersonInputCommandRegion personInputCommandRegion = new PersonInputCommandRegion();
         LevelInputCommandRegion levelInputCommandRegion = new LevelInputCommandRegion();
+        BagInputCommandRegion bagInputCommandRegion = new BagInputCommandRegion();
         EquipInputCommandRegion equipInputCommandRegion = new EquipInputCommandRegion();
 
         // 模拟请求数据
@@ -63,8 +65,11 @@ public class CommonClient {
                 // 地图
                 , mapInputCommandRegion
                 // 人物、英雄
-                , personInputCommandRegion
+//                , personInputCommandRegion
                 // 等级相关
+//                , levelInputCommandRegion
+                // 背包
+                , bagInputCommandRegion
                 , levelInputCommandRegion
                 // 装备相关
                 , equipInputCommandRegion

+ 5 - 1
pom.xml

@@ -39,6 +39,10 @@
         <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>
         <module>provide/equip-provide</module>
 
@@ -54,7 +58,7 @@
         <encoding>UTF-8</encoding>
 
         <!-- 项目版本 -->
-        <ioGame.version>17.1.50</ioGame.version>
+        <ioGame.version>17.1.51</ioGame.version>
         <spring-boot.version>3.1.2</spring-boot.version>
         <!-- lombok 消除冗长的 Java 代码 https://mvnrepository.com/artifact/org.projectlombok/lombok -->
         <lombok.version>1.18.24</lombok.version>

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

@@ -49,6 +49,18 @@
             <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>
+            <version>${project.parent.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>com.iohao.mmo</groupId>
             <artifactId>equip-provide</artifactId>

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

@@ -0,0 +1,38 @@
+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

+ 33 - 0
provide/bag-provide/pom.xml

@@ -0,0 +1,33 @@
+<?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>bag-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>
+
+        <dependency>
+            <groupId>com.iohao.mmo</groupId>
+            <artifactId>item-provide</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+    </dependencies>
+</project>

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

@@ -0,0 +1,28 @@
+/*
+ * 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-06
+ */
+public interface ItemIdConst {
+    String expId = "exp";
+    String hpId = "hp";
+}

+ 57 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagExchange.java

@@ -0,0 +1,57 @@
+/*
+ * 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.core.CmdInfo;
+import com.iohao.game.action.skeleton.core.flow.FlowContext;
+import com.iohao.game.action.skeleton.protocol.ResponseMessage;
+import com.iohao.mmo.bag.cmd.BagCmd;
+import com.iohao.mmo.bag.proto.BagItemMessage;
+import com.iohao.mmo.common.kit.MessageKit;
+import com.iohao.mmo.common.provide.client.ExchangeKit;
+import lombok.experimental.UtilityClass;
+
+/**
+ * 背包模块,对外提供的访问 api
+ *
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@UtilityClass
+public class BagExchange {
+    ResponseMessage incrementItemResponse(BagItemMessage bagItemMessage, FlowContext flowContext) {
+        CmdInfo cmdInfo = BagCmd.of(BagCmd.incrementItem);
+        return ExchangeKit.invokeModuleMessage(flowContext, cmdInfo, bagItemMessage);
+    }
+
+    public BagItemMessage incrementItem(BagItemMessage bagItemMessage, FlowContext flowContext) {
+        ResponseMessage responseMessage = incrementItemResponse(bagItemMessage, flowContext);
+        return MessageKit.getData(responseMessage, BagItemMessage.class);
+    }
+
+    ResponseMessage decrementItemResponse(BagItemMessage bagItemMessage, FlowContext flowContext) {
+        CmdInfo cmdInfo = BagCmd.of(BagCmd.decrementItem);
+        return ExchangeKit.invokeModuleMessage(flowContext, cmdInfo, bagItemMessage);
+    }
+
+    public BagItemMessage decrementItem(BagItemMessage bagItemMessage, FlowContext flowContext) {
+        ResponseMessage responseMessage = decrementItemResponse(bagItemMessage, flowContext);
+        return MessageKit.getData(responseMessage, BagItemMessage.class);
+    }
+}

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

@@ -0,0 +1,143 @@
+/*
+ * 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.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.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.common.provide.kit.JsonKit;
+import com.iohao.mmo.common.snow.SnowKit;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@Slf4j
+public class BagInputCommandRegion extends AbstractInputCommandRegion {
+    @Override
+    public void initInputCommand() {
+        this.inputCommandCreate.cmd = BagCmd.cmd;
+        request();
+        useRequest();
+    }
+
+    @Override
+    public void loginSuccessCallback() {
+        // 添加一些经验值道具
+        var bagItemMessage = BagInternalHelper.ofBagItemMessage(ItemIdConst.expId);
+        bagItemMessage.quantity = 10;
+        log.info("添加 {} 个经验值道具 {}", bagItemMessage.quantity, bagItemMessage);
+        ofRequestCommand(BagCmd.incrementItem).request(bagItemMessage);
+    }
+
+    private void request() {
+        ofCommand(BagCmd.bag).callback(BagMessage.class, result -> {
+            BagMessage value = result.getValue();
+            log.info("{}", JsonKit.toJsonString(value));
+        }).setDescription("查询玩家背包");
+
+        InputRequestData inputRequestData = () -> {
+            ScannerKit.log(() -> log.info("输入【1】表示添加一个可叠加的物品。"));
+            String inputType = ScannerKit.nextLine("1");
+
+            String id = "1";
+            String itemId = "1";
+
+            if (!"1".equals(inputType)) {
+                id = SnowKit.nextToString();
+            }
+
+            BagItemMessage bagItemMessage = new BagItemMessage();
+            bagItemMessage.id = id;
+            bagItemMessage.itemId = itemId;
+            bagItemMessage.quantity = 1;
+
+            ScannerKit.log(() -> log.info("{}", bagItemMessage));
+
+            return bagItemMessage;
+        };
+
+        ofCommand(BagCmd.incrementItem).callback(BagItemMessage.class, result -> {
+            var value = result.getValue();
+            log.info("value : {}", value);
+            // 重新查询一次背包
+            ofRequestCommand(BagCmd.bag).request();
+        }).setDescription("往背包添加(增加)物品").setInputRequestData(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);
+
+            BagItemMessage bagItemMessage = new BagItemMessage();
+            bagItemMessage.id = id;
+            bagItemMessage.quantity = quantity;
+
+            ScannerKit.log(() -> log.info("{}", bagItemMessage));
+
+            return bagItemMessage;
+        };
+
+        ofCommand(BagCmd.decrementItem).callback(BagItemMessage.class, result -> {
+            var value = result.getValue();
+            log.info("value : {}", value);
+
+            // 重新查询一次背包
+            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);
+            return useMessage;
+        };
+
+        ofCommand(BagCmd.use).callback(BoolValue.class, result -> {
+            var value = result.getValue();
+            log.info("value : {}", value);
+        }).setDescription("使用背包物品").setInputRequestData(inputRequestData);
+    }
+}

+ 48 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/client/BagInternalHelper.java

@@ -0,0 +1,48 @@
+/*
+ * 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.mmo.bag.proto.BagItemMessage;
+import com.iohao.mmo.bag.proto.UseItemMessage;
+import lombok.experimental.UtilityClass;
+
+/**
+ * 模拟测试辅助类
+ *
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@UtilityClass
+class BagInternalHelper {
+    BagItemMessage ofBagItemMessage(String itemId) {
+        BagItemMessage bagItemMessage = new BagItemMessage();
+        bagItemMessage.id = itemId;
+        bagItemMessage.itemId = itemId;
+        bagItemMessage.quantity = 1;
+        return bagItemMessage;
+    }
+
+    UseItemMessage ofUseItemMessage(String itemId) {
+        UseItemMessage useItemMessage = new UseItemMessage();
+        useItemMessage.id = itemId;
+        useItemMessage.itemId = itemId;
+        useItemMessage.quantity = 1;
+        return useItemMessage;
+    }
+}

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

@@ -0,0 +1,45 @@
+/*
+ * 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.cmd;
+
+import com.iohao.game.action.skeleton.core.CmdInfo;
+import com.iohao.mmo.common.provide.cmd.CmdModule;
+
+/**
+ * 背包
+ *
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+public interface BagCmd {
+    int cmd = CmdModule.bagCmd;
+    /** 背包列表 */
+    int bag = 1;
+    /** 添加物品 */
+    int incrementItem = 2;
+    /** 减少物品 */
+    int decrementItem = 3;
+
+    /** 使用物品 */
+    int use = 5;
+
+    static CmdInfo of(int subCmd) {
+        return CmdInfo.of(cmd, subCmd);
+    }
+}

+ 42 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/BagItemMessage.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-04
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class BagItemMessage {
+    /** 背包物品 id */
+    String id;
+    /** 物品 id */
+    String itemId;
+    /** 物品数量 */
+    int quantity;
+}

+ 40 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/BagMessage.java

@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+/**
+ * 背包
+ *
+ * @author 渔民小镇
+ * @date 2023-08-04
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class BagMessage {
+    /** 背包物品 */
+    Map<String, BagItemMessage> itemMap;
+}

+ 64 - 0
provide/bag-provide/src/main/java/com/iohao/mmo/bag/proto/UseItemMessage.java

@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import java.util.Objects;
+
+/**
+ * 使用物品的具体信息
+ *
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class UseItemMessage {
+    /** 背包物品 id */
+    String id;
+    /** 物品 id */
+    String itemId;
+    /** 使用数量 */
+    int quantity;
+
+    /**
+     * 数据验证
+     * <pre>
+     *     id 与 itemId 相同,表示简单物品,是允许有数量的。
+     *
+     *     当 id 与 itemId 不相同时,则只能使用 1 表示。
+     * </pre>
+     *
+     * @return true 表示验证通过
+     */
+    public boolean verify() {
+        if (Objects.equals(id, itemId)) {
+            //
+            return quantity > 0;
+        }
+
+        quantity = 1;
+        return true;
+    }
+}

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

@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import java.util.List;
+
+/**
+ * 使用物品
+ *
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class UseMessage {
+    /** 业务操作 */
+    int operation;
+    /** 使用多个物品 */
+    List<UseItemMessage> useItems;
+
+    /**
+     * 数据验证
+     *
+     * @return true 表示验证通过
+     */
+    public boolean verify() {
+
+        for (UseItemMessage useItem : useItems) {
+            if (!useItem.verify()) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+}

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

@@ -38,5 +38,11 @@
             <artifactId>fastjson2</artifactId>
             <version>2.0.38</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.iohao.mmo</groupId>
+            <artifactId>common-core</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
     </dependencies>
 </project>

+ 49 - 0
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/client/ExchangeKit.java

@@ -0,0 +1,49 @@
+/*
+ * 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.client;
+
+import com.iohao.game.action.skeleton.core.CmdInfo;
+import com.iohao.game.action.skeleton.core.commumication.BrokerClientContext;
+import com.iohao.game.action.skeleton.core.commumication.InvokeModuleContext;
+import com.iohao.game.action.skeleton.core.flow.FlowContext;
+import com.iohao.game.action.skeleton.core.flow.attr.FlowAttr;
+import com.iohao.game.action.skeleton.protocol.RequestMessage;
+import com.iohao.game.action.skeleton.protocol.ResponseMessage;
+import lombok.experimental.UtilityClass;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-06
+ */
+@UtilityClass
+public class ExchangeKit {
+    public ResponseMessage invokeModuleMessage(FlowContext flowContext, CmdInfo cmdInfo) {
+        return invokeModuleMessage(flowContext, cmdInfo, null);
+    }
+
+    public ResponseMessage invokeModuleMessage(FlowContext flowContext, CmdInfo cmdInfo, Object data) {
+        RequestMessage requestMessage = flowContext
+                .getRequest()
+                .createRequestMessage(cmdInfo, data);
+
+        BrokerClientContext brokerClientContext = flowContext.option(FlowAttr.brokerClientContext);
+        InvokeModuleContext invokeModuleContext = brokerClientContext.getInvokeModuleContext();
+        return invokeModuleContext.invokeModuleMessage(requestMessage);
+    }
+}

+ 5 - 1
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/cmd/CmdModule.java

@@ -35,6 +35,10 @@ public interface CmdModule {
     int heroCmd = 4;
     /** 等级 */
     int levelCmd = 5;
+    /** 物品 */
+    int itemCmd = 6;
+    /** 背包 */
+    int bagCmd = 7;
     /** 装备 */
-    int equipCmd = 6;
+    int equipCmd = 8;
 }

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

@@ -0,0 +1,38 @@
+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

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

@@ -0,0 +1,27 @@
+<?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>

+ 36 - 0
provide/item-provide/src/main/java/com/iohao/mmo/item/cmd/ItemCmd.java

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

+ 2 - 2
provide/level-provide/src/main/java/com/iohao/mmo/level/cmd/LevelCmd.java

@@ -36,7 +36,7 @@ public interface LevelCmd {
     /** 得到等级信息,没有则创建 */
     int ofLevel = 4;
 
-    static CmdInfo getCmdInfo(int subCmd) {
-        return CmdInfo.getCmdInfo(cmd, subCmd);
+    static CmdInfo of(int subCmd) {
+        return CmdInfo.of(cmd, subCmd);
     }
 }