Browse Source

:whale: 添加等级模块:增加经验值、查询等级信息

渔民小镇 1 year ago
parent
commit
42e94a271d
24 changed files with 741 additions and 15 deletions
  1. 5 0
      logic/all-logic/pom.xml
  2. 38 0
      logic/level-logic/.gitignore
  3. 34 0
      logic/level-logic/pom.xml
  4. 61 0
      logic/level-logic/src/main/java/com/iohao/mmo/level/LevelLogicServer.java
  5. 94 0
      logic/level-logic/src/main/java/com/iohao/mmo/level/action/LevelAction.java
  6. 56 0
      logic/level-logic/src/main/java/com/iohao/mmo/level/entity/Level.java
  7. 35 0
      logic/level-logic/src/main/java/com/iohao/mmo/level/mapper/LevelMapper.java
  8. 38 0
      logic/level-logic/src/main/java/com/iohao/mmo/level/repository/LevelRepository.java
  9. 62 0
      logic/level-logic/src/main/java/com/iohao/mmo/level/service/LevelService.java
  10. 0 2
      logic/map-logic/pom.xml
  11. 3 7
      logic/person-logic/src/main/java/com/iohao/mmo/hero/service/HeroService.java
  12. 2 6
      logic/person-logic/src/main/java/com/iohao/mmo/person/service/PersonService.java
  13. 4 0
      one-application/src/main/java/com/iohao/mmo/OneApplication.java
  14. 4 0
      one-client/src/main/java/com/iohao/mmo/client/CommonClient.java
  15. 2 0
      pom.xml
  16. 6 0
      provide/all-provide/pom.xml
  17. 6 0
      provide/common-provide/src/main/java/com/iohao/mmo/common/provide/cmd/CmdModule.java
  18. 38 0
      provide/level-provide/.gitignore
  19. 27 0
      provide/level-provide/pom.xml
  20. 60 0
      provide/level-provide/src/main/java/com/iohao/mmo/level/client/LevelInputCommandRegion.java
  21. 35 0
      provide/level-provide/src/main/java/com/iohao/mmo/level/cmd/LevelCmd.java
  22. 40 0
      provide/level-provide/src/main/java/com/iohao/mmo/level/proto/ExpMessage.java
  23. 46 0
      provide/level-provide/src/main/java/com/iohao/mmo/level/proto/ExpTargetEnum.java
  24. 45 0
      provide/level-provide/src/main/java/com/iohao/mmo/level/proto/LevelMessage.java

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

@@ -38,6 +38,11 @@
             <version>${project.parent.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.iohao.mmo</groupId>
+            <artifactId>level-logic</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
 
     </dependencies>
 

+ 38 - 0
logic/level-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/level-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>level-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>level-provide</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+    </dependencies>
+</project>

+ 61 - 0
logic/level-logic/src/main/java/com/iohao/mmo/level/LevelLogicServer.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.level;
+
+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.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() {
+        // 业务框架构建器
+        BarSkeletonBuilder builder = LogicServerKit
+                .createBuilder(LevelAction.class);
+
+        extractedSendDco(builder);
+
+        return builder.build();
+    }
+
+    @Override
+    public BrokerClientBuilder createBrokerClientBuilder() {
+        BrokerClientBuilder builder = LogicServerKit.newBrokerClientBuilder();
+        builder.appName("等级逻辑服");
+        return builder;
+    }
+
+    private static void extractedSendDco(BarSkeletonBuilder builder) {
+
+    }
+}

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

