浏览代码

:whale: 添加物品使用协议

渔民小镇 1 年之前
父节点
当前提交
90c674e64f

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

@@ -20,15 +20,20 @@ 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;
 
 /**
@@ -37,6 +42,7 @@ import org.springframework.stereotype.Component;
  * @author 渔民小镇
  * @date 2023-08-04
  */
+@Slf4j
 @Component
 @ActionController(BagCmd.cmd)
 public class BagAction {
@@ -93,4 +99,30 @@ public class BagAction {
 
         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);
+    }
+
+
+}

+ 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;
+}

+ 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;
+    }
+}

+ 14 - 10
logic/item-logic/src/main/java/com/iohao/mmo/item/action/ItemAction.java → logic/bag-logic/src/main/java/com/iohao/mmo/bag/pojo/UseItemPOJO.java

@@ -16,20 +16,24 @@
  * 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.action;
+package com.iohao.mmo.bag.pojo;
 
-import com.iohao.game.action.skeleton.annotation.ActionController;
-import com.iohao.game.action.skeleton.core.flow.FlowContext;
-import com.iohao.mmo.item.cmd.ItemCmd;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
 
 /**
  * @author 渔民小镇
- * @date 2023-08-04
+ * @date 2023-08-06
  */
-@ActionController(ItemCmd.cmd)
-public class ItemAction {
-    public void consumer(FlowContext flowContext) {
-        long userId = flowContext.getUserId();
+@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;
+}

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

@@ -28,5 +28,4 @@ import org.springframework.stereotype.Repository;
  */
 @Repository
 public interface BagRepository extends CrudRepository<Bag, Long> {
-
 }

+ 0 - 1
logic/bag-logic/src/main/java/com/iohao/mmo/bag/service/BagService.java

@@ -107,5 +107,4 @@ public class BagService {
 
         return bagItem;
     }
-
 }

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

@@ -23,5 +23,11 @@
             <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";
+}

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

@@ -18,16 +18,22 @@
  */
 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
@@ -38,6 +44,16 @@ public class BagInputCommandRegion extends AbstractInputCommandRegion {
     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() {
@@ -78,10 +94,9 @@ public class BagInputCommandRegion extends AbstractInputCommandRegion {
             ScannerKit.log(() -> log.info("输入需要减少的物品信息,格式 [背包物品id-数量]"));
             String inputType = ScannerKit.nextLine("1-1");
 
-            String[] split = inputType.split("-");
-
-            String id = split[0];
-            int quantity = Integer.parseInt(split[1]);
+            SplitParam param = new SplitParam(inputType);
+            String id = param.getString(0);
+            int quantity = param.getInt(1, 1);
 
             BagItemMessage bagItemMessage = new BagItemMessage();
             bagItemMessage.id = id;
@@ -99,5 +114,30 @@ 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);
+            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;
+    }
+}

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

@@ -36,6 +36,9 @@ public interface BagCmd {
     /** 减少物品 */
     int decrementItem = 3;
 
+    /** 使用物品 */
+    int use = 5;
+
     static CmdInfo of(int subCmd) {
         return CmdInfo.of(cmd, subCmd);
     }

+ 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;
+    }
+}

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

@@ -27,6 +27,8 @@ import com.iohao.mmo.common.provide.cmd.CmdModule;
  */
 public interface ItemCmd {
     int cmd = CmdModule.itemCmd;
+    /** 使用物品 */
+    int use = 1;
 
     static CmdInfo of(int subCmd) {
         return CmdInfo.of(cmd, subCmd);