|
@@ -0,0 +1,102 @@
|
|
|
+/*
|
|
|
+ * 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.external.client.AbstractInputCommandRegion;
|
|
|
+import com.iohao.game.external.client.command.InputRequestData;
|
|
|
+import com.iohao.game.external.client.kit.ScannerKit;
|
|
|
+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.common.snow.SnowKit;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 渔民小镇
|
|
|
+ * @date 2023-08-04
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class BagInputCommandRegion extends AbstractInputCommandRegion {
|
|
|
+ @Override
|
|
|
+ public void initInputCommand() {
|
|
|
+ this.inputCommandCreate.cmd = BagCmd.cmd;
|
|
|
+ request();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void request() {
|
|
|
+ ofCommand(BagCmd.bag).callback(BagMessage.class, result -> {
|
|
|
+ BagMessage value = result.getValue();
|
|
|
+ log.info("value : {}", 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");
|
|
|
+
|
|
|
+ String[] split = inputType.split("-");
|
|
|
+
|
|
|
+ String id = split[0];
|
|
|
+ int quantity = Integer.parseInt(split[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);
|
|
|
+ }
|
|
|
+}
|