@@ -0,0 +1,94 @@
+/*
+ * 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.level.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.level.cmd.LevelCmd;
+import com.iohao.mmo.level.entity.Level;
+import com.iohao.mmo.level.mapper.LevelMapper;
+import com.iohao.mmo.level.proto.ExpMessage;
+import com.iohao.mmo.level.proto.LevelMessage;
+import com.iohao.mmo.level.service.LevelService;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.Optional;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@Slf4j
+@Component
+@ActionController(LevelCmd.cmd)
+public class LevelAction {
+    @Resource
+    LevelService levelService;
+
+    /**
+     * 经验值添加
+     *
+     * @param expMessage 经验值
+     */
+    @ActionMethod(LevelCmd.addExp)
+    public LevelMessage internalAddExp(ExpMessage expMessage) {
+        // internal 打头的方法名表示内部方法,只能由内部调用
+        long id = expMessage.id;
+        int exp = expMessage.exp;
+
+        Level level = levelService.ofLevel(id);
+        level.addExp(exp);
+        levelService.save(level);
+
+        return LevelMapper.ME.convert(level);
+    }
+
+    /**
+     * 查询等级信息
+     *
+     * @param id id
+     * @return 等级信息
+     */
+    @ActionMethod(LevelCmd.getLevel)
+    public LevelMessage getLevel(long id) {
+        Optional<Level> levelOptional = levelService.getById(id);
+
+        ActionErrorEnum.dataNotExist.assertTrueThrows(levelOptional.isEmpty());
+
+        return levelOptional
+                .map(LevelMapper.ME::convert)
+                .orElseThrow();
+    }
+
+    /**
+     * 玩家手动点升级,升级后会恢复各种状态
+     *
+     * @param flowContext flowContext
+     */
+    @ActionMethod(LevelCmd.upLevel)
+    public void upLevel(FlowContext flowContext) {
+        long userId = flowContext.getUserId();
+        // 检测经验是否足够
+
+    }
+}

+ 56 - 0
logic/level-logic/src/main/java/com/iohao/mmo/level/entity/Level.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.level.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;
+
+/**
+ * 等级
+ * <pre>
+ *     人物、宠物都可以用
+ * </pre>
+ *
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@Data
+@Document
+@FieldDefaults(level = AccessLevel.PRIVATE)
+public class Level {
+    /**
+     * 主键
+     * <pre>
+     *     userId or 宠物id
+     * </pre>
+     */
+    @Id
+    long id;
+    /** 经验值 */
+    long exp;
+    /** 当前等级 */
+    int level;
+
+    public void addExp(int exp) {
+        this.exp += exp;
+    }
+}

+ 35 - 0
logic/level-logic/src/main/java/com/iohao/mmo/level/mapper/LevelMapper.java

@@ -0,0 +1,35 @@
+/*
+ * 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.level.mapper;
+
+import com.iohao.mmo.level.entity.Level;
+import com.iohao.mmo.level.proto.LevelMessage;
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@Mapper
+public interface LevelMapper {
+    LevelMapper ME = Mappers.getMapper(LevelMapper.class);
+
+    LevelMessage convert(Level level);
+}

+ 38 - 0
logic/level-logic/src/main/java/com/iohao/mmo/level/repository/LevelRepository.java

@@ -0,0 +1,38 @@
+/*
+ * 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.level.repository;
+
+import com.iohao.mmo.level.entity.Level;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.Optional;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@Repository
+public interface LevelRepository extends CrudRepository<Level, Long> {
+    <S extends Level> S save(S entity);
+
+    Optional<Level> findById(long primaryKey);
+
+    boolean existsById(long primaryKey);
+}

+ 62 - 0
logic/level-logic/src/main/java/com/iohao/mmo/level/service/LevelService.java

@@ -0,0 +1,62 @@
+/*
+ * 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.level.service;
+
+import com.iohao.mmo.level.entity.Level;
+import com.iohao.mmo.level.repository.LevelRepository;
+import lombok.AllArgsConstructor;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@Service
+@AllArgsConstructor
+public class LevelService {
+    final MongoTemplate mongoTemplate;
+    final LevelRepository levelRepository;
+
+    public Level ofLevel(long id) {
+
+        Level level = mongoTemplate.findById(id, Level.class);
+
+        if (Objects.isNull(level)) {
+            level = new Level();
+            level.setId(id);
+            level.setExp(0);
+            level.setLevel(1);
+            mongoTemplate.save(level);
+        }
+
+        return level;
+    }
+
+    public Optional<Level> getById(long primaryKey) {
+        return levelRepository.findById(primaryKey);
+    }
+
+    public void save(Level level) {
+        mongoTemplate.save(level);
+    }
+}

+ 0 - 2
logic/map-logic/pom.xml

@@ -31,7 +31,5 @@
             <artifactId>map-provide</artifactId>
             <version>${project.parent.version}</version>
         </dependency>
-
-
     </dependencies>
 </project>

+ 3 - 7
logic/person-logic/src/main/java/com/iohao/mmo/hero/service/HeroService.java

@@ -20,6 +20,7 @@ package com.iohao.mmo.hero.service;
 
 import com.iohao.mmo.person.entity.BasicProperty;
 import com.iohao.mmo.person.entity.Hero;
+import lombok.AllArgsConstructor;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.stereotype.Service;
 
@@ -28,14 +29,9 @@ import org.springframework.stereotype.Service;
  * @date 2023-07-27
  */
 @Service
