Bläddra i källkod

装备随机生成初步完成

tangbin 1 år sedan
förälder
incheckning
1130e0e40a
21 ändrade filer med 802 tillägg och 14 borttagningar
  1. 57 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/EquipQualityEnum.java
  2. 3 3
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/action/EquipAction.java
  3. 70 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/action/EquipTemplateAction.java
  4. 10 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/BasicEquipProperty.java
  5. 9 1
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/Equip.java
  6. 47 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipTemplate.java
  7. 55 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/Goods.java
  8. 3 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/mapper/EquipMapper.java
  9. 41 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/mapper/EquipTemplateMapper.java
  10. 32 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/repository/EquipTemplateRepository.java
  11. 5 2
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipService.java
  12. 111 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipTemplateService.java
  13. 56 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/GoodsService.java
  14. 40 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/utils/EquipUtils.java
  15. 88 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/utils/RandomUtils.java
  16. 30 5
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/client/EquipInputCommandRegion.java
  17. 8 0
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/cmd/EquipCmd.java
  18. 10 2
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/EquipMessage.java
  19. 59 0
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/EquipTemplateMessage.java
  20. 67 0
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/GoodsMessage.java
  21. 1 1
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/OfEquipReq.java

+ 57 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/EquipQualityEnum.java

@@ -0,0 +1,57 @@
+package com.iohao.mmo.equip;
+
+/**
+ * @author 唐斌
+ * @date 2023-08-03
+ * @description: TODO
+ */
+public enum EquipQualityEnum {
+    WHITE(0.1, 1),
+    GREEN(0.3, 2),
+    BLUE(0.5, 3),
+    RED(0.7, 4),
+    PURPLE(0.95, 5),
+    GOLDEN(1.0, 6);
+    // 属性比例
+    private double prop;
+    //装备品质
+    private int quality;
+    // 构造方法
+    private EquipQualityEnum(double prop, int quality) {
+        this.prop = prop;
+        this.quality = quality;
+    }
+    // 通过品质数字拿属性比例
+    public static double getProp(int quality) {
+        for (EquipQualityEnum c : EquipQualityEnum.values()) {
+            if (c.getQuality() == quality) {
+                return c.prop;
+            }
+        }
+        return 0;
+    }
+
+    // 通过属性比例拿品质等级
+    public static int getQuality(double prop) {
+        for (EquipQualityEnum c : EquipQualityEnum.values()) {
+            if (c.getProp() >= prop) {
+                return c.quality;
+            }
+        }
+        return 1;
+    }
+    // get set 方法
+    public double getProp() {
+        return prop;
+    }
+    public void setProp(double prop) {
+        this.prop = prop;
+    }
+    public int getQuality() {
+        return quality;
+    }
+    public void setQuality(int quality) {
+        this.quality = quality;
+    }
+
+}

+ 3 - 3
logic/equip-logic/src/main/java/com/iohao/mmo/equip/action/EquipAction.java

@@ -3,7 +3,7 @@ package com.iohao.mmo.equip.action;
 import com.iohao.game.action.skeleton.annotation.ActionController;
 import com.iohao.game.action.skeleton.annotation.ActionMethod;
 import com.iohao.game.action.skeleton.core.flow.FlowContext;
-import com.iohao.game.action.skeleton.protocol.wrapper.LongValue;
+import com.iohao.game.action.skeleton.protocol.wrapper.StringValue;
 import com.iohao.mmo.equip.cmd.EquipCmd;
 import com.iohao.mmo.equip.entity.Equip;
 import com.iohao.mmo.equip.mapper.EquipMapper;
