diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 63e9001..aa00ffa 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 760b2c6..c922853 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,26 @@
org.example
SecretGradeGame
1.0-SNAPSHOT
+ jar
+ secretGradeGame
+
+ secretGardenGame
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+
+
+
org.springframework.boot
@@ -22,6 +42,12 @@
org.springframework.boot
spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
@@ -44,6 +70,10 @@
2.2.0
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
mysql
mysql-connector-java
runtime
@@ -61,19 +91,9 @@
org.projectlombok
lombok
- RELEASE
+ 1.18.24
compile
-
- org.slf4j
- slf4j-api
- 1.7.12
-
-
- org.slf4j
- slf4j-log4j12
- 1.7.12
-
diff --git a/src/main/java/com/qiwuai/garden/common/Constants.java b/src/main/java/com/qiwuai/garden/common/Constants.java
index 923e6a6..670f8e8 100644
--- a/src/main/java/com/qiwuai/garden/common/Constants.java
+++ b/src/main/java/com/qiwuai/garden/common/Constants.java
@@ -3,31 +3,62 @@ package com.qiwuai.garden.common;
public class Constants {
/**
+ * 玩家离线-0
+ */
+ public static final int OFFLINE = 0;
+ /**
+ * 玩家在线-1
+ */
+ public static final int ONLINE = 1;
+
+
+ /**
+ * 玩家初始等级
+ */
+ public static final int INITIAL_LV = 1;
+
+
+ /**
+ * 背包
* 货币-1
*/
public static final int ITEM_TYPE_MONEY = 1;
/**
- * 果实-3
+ * 果实-2
*/
public static final int ITEM_TYPE_FRUIT = 2;
/**
- * 材料-4
+ * 材料-3
*/
public static final int ITEM_TYPE_MATERIAL = 3;
/**
- * 其他-5
+ * 其他-4
*/
public static final int ITEM_TYPE_OTHER = 4;
+
/**
* 货币
*/
- public static final int MONEY = 1;
+ public static final int TYPE_MONEY = 1;
/**
- * 其他
+ * 物品
*/
- public static final int OTHER = 5;
+ public static final int TYPE_ITEM = 2;
+ /**
+ * 宠物
+ */
+ public static final int TYPE_PET = 3;
+
+ /**
+ * 很少
+ */
+ public static final String FEW = "few";
+ /**
+ * 很多
+ */
+ public static final String LOT = "lot";
/**
@@ -89,6 +120,22 @@ public class Constants {
* 请求的名称随机
*/
public static final int REQ_RANDOM = -2;
+ /**
+ * 请求的数量为"都", "统统", "全数", "所有", "全", "全部", "全都", "一起"之类
+ */
+ public static final int REQ_ALL = -3;
+ /**
+ * 请求的名称为首个、首位之类
+ */
+ public static final int REQ_FIRST = -4;
+ /**
+ * 请求的名称为中间
+ */
+ public static final int REQ_MIDDLE = -5;
+ /**
+ * 请求的名称为最后
+ */
+ public static final int REQ_LAST = -6;
@@ -116,5 +163,114 @@ public class Constants {
* 帮助好友
*/
public static final int HELP_EVENT = 4;
+ /**
+ * 日常任务
+ */
+ public static final int DAILY_TASK_EVENT = 5;
+ /**
+ * 获得宠物
+ */
+ public static final int GET_PET_EVENT = 6;
+ /**
+ * 开启花圃
+ */
+ public static final int RECLAIM_NURSERY_EVENT = 7;
+ /**
+ * 偷菜
+ */
+ public static final int STEAL_EVENT = 8;
+
+ /**
+ * 帮助标记:0-未帮助
+ */
+ public static final int HELP_NO_SIGN = 0;
+ /**
+ * 帮助标记:1-已帮助
+ */
+ public static final int HELP_HAVE_SIGN = 1;
+
+
+ /**
+ * 话术-旁白
+ */
+ public static final String SPEECH_ASIDE = "aside";
+ /**
+ * 话术-男园丁
+ */
+ public static final String SPEECH_MAN = "man";
+ /**
+ * 话术-女园丁
+ */
+ public static final String SPEECH_WOMAN = "woman";
+
+
+
+ /**
+ * 好友申请消息提醒
+ */
+ public static final String ADD_FRIEND_NOTICE = "addFriend";
+ /**
+ * 帮助简报消息提醒
+ */
+ public static final String HELP_REPORT_NOTICE = "helpReport";
+ /**
+ * 偷菜简报消息提醒
+ */
+ public static final String STEAL_REPORT_NOTICE = "stealReport";
+ /**
+ * 任务消息提醒
+ */
+ public static final String TASK_NOTICE = "task";
+
+
+ /**
+ * 未成熟-0
+ */
+ public static final Integer MATURE_NO = 0;
+ /**
+ * 成熟-1
+ */
+ public static final Integer MATURE_YES = 1;
+
+
+ /**
+ * 花圃空闲-0
+ */
+ public static final Integer NURSERY_FREE = 0;
+ /**
+ * 花圃忙碌-1
+ */
+ public static final Integer NURSERY_BUSY = 1;
+
+
+ /**
+ * 不存在-0
+ */
+ public static final Integer NON = 0;
+
+
+ /**
+ * 防守失败-0
+ */
+ public static final Integer DEFEND_FAIL = 0;
+ /**
+ * 防守成功-1
+ */
+ public static final Integer DEFEND_SUCCESS = 1;
+
+ /**
+ * 简报未读-0
+ */
+ public static final Integer READ_NO = 0;
+ /**
+ * 简报已读-1
+ */
+ public static final Integer READ_YES = 1;
+
+
+ /**
+ * 数据存放地址
+ */
+ public static final String userFilePath = "/home/qwyf14/dataBackup/";
}
diff --git a/src/main/java/com/qiwuai/garden/common/InitSysServlet.java b/src/main/java/com/qiwuai/garden/common/InitSysServlet.java
index ebc231e..e8c6008 100644
--- a/src/main/java/com/qiwuai/garden/common/InitSysServlet.java
+++ b/src/main/java/com/qiwuai/garden/common/InitSysServlet.java
@@ -1,20 +1,25 @@
package com.qiwuai.garden.common;
+import com.qiwuai.garden.common.utils.TypeConvertUtil;
import com.qiwuai.garden.dao.*;
-import com.qiwuai.garden.dto.AddItemDto;
-import com.qiwuai.garden.dto.AddItemSetDto;
+import com.qiwuai.garden.dto.GardenerDto;
+import com.qiwuai.garden.dto.GardenerSkillDto;
import com.qiwuai.garden.dto.PlantPeriodDto;
+import com.qiwuai.garden.dto.RegionDto;
import com.qiwuai.garden.pojo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
import java.math.BigDecimal;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
@Component
public class InitSysServlet implements InitializingBean {
@@ -23,7 +28,7 @@ public class InitSysServlet implements InitializingBean {
private NurseryMapper nurseryMapper;
private PlantPeriodMapper plantPeriodMapper;
private PlantMapper plantMapper;
- private PlantAttributeMapper plantAttributeMapper;
+ private AttributeMapper attributeMapper;
private AddItemSetMapper addItemSetMapper;
private AddItemMapper addItemMapper;
private ItemMapper itemMapper;
@@ -37,6 +42,9 @@ public class InitSysServlet implements InitializingBean {
private SkillResetCostMapper skillResetCostMapper;
private ItemTypeMapper itemTypeMapper;
private GoodsMapper goodsMapper;
+ private QuantityRangeMapper quantityRangeMapper;
+ private RegionMapper regionMapper;
+ private RarityMapper rarityMapper;
@Autowired
public void setNurseryMapper(NurseryMapper nurseryMapper) {
@@ -54,8 +62,8 @@ public class InitSysServlet implements InitializingBean {
}
@Autowired
- public void setPlantAttributeMapper(PlantAttributeMapper plantAttributeMapper) {
- this.plantAttributeMapper = plantAttributeMapper;
+ public void setAttributeMapper(AttributeMapper attributeMapper) {
+ this.attributeMapper = attributeMapper;
}
@Autowired
@@ -123,6 +131,21 @@ public class InitSysServlet implements InitializingBean {
this.goodsMapper = goodsMapper;
}
+ @Autowired
+ public void setQuantityRangeMapper(QuantityRangeMapper quantityRangeMapper) {
+ this.quantityRangeMapper = quantityRangeMapper;
+ }
+
+ @Autowired
+ public void setRegionMapper(RegionMapper regionMapper) {
+ this.regionMapper = regionMapper;
+ }
+
+ @Autowired
+ public void setRarityMapper(RarityMapper rarityMapper) {
+ this.rarityMapper = rarityMapper;
+ }
+
/**
* 保存配置信息到缓存
*/
@@ -161,14 +184,14 @@ public class InitSysServlet implements InitializingBean {
log.info("缓存中植物配置信息:" + TimingAcquisition.plantMap);
log.info("植物配置缓存完成");
- //缓存植物属性配置信息
- Map plantAttributePojoMap = new ConcurrentHashMap<>();
- List plantAttributeList = plantAttributeMapper.searchAll();
- for (PlantAttributePojo plantAttribute : plantAttributeList) {
- plantAttributePojoMap.put(plantAttribute.getId(), plantAttribute);
+ //缓存属性配置信息
+ Map attributePojoMap = new ConcurrentHashMap<>();
+ List attributeList = attributeMapper.searchAll();
+ for (AttributePojo attribute : attributeList) {
+ attributePojoMap.put(attribute.getId(), attribute);
}
- TimingAcquisition.plantAttributeMap.putAll(plantAttributePojoMap);
- log.info("缓存中植物属性配置信息:" + TimingAcquisition.plantAttributeMap);
+ TimingAcquisition.attributeMap.putAll(attributePojoMap);
+ log.info("缓存中植物属性配置信息:" + TimingAcquisition.attributeMap);
log.info("植物属性配置缓存完成");
//缓存植物生长周期信息
@@ -327,5 +350,76 @@ public class InitSysServlet implements InitializingBean {
TimingAcquisition.goodsConfigMap.putAll(goodsConfigMap);
log.info("缓存中商品配置信息" + TimingAcquisition.goodsConfigMap);
log.info("商品配置信息缓存完成");
+
+ //缓存稀有度配置信息
+ Map rarityMap = new ConcurrentHashMap<>();
+ List rarityList = rarityMapper.findAll();
+ for (RarityPojo rarity : rarityList) {
+ rarityMap.put(rarity.getId(), rarity);
+ }
+ TimingAcquisition.rarityMap.putAll(rarityMap);
+ log.info("缓存中稀有度配置信息" + TimingAcquisition.rarityMap);
+ log.info("稀有度配置信息缓存完成");
+
+ //缓存数量范围配置信息
+ Map quantityRangeMap = new ConcurrentHashMap<>();
+ List quantityRangeList = quantityRangeMapper.findAll();
+ for (QuantityRangePojo quantityRange : quantityRangeList) {
+ quantityRangeMap.put(quantityRange.getId(), quantityRange);
+ }
+ TimingAcquisition.quantityRangeMap.putAll(quantityRangeMap);
+ log.info("缓存中数量范围配置信息" + TimingAcquisition.quantityRangeMap);
+ log.info("数量范围配置信息缓存完成");
+
+ //缓存地区与服务器对应信息
+ Map regionIPMap = new ConcurrentHashMap<>();
+ List regionList = regionMapper.findAll();
+ for (RegionPojo region : regionList) {
+ regionIPMap.put(region.getPlace(), region);
+ }
+ TimingAcquisition.regionIPMap.putAll(regionIPMap);
+ log.info("缓存中地区与服务器对应信息" + TimingAcquisition.regionIPMap);
+ log.info("地区与服务器对应信息缓存完成");
+
+ //缓存玩家地址对应的地区信息
+ Map> addressMap = new ConcurrentHashMap<>();
+ Map regionPojoMap = TimingAcquisition.regionIPMap;
+ //所有地区
+ List placeList = regionPojoMap.values().stream().map(RegionPojo::getPlace).collect(Collectors.toList());
+ for (String p : placeList) {
+ Map regionDtoMap = new HashMap<>();
+ addressMap.put(p, regionDtoMap);
+ }
+ for (Map.Entry entry : TimingAcquisition.gardenerMap.entrySet()) {
+ GardenerDto gardener = entry.getValue();
+ //玩家地址
+ String location = gardener.getLocation();
+ //存在玩家地址
+ if (!StringUtils.isEmpty(location)) {
+ //分地区存放玩家地址
+ for (String p : placeList) {
+ RegionDto region = new RegionDto();
+ String place = TypeConvertUtil.extractChinese(location);
+ //找到了玩家地址对应地区
+ if (p.equals(place)) {
+ if (!StringUtils.isEmpty(regionPojoMap.get(place))) {
+ String serverIP = regionPojoMap.get(place).getServerIP();
+ region.setServerIP(serverIP);
+ }
+ String number = TypeConvertUtil.extractNo(location);
+ region.setUid(gardener.getUid());
+ region.setName(gardener.getGardenerInfo().getName());
+ region.setPlace(place);
+ region.setNumber(number);
+ addressMap.get(p).put(location, region);
+ break;
+ }
+ }
+ }
+ }
+ TimingAcquisition.addressMap.putAll(addressMap);
+ log.info("缓存中玩家地址对应的地区信息" + TimingAcquisition.addressMap);
+ log.info("玩家地址对应的地区信息缓存完成");
+
}
}
diff --git a/src/main/java/com/qiwuai/garden/common/ProxyFactory.java b/src/main/java/com/qiwuai/garden/common/ProxyFactory.java
new file mode 100644
index 0000000..6987d4d
--- /dev/null
+++ b/src/main/java/com/qiwuai/garden/common/ProxyFactory.java
@@ -0,0 +1,50 @@
+package com.qiwuai.garden.common;
+
+import com.qiwuai.garden.dto.request.OperationRequest;
+import org.springframework.util.StringUtils;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public class ProxyFactory {
+ private Object target;
+ public ProxyFactory(Object target) {
+ this.target = target;
+ }
+
+ public Object getProxyInstance() {
+ return Proxy.newProxyInstance(
+ target.getClass().getClassLoader(),
+ target.getClass().getInterfaces(),
+ new InvocationHandler() {
+ @Override
+ public Object invoke(Object o, Method method, Object[] args) throws Throwable {
+ OperationRequest request = (OperationRequest) args[0];
+ //更新玩家在线状态
+ statusUpdate(request.getUid());
+ Object var = method.invoke(target, args);
+ //玩家有新消息提示
+ System.out.println("增加参数返回,var:" + var);
+ return var;
+ }
+ }
+ );
+ }
+
+ /**
+ * 玩家状态更新为在线
+ */
+ public void statusUpdate(String uid) {
+ if (!StringUtils.isEmpty(TimingAcquisition.gardenerMap.get(uid))) {
+ TimingAcquisition.gardenerMap.get(uid).setStatus(Constants.ONLINE);
+ }
+ }
+
+ /**
+ * 检查玩家是否有新消息,有则添加后台返回值给bot端
+ */
+ public void addMessage() {
+
+ }
+}
diff --git a/src/main/java/com/qiwuai/garden/common/TimingAcquisition.java b/src/main/java/com/qiwuai/garden/common/TimingAcquisition.java
index fc797f2..8b6a625 100644
--- a/src/main/java/com/qiwuai/garden/common/TimingAcquisition.java
+++ b/src/main/java/com/qiwuai/garden/common/TimingAcquisition.java
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.qiwuai.garden.common.utils.DateUtil;
import com.qiwuai.garden.common.utils.PersistenceUtil;
+import com.qiwuai.garden.common.utils.TypeConvertUtil;
+import com.qiwuai.garden.common.utils.YamlUtil;
import com.qiwuai.garden.dto.*;
import com.qiwuai.garden.dto.ItemBagDto;
import com.qiwuai.garden.pojo.*;
@@ -11,9 +13,14 @@ import com.qiwuai.garden.service.plantService.PlantService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
+import java.io.File;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -37,21 +44,22 @@ public class TimingAcquisition {
*/
public volatile static Map gardenerMap = new ConcurrentHashMap<>();
/**
- * 背包信息
+ * 地区与编号对应信息,用于新建玩家的地区+ID中的ID编号生成
*/
- public volatile static Map backpackMap = new ConcurrentHashMap<>();
+ public volatile static Map regionNoMap = new ConcurrentHashMap<>();
/**
- * 商店信息
+ * 玩家地址对应地区信息,加载玩家数据时一起缓存: Map<地区, Map<玩家地址, RegionDto>>
*/
- public volatile static Map shopMap = new ConcurrentHashMap<>();
+ public volatile static Map> addressMap = new ConcurrentHashMap<>();
+
/**
- * 商品配置信息
+ * 地区与服务器对应的配置信息
*/
- public volatile static Map goodsConfigMap = new ConcurrentHashMap<>();
+ public volatile static Map regionIPMap = new ConcurrentHashMap<>();
/**
- * 花园信息
+ * 商品配置信息
*/
- public volatile static Map gardenMap = new ConcurrentHashMap<>();
+ public volatile static Map goodsConfigMap = new ConcurrentHashMap<>();
/**
* 植物生长周期信息
*/
@@ -97,9 +105,9 @@ public class TimingAcquisition {
*/
public volatile static Map plantTypeMap = new ConcurrentHashMap<>();
/**
- * 植物属性配置信息
+ * 属性配置信息
*/
- public volatile static Map plantAttributeMap = new ConcurrentHashMap<>();
+ public volatile static Map attributeMap = new ConcurrentHashMap<>();
/**
* 植物生长期配置信息
*/
@@ -113,10 +121,6 @@ public class TimingAcquisition {
*/
public volatile static Map petTypeMap = new ConcurrentHashMap<>();
/**
- * 宠物属性配置信息
- */
- public volatile static Map petAttributeMap = new ConcurrentHashMap<>();
- /**
* 物品配置信息
*/
public volatile static Map itemConfigMap = new ConcurrentHashMap<>();
@@ -140,21 +144,37 @@ public class TimingAcquisition {
* 系统配置信息
*/
public volatile static Map systemConfigMap = new ConcurrentHashMap<>();
+ /**
+ * 数量范围配置信息
+ */
+ public volatile static Map quantityRangeMap = new ConcurrentHashMap<>();
+
+
+ /**
+ * 种植模块话术
+ */
+ public volatile static Map>> plantSpeechMap = new ConcurrentHashMap<>();
+ /**
+ * 园丁模块话术
+ */
+ public volatile static Map>> gardenerSpeechMap = new ConcurrentHashMap<>();
+ /**
+ * 宠物模块话术
+ */
+ public volatile static Map>> petSpeechMap = new ConcurrentHashMap<>();
+ /**
+ * 市场模块话术
+ */
+ public volatile static Map>> marketSpeechMap = new ConcurrentHashMap<>();
+ /**
+ * 社交模块话术
+ */
+ public volatile static Map>> socialSpeechMap = new ConcurrentHashMap<>();
/**
* 加载所有数据到缓存中
*/
public void loadingTest() {
- ShopDto shop = new ShopDto();
- ItemInfoDto item = new ItemInfoDto();
- item.setItemId(2);
- item.setItemName("西瓜");
- item.setPrice(300);
- Map itemMap = new ConcurrentHashMap<>();
- itemMap.put(2, item);
- shop.setItems(itemMap);
- shopMap.put("test", shop);
-
//初始化背包,后期删除
BackPackDto backPack= new BackPackDto(); //定义背包
ItemBagDto moneyBag = new ItemBagDto(); //定义背包里的货币袋
@@ -175,7 +195,6 @@ public class TimingAcquisition {
backPack.setUpdateTime(DateUtil.getCurrentTime());
backPack.add(1, moneyBag);
backPack.add(3, materialBag);
- backpackMap.put("test", backPack);
//初始化花园
GardenDto gardenDto = new GardenDto();
@@ -198,7 +217,6 @@ public class TimingAcquisition {
gardenDto.setNurseryResetTimes(0);
gardenDto.setCreateTime(DateUtil.getCurrentTime());
gardenDto.setUpdateTime(DateUtil.getCurrentTime());
- gardenMap.put("test", gardenDto);
//初始化累计任务信息
Map taskCountMap = new ConcurrentHashMap<>();
@@ -206,6 +224,10 @@ public class TimingAcquisition {
taskCountMap.put(Constants.HARVEST_EVENT, 0);
taskCountMap.put(Constants.STEAL_SUCCESS_EVENT, 0);
taskCountMap.put(Constants.HELP_EVENT, 0);
+ taskCountMap.put(Constants.DAILY_TASK_EVENT, 0);
+ taskCountMap.put(Constants.GET_PET_EVENT, 0);
+ taskCountMap.put(Constants.RECLAIM_NURSERY_EVENT, 0);
+ taskCountMap.put(Constants.STEAL_EVENT, 0);
//初始化园丁信息
GardenerDto gardener = new GardenerDto();
@@ -217,26 +239,80 @@ public class TimingAcquisition {
}
/**
- * 通过json文件加载所有数据到缓存中
+ * 通过json文件加载所有用户数据到缓存中
*/
public static void loading() {
- String s = PersistenceUtil.getDataFromFile("test");
- //JSON转map对象
- log.info("取出的数据:" + s);
- Map gardener = JSON.parseObject(s, new TypeReference