+@AllArgsConstructor
 public class HeroService {
-
-    MongoTemplate mongoTemplate;
-
-    public HeroService(MongoTemplate mongoTemplate) {
-        this.mongoTemplate = mongoTemplate;
-        initHeroData();
-    }
+    final MongoTemplate mongoTemplate;
 
     public Hero getFirstHero() {
         // 得到第一个英雄,即使后期我们有几十个英雄,也初始化这一个(类似新手英雄)

+ 2 - 6
logic/person-logic/src/main/java/com/iohao/mmo/person/service/PersonService.java

@@ -22,6 +22,7 @@ import com.iohao.mmo.hero.service.HeroService;
 import com.iohao.mmo.person.entity.BasicProperty;
 import com.iohao.mmo.person.entity.Hero;
 import com.iohao.mmo.person.entity.Person;
+import lombok.AllArgsConstructor;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
@@ -35,16 +36,11 @@ import java.util.Objects;
  * @date 2023-07-24
  */
 @Service
+@AllArgsConstructor
 public class PersonService {
     final MongoTemplate mongoTemplate;
-
     final HeroService heroService;
 
-    public PersonService(MongoTemplate mongoTemplate, HeroService heroService) {
-        this.mongoTemplate = mongoTemplate;
-        this.heroService = heroService;
-    }
-
     public void initPerson(long userId) {
         Query query = new Query(Criteria.where("userId").is(userId));
         Person person = mongoTemplate.findOne(query, Person.class);

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

@@ -26,6 +26,7 @@ import com.iohao.game.external.core.config.ExternalGlobalConfig;
 import com.iohao.game.external.core.netty.simple.NettyRunOne;
 import com.iohao.mmo.broker.MyBrokerServer;
 import com.iohao.mmo.external.MyExternalServer;
+import com.iohao.mmo.level.LevelLogicServer;
 import com.iohao.mmo.login.LoginLogicServer;
 import com.iohao.mmo.map.MapLogicServer;
 import com.iohao.mmo.person.PersonLogicServer;
@@ -73,6 +74,7 @@ public class OneApplication {
         LoginLogicServer loginLogicServer = new LoginLogicServer();
         PersonLogicServer personLogicServer = new PersonLogicServer();
         MapLogicServer mapLogicServer = new MapLogicServer();
+        LevelLogicServer levelLogicServer = new LevelLogicServer();
 
         // 游戏逻辑服列表
         return List.of(
@@ -82,6 +84,8 @@ public class OneApplication {
                 , personLogicServer
                 // 地图
                 , mapLogicServer
+                // 等级
+                , levelLogicServer
         );
     }
 

+ 4 - 0
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.level.client.LevelInputCommandRegion;
 import com.iohao.mmo.login.client.LoginInputCommandRegion;
 import com.iohao.mmo.map.client.MapInputCommandRegion;
 import com.iohao.mmo.person.client.PersonInputCommandRegion;
@@ -51,6 +52,7 @@ public class CommonClient {
         LoginInputCommandRegion loginInputCommandRegion = new LoginInputCommandRegion();
         MapInputCommandRegion mapInputCommandRegion = new MapInputCommandRegion();
         PersonInputCommandRegion personInputCommandRegion = new PersonInputCommandRegion();
+        LevelInputCommandRegion levelInputCommandRegion = new LevelInputCommandRegion();
 
         // 模拟请求数据
         return List.of(
@@ -60,6 +62,8 @@ public class CommonClient {
                 , mapInputCommandRegion
                 // 人物、英雄
                 , personInputCommandRegion
+                // 等级相关
+                , levelInputCommandRegion
         );
     }
 

+ 2 - 0
pom.xml

@@ -37,6 +37,8 @@
         <module>provide/person-provide</module>
         <module>logic/map-logic</module>
         <module>provide/map-provide</module>
+        <module>logic/level-logic</module>
+        <module>provide/level-provide</module>
 
     </modules>
 

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

@@ -42,6 +42,12 @@
             <artifactId>map-provide</artifactId>
             <version>${project.parent.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.iohao.mmo</groupId>
+            <artifactId>level-provide</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 6 - 0
provide/common-provide/src/main/java/com/iohao/mmo/common/provide/cmd/CmdModule.java

@@ -25,8 +25,14 @@ package com.iohao.mmo.common.provide.cmd;
  * @date 2023-07-21
  */
 public interface CmdModule {
+    /** 大厅 - 登录 */
     int loginCmd = 1;
+    /** 人物 */
     int personCmd = 2;
+    /** 地图 */
     int mapCmd = 3;
+    /** 英雄 */
     int heroCmd = 4;
+    /** 等级 */
+    int levelCmd = 5;
 }

+ 38 - 0
provide/level-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/level-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>level-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>

+ 60 - 0
provide/level-provide/src/main/java/com/iohao/mmo/level/client/LevelInputCommandRegion.java

@@ -0,0 +1,60 @@
+/*
+ * 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.level.client;
+
+import com.iohao.game.action.skeleton.protocol.wrapper.LongValue;
+import com.iohao.game.external.client.AbstractInputCommandRegion;
+import com.iohao.game.external.client.command.InputRequestData;
+import com.iohao.mmo.level.cmd.LevelCmd;
+import com.iohao.mmo.level.proto.ExpMessage;
+import com.iohao.mmo.level.proto.LevelMessage;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@Slf4j
+public class LevelInputCommandRegion extends AbstractInputCommandRegion {
+    @Override
+    public void initInputCommand() {
+        this.inputCommandCreate.cmd = LevelCmd.cmd;
+        InputRequestData inputRequestData;
+
+        ofCommand(LevelCmd.getLevel).callback(LevelMessage.class, result -> {
+            LevelMessage value = result.getValue();
+            log.info("value : {}", value);
+        }).setDescription("查询等级信息").setInputRequestData(() -> LongValue.of(clientUser.getUserId()));
+
+        // 动态请求参数
+        inputRequestData = () -> {
+            // 给自己添加 10 经验值
+            ExpMessage expMessage = new ExpMessage();
+            expMessage.id = clientUser.getUserId();
+            expMessage.exp = 10;
+            return expMessage;
+        };
+
+        ofCommand(LevelCmd.addExp).callback(LevelMessage.class, result -> {
+            LevelMessage value = result.getValue();
+            log.info("value : {}", value);
+        }).setDescription("添加经验值").setInputRequestData(inputRequestData);
+
+    }
+}

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

@@ -0,0 +1,35 @@
+/*
+ * 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.level.cmd;
+
+import com.iohao.mmo.common.provide.cmd.CmdModule;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+public interface LevelCmd {
+    int cmd = CmdModule.levelCmd;
+    /** 添加经验值 */
+    int addExp = 1;
+    /** 等级信息 */
+    int getLevel = 2;
+    /** 升级 */
+    int upLevel = 3;
+}

+ 40 - 0
provide/level-provide/src/main/java/com/iohao/mmo/level/proto/ExpMessage.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.level.proto;
+
+import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+/**
+ * 经验值
+ *
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class ExpMessage {
+    /** userId or 宠物id or other */
+    long id;
+    /** 经验值 */
+    int exp;
+}

+ 46 - 0
provide/level-provide/src/main/java/com/iohao/mmo/level/proto/ExpTargetEnum.java

@@ -0,0 +1,46 @@
+/*
+ * ioGame
+ * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
+ * # iohao.com . 渔民小镇
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.iohao.mmo.level.proto;
+
+import com.baidu.bjf.remoting.protobuf.EnumReadable;
+
+/**
+ * 目标类型:人物、宠物
+ *
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+public enum ExpTargetEnum implements EnumReadable {
+    /** 人物 */
+    PERSON(0, "人物"),
+    /** 宠物 */
+    PET(1, "宠物");
+    final int value;
+    final String name;
+
+    ExpTargetEnum(int value, String name) {
+        this.value = value;
+        this.name = name;
+    }
+
+    @Override
+    public int value() {
+        return value;
+    }
+}

+ 45 - 0
provide/level-provide/src/main/java/com/iohao/mmo/level/proto/LevelMessage.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.level.proto;
+
+import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
+import lombok.AccessLevel;
+import lombok.ToString;
+import lombok.experimental.FieldDefaults;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-30
+ */
+@ToString
+@ProtobufClass
+@FieldDefaults(level = AccessLevel.PUBLIC)
+public class LevelMessage {
+    /**
+     * 主键
+     * <pre>
+     *     userId or 宠物id
+     * </pre>
+     */
+    long id;
+    /** 经验值 */
+    long exp;
+    /** 当前等级 */
+    int level;
+}