@@ -46,9 +46,9 @@ public class EquipAction {
      */
     @ActionMethod(EquipCmd.getEquip)
 //    public EquipMessage getEquip(FlowContext flowContext, OfEquipReq ofEquipReq) { //对象
-    public EquipMessage getEquip(FlowContext flowContext, LongValue longValue) { //参数值
+    public EquipMessage getEquip(FlowContext flowContext, StringValue stringValue) { //参数值
         // 初始化装备数据,暂时放这
-        Equip equip = equipService.ofEquip(longValue.value);
+        Equip equip = equipService.ofEquip(stringValue.value);
         return EquipMapper.ME.convert(equip);
     }
 }

+ 70 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/action/EquipTemplateAction.java

@@ -0,0 +1,70 @@
+package com.iohao.mmo.equip.action;
+
+import com.iohao.game.action.skeleton.annotation.ActionController;
+import com.iohao.game.action.skeleton.annotation.ActionMethod;
+import com.iohao.game.action.skeleton.core.flow.FlowContext;
+import com.iohao.game.action.skeleton.protocol.wrapper.StringValue;
+import com.iohao.mmo.equip.cmd.EquipCmd;
+import com.iohao.mmo.equip.entity.Equip;
+import com.iohao.mmo.equip.entity.EquipTemplate;
+import com.iohao.mmo.equip.mapper.EquipMapper;
+import com.iohao.mmo.equip.mapper.EquipTemplateMapper;
+import com.iohao.mmo.equip.proto.EquipMessage;
+import com.iohao.mmo.equip.proto.EquipTemplateMessage;
+import com.iohao.mmo.equip.service.EquipService;
+import com.iohao.mmo.equip.service.EquipTemplateService;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ * @description: 装备属性类
+ */
+@Slf4j
+@Component
+@ActionController(EquipCmd.cmd)
+public class EquipTemplateAction {
+
+    @Resource
+    EquipTemplateService equipTemplateService;
+
+    /**
+     * 初始化装备模板
+     *
+     * @param flowContext flowContext
+     */
+    @ActionMethod(EquipCmd.initEquipTemplate)
+    public void initEquipTemplate(FlowContext flowContext) {
+        long userId = flowContext.getUserId();
+        // 初始化装备数据,暂时放这
+        equipTemplateService.initEquipTemplate();
+    }
+
+    /**
+     * 获取装备模板信息
+     *
+     * @param flowContext flowContext
+     * @param stringValue 装备模板id
+     */
+    @ActionMethod(EquipCmd.getEquipTemplate)
+    public EquipTemplateMessage getEquipTemplate(FlowContext flowContext, StringValue stringValue) { //参数值
+        // 初始化装备数据,暂时放这
+        EquipTemplate equipTemplate = equipTemplateService.ofEquip(stringValue.value);
+        return EquipTemplateMapper.ME.convert(equipTemplate);
+    }
+
+    /**
+     * 根据装备模板随机出一件新的装备
+     *
+     * @param flowContext flowContext
+     * @param stringValve 装备模板id
+     */
+    @ActionMethod(EquipCmd.randomEquip)
+    public EquipMessage randomEquip(FlowContext flowContext, StringValue stringValve) { //参数值
+        // 初始化装备数据,暂时放这
+        Equip equip = equipTemplateService.randomEquip(stringValve.value);
+        return EquipMapper.ME.convert(equip);
+    }
+}

+ 10 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/BasicEquipProperty.java

@@ -52,4 +52,14 @@ public class BasicEquipProperty {
     /** 敏捷 */
     int agile;
 
+    public BasicEquipProperty() {
+    }
+
+    public BasicEquipProperty(int constitution, int magicPower, int power, int endurance, int agile) {
+        this.constitution = constitution;
+        this.magicPower = magicPower;
+        this.power = power;
+        this.endurance = endurance;
+        this.agile = agile;
+    }
 }

+ 9 - 1
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/Equip.java

@@ -33,9 +33,17 @@ import org.springframework.data.mongodb.core.mapping.Document;
 @FieldDefaults(level = AccessLevel.PRIVATE)
 public class Equip {
     @Id
-    long id;
+    String id;
     /** 装备名 */
     String name;
+    /** 总属性点 */
+    int attrTotal;
+    /** 未分配属性点 */
+    int undistributedAttr;
+    /** 品质 */
+    int quality;
+    /** 装备模板 */
+    EquipTemplate equipTemplate;
     /** 基础属性 */
     BasicEquipProperty basicEquipProperty;
 }

+ 47 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipTemplate.java

@@ -0,0 +1,47 @@
+/*
+ * 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.equip.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;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-26
+ */
+@Data
+@Document(collection = "equipTemplate")
+@FieldDefaults(level = AccessLevel.PRIVATE)
+public class EquipTemplate {
+    @Id
+    String id;
+    /** 所属物品 */
+    Goods goods;
+    /** 部位(0帽子,1衣服,2武器,3手镯,4裤子,5鞋子) */
+    int position;
+    /** 要求等级 */
+    int level;
+    /** 自定义属性随机范围最小值 */
+    int totalAttrMin;
+    /** 自定义属性随机范围最大值 */
+    int totalAttrMax;
+}

+ 55 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/Goods.java

@@ -0,0 +1,55 @@
+/*
+ * 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.equip.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;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-26
+ */
+@Data
+@Document
+@FieldDefaults(level = AccessLevel.PRIVATE)
+public class Goods {
+    @Id
+    String id;
+    /** 物品名称 */
+    String name;
+    /** 物品描述 */
+    String desc;
+    /** 图标 */
+    String icon;
+    /** 大图 */
+    String image;
+    /** 绑定货币价格 */
+    int bindPrice;
+    /** 非绑定货币价格 */
+    int price;
+    /** 是否可交易 */
+    boolean dealFlag;
+    /** 物品类型:0装备,1药品,2材料 */
+    int type;
+    /** 子表主键 */
+    String detailId;
+}

+ 3 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/mapper/EquipMapper.java

@@ -20,8 +20,10 @@ package com.iohao.mmo.equip.mapper;
 
 import com.iohao.mmo.equip.entity.BasicEquipProperty;
 import com.iohao.mmo.equip.entity.Equip;
+import com.iohao.mmo.equip.entity.EquipTemplate;
 import com.iohao.mmo.equip.proto.BasicEquipPropertyMessage;
 import com.iohao.mmo.equip.proto.EquipMessage;
+import com.iohao.mmo.equip.proto.EquipTemplateMessage;
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 import org.mapstruct.factory.Mappers;
@@ -37,5 +39,6 @@ public interface EquipMapper {
     @Mapping(source = "id", target = "id")
     EquipMessage convert(Equip equip);
 
+    EquipTemplateMessage convert(EquipTemplate equipTemplate);
     BasicEquipPropertyMessage convert(BasicEquipProperty basicEquipProperty);
 }

+ 41 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/mapper/EquipTemplateMapper.java

@@ -0,0 +1,41 @@
+/*
+ * 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.equip.mapper;
+
+import com.iohao.mmo.equip.entity.BasicEquipProperty;
+import com.iohao.mmo.equip.entity.Equip;
+import com.iohao.mmo.equip.entity.EquipTemplate;
+import com.iohao.mmo.equip.proto.BasicEquipPropertyMessage;
+import com.iohao.mmo.equip.proto.EquipMessage;
+import com.iohao.mmo.equip.proto.EquipTemplateMessage;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ */
+@Mapper
+public interface EquipTemplateMapper {
+    EquipTemplateMapper ME = Mappers.getMapper(EquipTemplateMapper.class);
+
+    @Mapping(source = "id", target = "id")
+    EquipTemplateMessage convert(EquipTemplate equipTemplate);
+}

+ 32 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/repository/EquipTemplateRepository.java

@@ -0,0 +1,32 @@
+/*
+ * 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.equip.repository;
+
+import com.iohao.mmo.equip.entity.EquipTemplate;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ */
+@Repository
+public interface EquipTemplateRepository extends CrudRepository<EquipTemplate, Long> {
+
+}

+ 5 - 2
logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipService.java

@@ -41,7 +41,7 @@ public class EquipService {
     final MongoTemplate mongoTemplate;
     final EquipRepository equipRepository;
 
-    public Equip ofEquip(long id) {
+    public Equip ofEquip(String id) {
 
         return  mongoTemplate.findById(id, Equip.class);
     }
@@ -58,8 +58,11 @@ public class EquipService {
         // 初始化一些英雄数配置,后期将移到 excel 中做。
 
         Equip equip = new Equip();
-        equip.setId(1000000L);
+//        equip.setId(1000000L);
         equip.setName("青铜甲");
+        equip.setAttrTotal(35);
+        equip.setUndistributedAttr(30);
+        equip.setQuality(2);
 
         BasicEquipProperty basicEquipProperty = getInitBasicEquipProperty();
         equip.setBasicEquipProperty(basicEquipProperty);

+ 111 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipTemplateService.java

@@ -0,0 +1,111 @@
+/*
+ * 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.equip.service;
+
+import com.iohao.mmo.equip.entity.BasicEquipProperty;
+import com.iohao.mmo.equip.entity.Equip;
+import com.iohao.mmo.equip.entity.EquipTemplate;
+import com.iohao.mmo.equip.entity.Goods;
+import com.iohao.mmo.equip.repository.EquipTemplateRepository;
+import com.iohao.mmo.equip.utils.EquipUtils;
+import com.iohao.mmo.equip.utils.RandomUtils;
+import jakarta.annotation.Resource;
+import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ * @description: 装备属性实现类
+ */
+@Service
+@AllArgsConstructor
+public class EquipTemplateService {
+
+    @Resource
+    private GoodsService goodsService;
+
+    final MongoTemplate mongoTemplate;
+    final EquipTemplateRepository equipTemplateRepository;
+
+    public EquipTemplate ofEquip(String id) {
+
+        return  mongoTemplate.findById(id, EquipTemplate.class);
+    }
+
+    public void saveEquipTemplate(EquipTemplate equipTemplate) {
+        mongoTemplate.save(equipTemplate);
+    }
+
+
+    public void initEquipTemplate() {
+        // 初始化一些英雄数配置,后期将移到 excel 中做。
+
+        EquipTemplate equipTemplate = new EquipTemplate();
+//        equipTemplate.setId(1000000L);
+        equipTemplate.setPosition(1);
+        equipTemplate.setLevel(1);
+        equipTemplate.setTotalAttrMin(10);
+        equipTemplate.setTotalAttrMax(40);
+
+        Goods goods = new Goods();
+        goods.setName("装备名称1");
+        goods.setDesc("装备描述1");
+        goods.setIcon("装备图标1");
+        goods.setImage("装备大图1");
+        goods.setBindPrice(120);
+        goods.setPrice(100);
+        goods.setDealFlag(true);
+        goodsService.save(goods);
+        equipTemplate.setGoods(goods);
+
+        mongoTemplate.insert(equipTemplate);
+    }
+
+    /**
+     * 根据装备模板随机一件新的装备
+     * @param equipTemplateId
+     * @return
+     */
+    public Equip randomEquip(String equipTemplateId){
+        EquipTemplate equipTemplate = mongoTemplate.findById(equipTemplateId, EquipTemplate.class);
+        Equip equip = new Equip();
+        //随机属性值
+        if(equipTemplate!=null){
+            //随机出的总属性值
+            equip.setAttrTotal(RandomUtils.randomFromInt(equipTemplate.getTotalAttrMin(),equipTemplate.getTotalAttrMax()));
+            equip.setQuality(EquipUtils.getEquipQuality(equipTemplate.getTotalAttrMin(),equipTemplate.getTotalAttrMax(),equip.getAttrTotal()));
+        }else {
+            equip.setAttrTotal(0);
+            equip.setQuality(1);
+        }
+        equip.setUndistributedAttr(equip.getAttrTotal());
+        equip.setEquipTemplate(equipTemplate);
+
+        BasicEquipProperty basicEquipProperty = new BasicEquipProperty(0,0,0,0,0);
+        equip.setBasicEquipProperty(basicEquipProperty);
+
+        mongoTemplate.save(equip);
+        return equip;
+    }
+}

+ 56 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/GoodsService.java

@@ -0,0 +1,56 @@
+/*
+ * 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.equip.service;
+
+import com.iohao.mmo.equip.entity.BasicEquipProperty;
+import com.iohao.mmo.equip.entity.EquipTemplate;
+import com.iohao.mmo.equip.entity.Goods;
+import lombok.AllArgsConstructor;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ * @description: 装备属性实现类
+ */
+@Service
+@AllArgsConstructor
+public class GoodsService {
+    final MongoTemplate mongoTemplate;
+
+    public Goods ofEquip(long id) {
+
+        return  mongoTemplate.findById(id, Goods.class);
+    }
+
+    public void save(Goods goods) {
+        mongoTemplate.save(goods);
+    }
+
+    private BasicEquipProperty getInitBasicEquipProperty() {
+        BasicEquipProperty basicEquipProperty = new BasicEquipProperty();
+        basicEquipProperty.setConstitution(1000);
+        basicEquipProperty.setMagicPower(120);
+        basicEquipProperty.setPower(110);
+        basicEquipProperty.setEndurance(200);
+        basicEquipProperty.setAgile(20);
+        return basicEquipProperty;
+    }
+}

+ 40 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/utils/EquipUtils.java

@@ -0,0 +1,40 @@
+package com.iohao.mmo.equip.utils;
+
+import com.iohao.mmo.equip.EquipQualityEnum;
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * @author kioor
+ * @ClassName RandomUtils
+ * @description: 装备相关工具
+ * @date 2023年07月26日
+ * @version: 1.0
+ */
+@Component
+public class EquipUtils {
+
+    /**
+     * 计算装备品质
+     *
+     * @param randomMin 随机范围下限
+     * @param randomMax 随机范围上限
+     * @param nowVal 当前随机值
+     * @return boolean
+     */
+    public static int getEquipQuality(int randomMin,int randomMax,int nowVal) {
+        if (randomMin >= randomMax){
+            return 1;
+        }
+        double prop = (nowVal-randomMin)*1.00/(randomMax-randomMin);
+        return EquipQualityEnum.getQuality(prop);
+    }
+
+    public static void main(String[] args) {
+        System.out.println(getEquipQuality(10,40,38));
+    }
+
+}

+ 88 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/utils/RandomUtils.java

@@ -0,0 +1,88 @@
+package com.iohao.mmo.equip.utils;
+
+import org.springframework.stereotype.Component;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * @author kioor
+ * @ClassName RandomUtils
+ * @description: 随机概率工具
+ *  常见四种概率算法:
+ *      1.常规做法,直接配置概率,程序直接判定
+ *      2.在1的基础上,加个保底次数,当连续不发生的次数高于保底时,强制发生
+ *      3.设置基础概率,事件不发生概率翻倍
+ *      4.设置数组,将事件发生概率变成数组元素
+ * @date 2023年07月26日
+ * @version: 1.0
+ */
+@Component
+public class RandomUtils {
+
+    private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
+
+    ////////////////////////// ↓↓↓算法实现↓↓↓ ///////////////////////////
+    /**
+     * 由概率随机是否触发(给定一个概率,返回是否命中)
+     *
+     * @param chance 概率 0.000000 - 1.000000
+     * @return boolean
+     */
+    public static boolean isLuck(BigDecimal chance) {
+        int chanceInt = chance.multiply(new BigDecimal("1000000")).intValue();
+        int randomNum = RANDOM.nextInt(1000000);
+        return randomNum <= chanceInt;
+    }
+
+    /**
+     * 由概率随机一个值(给定一个范围,范围随机值)
+     *
+     * @param rangeMin 限定范围的下限
+     * @param rangeMax 限定范围的上限
+     * @return boolean
+     */
+    public static BigDecimal randomFromArr(BigDecimal rangeMin,BigDecimal rangeMax) {
+        Random random = new Random();
+        BigDecimal randomValue =
+                rangeMin.add(
+                        rangeMax.subtract(rangeMin)
+                                .multiply(new BigDecimal(random.nextDouble()))
+                );
+        return randomValue;
+    }
+
+
+    /**
+     * 由概率随机一个值(给定一个范围,范围随机值)
+     *
+     * @param randomMin 限定范围的最小值(int)
+     * @param randomMax 限定范围的最大值(int)
+     * @return boolean
+     */
+    public static int randomFromInt(int randomMin,int randomMax) {
+        BigDecimal rangeMin = new BigDecimal(randomMin);
+        BigDecimal rangeMax = new BigDecimal(randomMax);
+        return RandomUtils.randomFromArr(rangeMin,rangeMax).intValue();
+
+    }
+
+
+
+//    ///////////////////////// ↓↓↓业务相关↓↓↓ ////////////////////
+//    /**
+//     * 怪物掉落物品计算(对象列表)-无排斥随机,每一次对每一个对象随机概率都是公平的
+//     * @param monster2GoodsDTOList 对象列表
+//     * @return 筛选后的对象列表
+//     */
+//    public List<Monster2GoodsDTO> obtainGoods(List<Monster2GoodsDTO> monster2GoodsDTOList){
+//        List<Monster2GoodsDTO> backMonster2GoodsDTOList = new ArrayList<>();
+//        for(Monster2GoodsDTO monster2GoodsDTO:monster2GoodsDTOList){
+//            if(isLuck(monster2GoodsDTO.getGoodsProb())){
+//                backMonster2GoodsDTOList.add(monster2GoodsDTO);
+//            }
+//        }
+//        return backMonster2GoodsDTOList;
+//    }
+
+}

+ 30 - 5
provide/equip-provide/src/main/java/com/iohao/mmo/equip/client/EquipInputCommandRegion.java

@@ -20,12 +20,13 @@ package com.iohao.mmo.equip.client;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONWriter;
-import com.iohao.game.action.skeleton.protocol.wrapper.LongValue;
+import com.iohao.game.action.skeleton.protocol.wrapper.StringValue;
 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.equip.cmd.EquipCmd;
 import com.iohao.mmo.equip.proto.EquipMessage;
+import com.iohao.mmo.equip.proto.EquipTemplateMessage;
 import com.iohao.mmo.equip.proto.OfEquipReq;
 import lombok.extern.slf4j.Slf4j;
 
@@ -51,6 +52,7 @@ public class EquipInputCommandRegion extends AbstractInputCommandRegion {
     private void request() {
         InputRequestData inputRequestData;
 
+        // 6-1
         ofCommand(EquipCmd.initEquip).callback(EquipMessage.class, result -> {
             EquipMessage value = result.getValue();
             String jsonFormat = JSON.toJSONString(value, JSONWriter.Feature.PrettyFormat);
@@ -72,16 +74,39 @@ public class EquipInputCommandRegion extends AbstractInputCommandRegion {
         // 动态请求参数(参数值)
         inputRequestData = () -> {
             ScannerKit.log(() -> log.info("请输入要查询的装备id"));
-            long id = ScannerKit.nextLong(1);
+            String id = ScannerKit.nextLine();
 
             // 请求参数
-            LongValue longValue = LongValue.of(id);
+            StringValue stringValue = StringValue.of(id);
 
-            return longValue;
+            return stringValue;
         };
+
+        // 6-2
         ofCommand(EquipCmd.getEquip).callback(EquipMessage.class, result -> {
             EquipMessage value = result.getValue();
             log.info("装备信息 : {}", value);
-        }).setDescription("查询装备信息").setInputRequestData(inputRequestData);;
+        }).setDescription("查询装备信息").setInputRequestData(inputRequestData);
+
+        // 6-10
+        ofCommand(EquipCmd.initEquipTemplate).callback(EquipTemplateMessage.class, result -> {
+            EquipTemplateMessage value = result.getValue();
+            log.info("装备模板信息 : {}", value);
+        }).setDescription("初始化装备模板");
+        // 动态请求参数(参数值)
+        inputRequestData = () -> {
+            ScannerKit.log(() -> log.info("请输入要查询的装备id"));
+            String id = ScannerKit.nextLine();
+
+            // 请求参数
+            StringValue stringValue = StringValue.of(id);
+
+            return stringValue;
+        };
+        // 6-13
+        ofCommand(EquipCmd.randomEquip).callback(EquipMessage.class, result -> {
+            EquipMessage value = result.getValue();
+            log.info("装备信息 : {}", value);
+        }).setDescription("根据装备模板随机出一件新的装备").setInputRequestData(inputRequestData);
     }
 }

+ 8 - 0
provide/equip-provide/src/main/java/com/iohao/mmo/equip/cmd/EquipCmd.java

@@ -32,6 +32,14 @@ public interface EquipCmd {
     int initEquip = 1;
     /** 得到信息 */
     int getEquip = 2;
+    /** 初始化装备模板 */
+    int initEquipTemplate = 10;
+    /** 新增装备模板 */
+    int saveEquipTemplate = 11;
+    /** 获取装备模板信息 */
+    int getEquipTemplate = 12;
+    /** 根据装备模板随机出一件新的装备 */
+    int randomEquip = 13;
 
     static CmdInfo getCmdInfo(int subCmd) {
         return CmdInfo.getCmdInfo(cmd, subCmd);

+ 10 - 2
provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/EquipMessage.java

@@ -31,11 +31,19 @@ import lombok.experimental.FieldDefaults;
 @ToString
 @ProtobufClass
 @FieldDefaults(level = AccessLevel.PUBLIC)
-public class EquipMessage {
+public class EquipMessage{
     /** 装备id */
-    long id;
+    String id;
     /** 装备名称 */
     String name;
+    /** 总属性点 */
+    int attrTotal;
+    /** 未分配属性点 */
+    int undistributedAttr;
+    /** 品质 */
+    int quality;
+    /** 装备模板 */
+    EquipTemplateMessage equipTemplate;
     /** 装备基础属性 */
     BasicEquipPropertyMessage basicEquipProperty;
 }

+ 59 - 0
provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/EquipTemplateMessage.java

@@ -0,0 +1,59 @@
+/*
+ * 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.equip.proto;
+
+import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ * @description:
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class EquipTemplateMessage{
+    /**
+     * id
+     */
+    String id;
+    /**
+     * 所属商品
+     */
+    GoodsMessage goods;
+    /**
+     * 部位(0帽子,1衣服,2武器,3手镯,4裤子,5鞋子)
+     */
+    int position;
+    /**
+     * 要求等级
+     */
+    int level;
+    /**
+     * 自定义属性随机范围最小值
+     */
+    int totalAttrMin;
+    /**
+     * 自定义属性随机范围最大值
+     */
+    int totalAttrMax;
+}

+ 67 - 0
provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/GoodsMessage.java

@@ -0,0 +1,67 @@
+/*
+ * 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.equip.proto;
+
+import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+/**
+ * @author 唐斌
+ * @date 2023-07-30
+ * @description:
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class GoodsMessage {
+    /**
+     * 物品id
+     */
+    String id;
+    /**
+     * 物品名称
+     */
+    String name;
+    /**
+     * 物品描述
+     */
+    String desc;
+    /**
+     * 图标
+     */
+    String icon;
+    /**
+     * 大图
+     */
+    String image;
+    /**
+     * 绑定货币价格
+     */
+    int bindPrice;
+    /**
+     * 非绑定货币价格
+     */
+    int price;
+    /**
+     * 是否可交易
+     */
+    boolean dealFlag;
+}

+ 1 - 1
provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/OfEquipReq.java

@@ -34,5 +34,5 @@ import lombok.experimental.FieldDefaults;
 @FieldDefaults(level = AccessLevel.PUBLIC)
 public class OfEquipReq {
     /** 装备 id */
-    long id;
+    String id;
 }