back_recharge
gaojie 2019-01-22 09:25:49 +08:00
commit 38080b502e
41 changed files with 1356 additions and 322 deletions

View File

@ -28,6 +28,10 @@ public class LjsdMongoTemplate {
root.setBsave(true);
}
public <T> void saveWithoutMongoRoot(T obj) throws Exception {
mongoTemplate.save(obj);
}
public <T> List<T> findAll(String collectionName, Class<T> clazz) throws Exception {
DBCollection coll = mongoTemplate.getCollection(collectionName);
DBCursor dbCursor = coll.find();
@ -44,6 +48,10 @@ public class LjsdMongoTemplate {
return BeanUtil.dbObject2Bean(doc, clazz);
}
public <T> T findById(int id, Class<T> clazz) throws Exception {
return mongoTemplate.findById(id,clazz);
}
public void chnage(Object obj){
Class<?> clazz = obj.getClass();
}

View File

@ -57,7 +57,10 @@ public class MongoUpdateCache {
valueDBObj.append(request.fullKey, ljsdMongoTemplate.convertToMongoType(request.value));
request.mongoBase.set_save(false);
}
dbobj.append("$set", valueDBObj);
if (!valueDBObj.isEmpty()) {
dbobj.append("$set", valueDBObj);
}
if (!removedbobj.isEmpty()) {
dbobj.append("$unset", removedbobj);
}

View File

@ -1,57 +1,58 @@
Id PiecesId PiecesCount Profession PropertyName MaxRank Hp Attack PhysicalDefence MagicDefence Speed SkillId RankupConsumeMaterial
int int int int int int float float float float float mut,int#int,2 mut,int#int,2
1 2001 0 1 1 10 2389 164 278 0 176 10100#10|10101#20 null
2 2002 0 5 2 10 2277 155 260 0 158 10100#10|10101#20 null
3 2003 0 2 3 10 2275 159 263 0 172 10100#10|10101#20 null
4 2004 0 3 4 10 2269 183 0 277 132 10100#10|10101#20 null
5 2005 0 4 5 10 2163 173 0 258 176 10100#10|10101#20 null
6 2006 0 3 6 10 2165 174 0 261 176 10100#10|10101#20 null
7 2007 0 0 2 10 2159 169 0 262 176 10100#10|10101#20 null
8 2008 0 0 2 10 2020 206 0 222 132 10100#10|10101#20 null
9 2009 0 0 2 10 1923 198 0 212 163 10100#10|10101#20 null
10 2010 0 0 2 10 1925 200 0 208 132 10100#10|10101#20 null
11 2011 0 0 2 10 1925 199 0 203 150 10100#10|10101#20 null
12 2012 0 0 2 10 1763 251 201 0 150 10100#10|10101#20 null
13 2013 0 0 3 10 1675 239 194 0 163 10100#10|10101#20 null
14 2014 0 0 3 10 1684 235 197 0 185 10100#10|10101#20 null
15 2015 0 0 3 10 1680 237 193 0 176 10100#10|10101#20 null
16 2016 0 0 3 10 1513 293 167 0 154 10100#10|10101#20 null
17 2017 0 0 3 10 1439 278 159 0 154 10100#10|10101#20 null
18 2018 0 0 3 10 1439 278 159 0 154 10100#10|10101#20 null
19 2019 0 0 4 10 1444 281 153 0 154 10100#10|10101#20 null
20 2020 0 0 4 10 2277 159 261 0 154 10100#10|10101#20 null
21 2021 0 0 4 10 1936 131 225 0 176 10100#10|10101#20 null
22 2022 0 0 4 10 1637 168 0 178 163 10100#10|10101#20 null
23 2023 0 0 4 10 1431 200 162 0 194 10100#10|10101#20 null
24 2024 0 0 4 10 1220 239 133 0 154 10100#10|10101#20 null
25 2025 0 0 4 10 1832 143 0 222 176 10100#10|10101#20 null
26 2026 0 0 4 10 1934 136 226 0 176 10100#10|10101#20 null
27 2027 0 0 4 10 1628 173 0 175 163 10100#10|10101#20 null
28 2028 0 0 4 10 1428 209 165 0 194 10100#10|10101#20 null
29 2029 0 0 4 10 1222 235 132 0 154 10100#10|10101#20 null
30 2030 0 0 4 10 1834 149 0 224 176 10100#10|10101#20 null
31 2031 0 0 4 10 1940 131 220 0 176 10100#10|10101#20 null
32 2032 0 0 4 10 1632 165 0 177 163 10100#10|10101#20 null
33 2033 0 0 4 10 1429 205 164 0 194 10100#10|10101#20 null
34 2034 0 0 4 10 1221 242 135 0 154 10100#10|10101#20 null
35 2035 0 0 4 10 1834 147 0 225 176 10100#10|10101#20 null
36 2036 0 0 4 10 1934 136 217 0 176 10100#10|10101#20 null
37 2037 0 0 4 10 1637 170 0 179 163 10100#10|10101#20 null
38 2038 0 0 4 10 1427 201 170 0 194 10100#10|10101#20 null
39 2039 0 0 4 10 1300 235 129 0 154 10100#10|10101#20 null
40 2040 0 0 4 10 1948 147 0 219 176 10100#10|10101#20 null
41 2041 0 0 4 10 1938 135 224 0 176 10100#10|10101#20 null
42 2042 0 0 4 10 1636 174 0 179 163 10100#10|10101#20 null
43 2043 0 0 4 10 1943 132 217 0 176 10100#10|10101#20 null
44 2044 0 0 4 10 1627 166 0 181 163 10100#10|10101#20 null
45 2045 0 0 4 10 1433 209 166 0 194 10100#10|10101#20 null
46 2046 0 0 4 10 1228 241 131 0 154 10100#10|10101#20 null
47 2047 0 0 4 10 1836 146 0 226 176 10100#10|10101#20 null
48 2048 0 0 4 10 1939 141 223 0 176 10100#10|10101#20 null
49 2049 0 0 4 10 1635 175 0 173 163 10100#10|10101#20 null
50 2050 0 0 4 10 1424 208 166 0 194 10100#10|10101#20 null
51 2051 0 0 4 10 1222 234 132 0 154 10100#10|10101#20 null
52 2052 0 0 4 10 1834 140 0 220 176 10100#10|10101#20 null
53 2053 0 0 4 10 1943 135 219 0 176 10100#10|10101#20 null
54 2054 0 0 4 10 1630 169 0 176 163 10100#10|10101#20 null
55 2055 0 0 4 10 1508 205 163 0 194 10100#10|10101#20 null
Id PiecesId PiecesCount Star Profession PropertyName MaxRank Hp Attack PhysicalDefence MagicDefence Speed SkillId RankupConsumeMaterial
int int int int int int int float float float float float mut,int#int,2 mut,int#int,2
10001 11001 50 5 1 1 10 2390 167 275 96 176 10100#10|10101#20 null
10002 11002 50 5 5 2 10 2278 165 265 93 158 10100#10|10101#20 null
10003 11003 50 5 2 3 10 2277 155 259 91 172 10100#10|10101#20 null
10004 11004 50 5 3 4 10 2263 183 97 278 132 10100#10|10101#20 null
10005 11005 50 5 4 5 10 2163 170 92 263 176 10100#10|10101#20 null
10006 11006 50 5 3 6 10 2159 174 93 265 176 10100#10|10101#20 null
10007 11007 50 5 0 2 10 2161 168 91 261 176 10100#10|10101#20 null
10008 11008 50 5 0 2 10 2016 208 77 220 132 10100#10|10101#20 null
10009 11009 50 5 0 2 10 1922 196 74 212 163 10100#10|10101#20 null
10010 11010 50 5 0 2 10 1919 202 71 203 132 10100#10|10101#20 null
10011 11011 50 5 0 2 10 1921 198 71 203 150 10100#10|10101#20 null
10012 11012 50 5 0 2 10 1768 253 201 70 150 10100#10|10101#20 null
10013 11013 50 5 0 3 10 1682 244 199 70 163 10100#10|10101#20 null
10014 11014 50 5 0 3 10 1676 245 200 70 185 10100#10|10101#20 null
10015 11015 50 5 0 3 10 1680 245 198 69 176 10100#10|10101#20 null
10016 11016 50 5 0 3 10 1507 293 160 56 154 10100#10|10101#20 null
10017 11017 50 5 0 3 10 1437 278 157 55 154 10100#10|10101#20 null
10018 11018 50 5 0 3 10 1440 285 154 54 154 10100#10|10101#20 null
10019 11019 50 5 0 4 10 1440 284 159 56 154 10100#10|10101#20 null
10020 11020 50 5 0 4 10 2280 164 256 90 154 10100#10|10101#20 null
10021 11021 40 4 0 4 10 1941 133 218 76 176 10100#10|10101#20 null
10022 11022 40 4 0 4 10 1630 175 62 178 163 10100#10|10101#20 null
10023 11023 40 4 0 4 10 1428 208 161 56 194 10100#10|10101#20 null
10024 11024 40 4 0 4 10 1225 237 135 47 154 10100#10|10101#20 null
10025 11025 40 4 0 4 10 1831 148 78 223 176 10100#10|10101#20 null
10026 11026 40 4 0 4 10 1943 132 223 78 176 10100#10|10101#20 null
10027 11027 40 4 0 4 10 1629 169 61 173 163 10100#10|10101#20 null
10028 11028 40 4 0 4 10 1431 203 166 58 194 10100#10|10101#20 null
10029 11029 40 4 0 4 10 1223 241 136 48 154 10100#10|10101#20 null
10030 11030 40 4 0 4 10 1835 140 76 218 176 10100#10|10101#20 null
10031 11031 40 4 0 4 10 1940 133 221 77 176 10100#10|10101#20 null
10032 11032 40 4 0 4 10 1636 172 61 175 163 10100#10|10101#20 null
10033 11033 40 4 0 4 10 1433 209 169 59 194 10100#10|10101#20 null
10034 11034 40 4 0 4 10 1222 237 137 48 154 10100#10|10101#20 null
10035 11035 40 4 0 4 10 1832 147 76 217 176 10100#10|10101#20 null
10036 11036 40 4 0 4 10 1933 137 217 76 176 10100#10|10101#20 null
10037 11037 40 4 0 4 10 1630 170 63 180 163 10100#10|10101#20 null
10038 11038 40 4 0 4 10 1428 204 169 59 194 10100#10|10101#20 null
10039 11039 40 4 0 4 10 1292 235 136 48 154 10100#10|10101#20 null
10040 11040 40 4 0 4 10 1945 142 78 224 176 10100#10|10101#20 null
10041 11041 40 4 0 4 10 1935 134 225 79 176 10100#10|10101#20 null
10042 11042 40 4 0 4 10 1634 172 63 179 163 10100#10|10101#20 null
10043 11043 40 4 0 4 10 1943 134 220 77 176 10100#10|10101#20 null
10044 11044 40 4 0 4 10 1629 169 61 173 163 10100#10|10101#20 null
10045 11045 40 4 0 4 10 1423 200 167 58 194 10100#10|10101#20 null
10046 11046 30 3 0 4 10 1222 240 135 47 154 10100#10|10101#20 null
10047 11047 30 3 0 4 10 1838 140 79 225 176 10100#10|10101#20 null
10048 11048 30 3 0 4 10 1940 138 220 77 176 10100#10|10101#20 null
10049 11049 30 3 0 4 10 1627 165 62 176 163 10100#10|10101#20 null
10050 11050 30 3 0 4 10 1433 204 169 59 194 10100#10|10101#20 null
10051 11051 30 3 0 4 10 1222 233 131 46 154 10100#10|10101#20 null
10052 11052 30 3 0 4 10 1834 142 79 225 176 10100#10|10101#20 null
10053 11053 30 3 0 4 10 1937 141 224 78 176 10100#10|10101#20 null
10054 11054 30 3 0 4 10 1633 167 61 174 163 10100#10|10101#20 null
10055 11055 30 3 0 4 10 1516 202 166 58 194 10100#10|10101#20 null
10056 11056 30 3 0 4 10 1299 235 129 45 154 10100#10|10101#20 null

View File

@ -1,6 +1,130 @@
Id BackpackOrNot ItemType ItemBaseType Quantity IsStacking
int bool int int int bool
1 false 1 1 5 false
2 true 1 1 5 false
3 true 1 1 5 false
4 false 1 1 5 false
Id ItemType Quantity IsStacking
int int int bool
1 0 5 true
2 0 5 true
3 0 5 true
4 0 5 true
5 0 5 true
1001 0 1 true
1002 0 2 true
1003 0 3 true
1004 0 4 true
1005 0 5 true
1006 0 5 true
1007 0 5 true
1008 0 5 true
1009 0 5 true
1100 0 3 true
1101 0 3 true
10001 1 5 false
10002 1 5 false
10003 1 5 false
10004 1 5 false
10005 1 5 false
10006 1 5 false
10007 1 5 false
10008 1 5 false
10009 1 5 false
10010 1 5 false
10011 1 5 false
10012 1 5 false
10013 1 5 false
10014 1 5 false
10015 1 5 false
10016 1 5 false
10017 1 5 false
10018 1 5 false
10019 1 5 false
10020 1 5 false
10021 1 5 false
10022 1 5 false
10023 1 5 false
10024 1 5 false
10025 1 5 false
10026 1 5 false
10027 1 5 false
10028 1 5 false
10029 1 5 false
10030 1 5 false
10031 1 5 false
10032 1 5 false
10033 1 5 false
10034 1 5 false
10035 1 5 false
10036 1 5 false
10037 1 5 false
10038 1 5 false
10039 1 5 false
10040 1 5 false
10041 1 5 false
10042 1 5 false
10043 1 5 false
10044 1 5 false
10045 1 5 false
10046 1 5 false
10047 1 5 false
10048 1 5 false
10049 1 5 false
10050 1 5 false
10051 1 5 false
10052 1 5 false
10053 1 5 false
10054 1 5 false
10055 1 5 false
10056 1 5 false
11001 2 5 true
11002 2 5 true
11003 2 5 true
11004 2 5 true
11005 2 5 true
11006 2 5 true
11007 2 5 true
11008 2 5 true
11009 2 5 true
11010 2 5 true
11011 2 5 true
11012 2 5 true
11013 2 5 true
11014 2 5 true
11015 2 5 true
11016 2 5 true
11017 2 5 true
11018 2 5 true
11019 2 5 true
11020 2 5 true
11021 2 5 true
11022 2 5 true
11023 2 5 true
11024 2 5 true
11025 2 5 true
11026 2 5 true
11027 2 5 true
11028 2 5 true
11029 2 5 true
11030 2 5 true
11031 2 5 true
11032 2 5 true
11033 2 5 true
11034 2 5 true
11035 2 5 true
11036 2 5 true
11037 2 5 true
11038 2 5 true
11039 2 5 true
11040 2 5 true
11041 2 5 true
11042 2 5 true
11043 2 5 true
11044 2 5 true
11045 2 5 true
11046 2 5 true
11047 2 5 true
11048 2 5 true
11049 2 5 true
11050 2 5 true
11051 2 5 true
11052 2 5 true
11053 2 5 true
11054 2 5 true
11055 2 5 true
11056 2 5 true

View File

@ -0,0 +1,73 @@
Id Reward ItemName Pool Weight
int mut,int#int,1 string int int
2 10002#1 角色2 1 11
3 10003#1 角色3 1 11
4 10004#1 角色4 1 8
5 10005#1 角色5 1 11
6 10006#1 角色6 1 11
7 10007#1 角色7 1 11
8 10008#1 角色8 1 8
9 10009#1 角色9 1 11
10 10010#1 角色10 1 5
11 10011#1 角色11 1 11
12 10012#1 角色12 1 8
13 10013#1 角色13 1 11
14 10014#1 角色14 1 5
15 10015#1 角色15 1 11
16 10016#1 角色16 1 8
17 10017#1 角色17 1 11
18 10018#1 角色18 1 5
19 10019#1 角色19 1 5
20 10020#1 角色20 1 11
21 10021#1 角色21 1 95
22 10022#1 角色22 1 95
23 10023#1 角色23 1 95
24 10024#1 角色24 1 95
25 10025#1 角色25 1 95
26 10026#1 角色26 1 95
27 10027#1 角色27 1 95
28 10028#1 角色28 1 95
29 10029#1 角色29 1 95
30 10030#1 角色30 1 95
31 10031#1 角色31 1 95
32 10032#1 角色32 1 95
33 10033#1 角色33 1 95
34 10034#1 角色34 1 95
35 10035#1 角色35 1 95
36 10036#1 角色36 1 95
37 10037#1 角色37 1 95
38 10038#1 角色38 1 95
39 10039#1 角色39 1 47
40 10040#1 角色40 1 47
41 10041#1 角色41 1 95
42 10042#1 角色42 1 95
43 10043#1 角色43 1 600
44 10044#1 角色44 1 600
45 10045#1 角色45 1 600
46 10046#1 角色46 1 600
47 10047#1 角色47 1 600
48 10048#1 角色48 1 600
49 10049#1 角色49 1 600
50 10050#1 角色50 1 600
51 10051#1 角色51 1 600
52 10052#1 角色52 1 600
53 10053#1 角色53 1 600
54 10054#1 角色54 1 600
55 10055#1 角色55 1 300
56 10056#1 角色56 1 300
57 10035#1 角色35 11 100
58 10036#1 角色36 11 100
59 10037#1 角色37 11 100
60 10038#1 角色38 11 100
61 10031#1 角色31 12 100
62 10032#1 角色32 12 100
63 10033#1 角色33 12 100
64 10034#1 角色34 12 100
65 10026#1 角色26 13 100
66 10027#1 角色27 13 100
67 10028#1 角色28 13 100
68 10029#1 角色29 13 100
69 10021#1 角色21 14 100
70 10022#1 角色22 14 100
71 10023#1 角色23 14 100
72 10024#1 角色24 14 100

View File

@ -0,0 +1,6 @@
Id OrderBoxOpenTime OrderBoxContinue OrderBoxInterval OrderBoxPool DiamondBoxInterval Cost GetHerosInterval DiamondBoxContain TenTimesMustGetItem PerCount
int int int int mut,int#int,1 int mut,int#int,1 int mut,int#int,2 mut,int#int,1 int
1 56 48 120 11#12#13#14 0 3#10 0 null null 10
2 56 48 120 11#12#13#14 0 3#1 0 null null 1
11 0 0 0 null 0 220 150 1#100 3#1 10
12 0 0 0 null 2160.0 2200 0 1#100 null 1

View File

@ -1,5 +1,7 @@
package com.ljsd;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.jieling.config.ServerConfig;
import com.ljsd.jieling.config.json.ServerConfiguration;
import com.ljsd.jieling.config.json.ServerProperties;
import com.ljsd.jieling.db.redis.RedisUtil;
@ -12,6 +14,7 @@ import com.ljsd.jieling.network.NettyServerAutoConfiguration;
import com.ljsd.jieling.network.server.ProtocolsManager;
import com.ljsd.jieling.network.session.ISessionFactory;
import com.ljsd.jieling.thread.ThreadManager;
import com.ljsd.jieling.util.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
@ -21,6 +24,8 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@ -39,6 +44,8 @@ public class GameApplication {
// public static ServerProperties serverProperties;
public static boolean start = false;
public static ServerConfig serverConfig;
public static void main(String[] args) throws Exception {
start = true;
app = new SpringApplication(GameApplication.class);
@ -62,7 +69,7 @@ public class GameApplication {
RedisUtil.getInstence().init(configurableApplicationContext);
// STableManager.initialize("com.ljsd.jieling.config");
STableManager.initialize("com.ljsd.jieling.config");
UserManager.init(configurableApplicationContext);
@ -71,6 +78,24 @@ public class GameApplication {
final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class);
NettyProperties properties = netServerConfig.getNettyProperties();
//todo 设置开服时间
ServerConfig serverConfigTmp = UserManager.ljsdMongoTemplate.findById(1, ServerConfig.class);
if( null == serverConfigTmp ){
serverConfigTmp = new ServerConfig();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long serverOenTime = TimeUtils.getAppointTime(5);
String format = simpleDateFormat.format(serverOenTime);
serverConfigTmp.setOpenTime(format);
serverConfigTmp.setCacheOpenTime(serverOenTime);
serverConfigTmp.setId(1);
UserManager.ljsdMongoTemplate.saveWithoutMongoRoot(serverConfigTmp);
}else{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String openTime = serverConfigTmp.getOpenTime();
Date date = simpleDateFormat.parse(openTime);
serverConfigTmp.setCacheOpenTime(date.getTime());
serverConfig = serverConfigTmp;
}
try {
LOGGER.info("main->CoreApplication start...");
ISessionFactory sessionFactory = new ISessionFactory();

View File

@ -22,6 +22,8 @@ public class SCHero implements BaseConfig{
private int maxRank; //角色最高星级
private int star;
private float hp;
private float attack; //攻击力

View File

@ -6,7 +6,7 @@ import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name = "1.Map")
@Table(name = "Map")
public class SCMap implements BaseConfig {
public static Map<Integer, Map<Integer, SCMap>> sCMap;
private int id;

View File

@ -6,9 +6,12 @@ import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name = "MapEventsConfig")
public class SCMapEvent implements BaseConfig{
public static Map<Integer, SCMapEvent> scMapEventMap;
public class SCMapEventsConfig implements BaseConfig{
public static Map<Integer, SCMapEventsConfig> scMapEventMap;
/**
* id
*/
private int id;
/**
* "
@ -22,6 +25,7 @@ public class SCMapEvent implements BaseConfig{
* 3
*/
private int refresh;
/**
*
* 1
@ -39,7 +43,7 @@ public class SCMapEvent implements BaseConfig{
@Override
public void init() throws Exception {
scMapEventMap = STableManager.getConfig(SCMapEvent.class);
scMapEventMap = STableManager.getConfig(SCMapEventsConfig.class);
}
public int getId() {
@ -54,7 +58,7 @@ public class SCMapEvent implements BaseConfig{
return refresh;
}
public static Map<Integer, SCMapEvent> getScMapEventMap() {
public static Map<Integer, SCMapEventsConfig> getScMapEventMap() {
return scMapEventMap;
}

View File

@ -0,0 +1,65 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.HashMap;
import java.util.Map;
@Table(name = "MapEventsItemConfig")
public class SCMapEventsItemConfig implements BaseConfig{
public static Map<Integer, SCMapEventsItemConfig> scMapEventsItemConfigMap;
public static Map<Integer, Map<Integer, SCMapEventsItemConfig>> scMapEventsItemConfigs;
private int id;
/**
*"id
*/
private int eventsId;
/**
*
* */
private int sort;
/**
*
*/
private String contents;
/**
*
*/
private String reward;
@Override
public void init() throws Exception {
scMapEventsItemConfigMap = STableManager.getConfig(SCMapEventsItemConfig.class);
scMapEventsItemConfigs = new HashMap<>(scMapEventsItemConfigMap.size());
for (SCMapEventsItemConfig eventsItemConfigEntry : scMapEventsItemConfigMap.values()){
if (!scMapEventsItemConfigs.containsKey(eventsItemConfigEntry.getEventId())) {
scMapEventsItemConfigs.put(eventsItemConfigEntry.getEventId(), new HashMap<>());
}
scMapEventsItemConfigs.get(eventsItemConfigEntry.getEventId()).put(eventsItemConfigEntry.getSort(), eventsItemConfigEntry);
}
}
public int getId() {
return id;
}
public int getEventId() {
return eventsId;
}
public int getSort() {
return sort;
}
public String getContents() {
return contents;
}
public String getReward() {
return reward;
}
}

View File

@ -0,0 +1,11 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.Table;
@Table(name = "MissionEventsConfig")
public class SCMissionEventsConfig implements BaseConfig {
@Override
public void init() throws Exception {
}
}

View File

@ -0,0 +1,11 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.Table;
@Table(name = "MissionEventsItemConfig")
public class SCMissionEventsItemConfig implements BaseConfig {
@Override
public void init() throws Exception {
}
}

View File

@ -0,0 +1,82 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Table(name ="LotteryRewardConfig")
public class SLotteryRewardConfig implements BaseConfig {
private int id;
private int[] reward;
private String itemName;
private int pool;
private int weight;
private static Map<Integer, List<SLotteryRewardConfig>> sLotteryRewardConfigsByPoolId;
private static Map<Integer, Integer> sLotteryRewardWeightByPoolId;
public static List<SLotteryRewardConfig> getSLotteryRewardConfigListByPoolId(int poolId) {
return sLotteryRewardConfigsByPoolId.get(poolId);
}
public static int getTotalCountByPoolId(int poolId) {
return sLotteryRewardWeightByPoolId.get(poolId);
}
@Override
public void init() throws Exception {
Map<Integer, SLotteryRewardConfig> config = STableManager.getConfig(SLotteryRewardConfig.class);
Map<Integer, Integer> sLotteryRewardWeightByPoolIdTmp = new HashMap<>();
Map<Integer, List<SLotteryRewardConfig>> sLotteryRewardConfigsByPoolIdTmp = new HashMap<>();
for(SLotteryRewardConfig sLotteryRewardConfig : config.values()){
int pool = sLotteryRewardConfig.getPool();
int weight = sLotteryRewardConfig.getWeight();
if(!sLotteryRewardConfigsByPoolIdTmp.containsKey(pool)){
sLotteryRewardConfigsByPoolIdTmp.put(pool,new ArrayList<>());
}
sLotteryRewardConfigsByPoolIdTmp.get(pool).add(sLotteryRewardConfig);
if(!sLotteryRewardWeightByPoolIdTmp.containsKey(pool)){
sLotteryRewardWeightByPoolIdTmp.put(pool,0);
}
sLotteryRewardWeightByPoolIdTmp.put(pool,sLotteryRewardWeightByPoolIdTmp.get(pool) + weight);
}
sLotteryRewardWeightByPoolId = sLotteryRewardWeightByPoolIdTmp;
sLotteryRewardConfigsByPoolId = sLotteryRewardConfigsByPoolIdTmp;
}
public int getId() {
return id;
}
public int[] getReward() {
return reward;
}
public String getItemName() {
return itemName;
}
public int getPool() {
return pool;
}
public int getWeight() {
return weight;
}
}

View File

@ -0,0 +1,93 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name ="LotterySetting")
public class SLotterySetting implements BaseConfig {
private int id;
private int orderBoxOpenTime;
private int orderBoxContinue;
private int orderBoxInterval;
private int[] orderBoxPool;
private int diamondBoxInterval;
private int[] cost;
private int getHerosInterval;
private int[][] diamondBoxContain;
private int[] tenTimesMustGetItem;
private int perCount;
private static Map<Integer,SLotterySetting> sLotterySettingByType;
public static Map<Integer, SLotterySetting> getsLotterySettingMap() {
return sLotterySettingByType;
}
@Override
public void init() throws Exception {
sLotterySettingByType = STableManager.getConfig(SLotterySetting.class);
System.out.println();
}
public int getId() {
return id;
}
public int getOrderBoxOpenTime() {
return orderBoxOpenTime;
}
public int getOrderBoxContinue() {
return orderBoxContinue;
}
public int getOrderBoxInterval() {
return orderBoxInterval;
}
public int[] getOrderBoxPool() {
return orderBoxPool;
}
public int getDiamondBoxInterval() {
return diamondBoxInterval;
}
public int[] getCost() {
return cost;
}
public int getGetHerosInterval() {
return getHerosInterval;
}
public int[][] getDiamondBoxContain() {
return diamondBoxContain;
}
public int[] getTenTimesMustGetItem() {
return tenTimesMustGetItem;
}
public int getPerCount() {
return perCount;
}
}

View File

@ -0,0 +1,43 @@
package com.ljsd.jieling.config;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@Document( collection = "server_config")
public class ServerConfig {
@Id
private int id;
@Field(value = "open_time")
private String openTime;
@Transient
private long cacheOpenTime;
public void setOpenTime(String openTime) {
this.openTime = openTime;
}
public String getOpenTime() {
return openTime;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getCacheOpenTime() {
return cacheOpenTime;
}
public void setCacheOpenTime(long cacheOpenTime) {
this.cacheOpenTime = cacheOpenTime;
}
}

View File

@ -4,8 +4,6 @@ import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;

View File

@ -5,7 +5,6 @@ import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import com.ljsd.jieling.util.MessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -42,7 +41,6 @@ public class DrawHeroHandler extends BaseHandler {
.setHeroId(1)
.setAttack(2)
.setStar(2)
.setHeroType(1)
.setLevel(1)
.setHp(1000)
.setMDefence(2000)
@ -55,7 +53,6 @@ public class DrawHeroHandler extends BaseHandler {
.setHeroId(2)
.setAttack(2)
.setStar(2)
.setHeroType(1)
.setLevel(1)
.setHp(1000)
.setMDefence(2000)
@ -68,7 +65,6 @@ public class DrawHeroHandler extends BaseHandler {
.setHeroId(3)
.setAttack(2)
.setStar(2)
.setHeroType(1)
.setLevel(1)
.setHp(1000)
.setMDefence(2000)

View File

@ -1,17 +1,23 @@
package com.ljsd.jieling.handler;
import com.ljsd.jieling.config.SCHero;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.dao.Hero;
import com.ljsd.jieling.logic.dao.HeroManager;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.MessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
@Component
public class GetAllHerosHandler extends BaseHandler{
@ -38,48 +44,13 @@ public class GetAllHerosHandler extends BaseHandler{
// // SCHero scHero = SCHero.getsCHero().get(1);
List<CommonProto.Hero> heroList = new ArrayList<>();
CommonProto.Hero hero1 = CommonProto.Hero.newBuilder()
.setId("aaa")
.setHeroId(1)
.setAttack(2)
.setStar(2)
.setHeroType(1)
.setLevel(1)
.setHp(1000)
.setMDefence(2000)
.setPDefence(3000)
.setSpeed(4000)
.build();
User user = UserManager.getUser(userId);
HeroManager heroManager = user.getHeroManager();
Map<String, Hero> heroMap = heroManager.getHeroMap();
for(Hero hero : heroMap.values()){
heroList.add(CBean2Proto.getHero(hero));
}
CommonProto.Hero hero2 = CommonProto.Hero.newBuilder()
.setId("bbb")
.setHeroId(2)
.setAttack(2)
.setStar(2)
.setHeroType(1)
.setLevel(1)
.setHp(1000)
.setMDefence(2000)
.setPDefence(3000)
.setSpeed(4000)
.build();
CommonProto.Hero hero3 = CommonProto.Hero.newBuilder()
.setId("ccc")
.setHeroId(3)
.setAttack(2)
.setStar(2)
.setHeroType(1)
.setLevel(1)
.setHp(1000)
.setMDefence(2000)
.setPDefence(3000)
.setSpeed(4000)
.build();
heroList.add(hero1);
heroList.add(hero2);
heroList.add(hero3);
HeroInfoProto.GetHeroListInfoResponse build
= HeroInfoProto.GetHeroListInfoResponse.newBuilder()

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
@Component
public class GetRandomHeroHandler extends BaseHandler{
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.HERO_RAND_REQQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] bytes = netData.parseClientProtoNetData();
HeroInfoProto.HeroRandRequest heroRandRequest = HeroInfoProto.HeroRandRequest.parseFrom(bytes);
int type = heroRandRequest.getType();
HeroLogic.getInstance().random(iSession,type);
}
}

View File

@ -1,24 +1,13 @@
package com.ljsd.jieling.handler.map;
import com.google.common.collect.Sets;
import java.util.Set;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Cell {
private Set<Integer> eventIds = Sets.newConcurrentHashSet();;
private Map<Integer, Integer> eventIds = new ConcurrentHashMap();
private boolean isFinish;
public Set<Integer> getEventIds() {
public Map<Integer, Integer> getEventIds() {
return eventIds;
}
public boolean isFinish() {
return isFinish;
}
public void setFinish(boolean finish) {
isFinish = finish;
}
}

View File

@ -1,14 +1,40 @@
package com.ljsd.jieling.handler.map;
public class EventType {
// 事件点类型 1怪物 2怪物群 3矿 4入口 5出口 6一次性事件 7重复事件 8npc 9地图boss
/**
*
* 1 2 3 4 5 6 7 8
*/
public static final int enter = 0;
public static final int monster = 1;
public static final int monsters = 2;
public static final int mine = 3;
public static final int enter = 4;
public static final int exit = 5;
public static final int disposable = 6;
public static final int repeated = 7;
public static final int npc = 8;
public static final int boss = 8;
public static final int mine = 2;
public static final int portal = 3;
public static final int continuity = 4;
public static final int businessman = 5;
public static final int box = 6;
public static final int hinder = 7;
public static final int allEvents = 8;
/**
*
* 1
* 2id#0-11#num
* 3
* 5
* 6
* 7
* 8
* 9buff
* 10
*/
public static final int fight = 1;
public static final int attribute = 2;
public static final int useItem = 3;
// public static final int scout = 4;
public static final int scout = 5;
public static final int leave = 6;
public static final int dialogue = 7;
public static final int jump = 8;
public static final int eatBuff = 9;
// public static final int obstacle = 10;
}

View File

@ -1,21 +0,0 @@
package com.ljsd.jieling.handler.map;
public class LittleEventType {
/**
* 1
* 2 id#0-11#num
* 3
* 4
* 5
* 6
* 7
*/
public static final int fight = 1;
public static final int attribute = 2;
public static final int item = 3;
public static final int reward = 4;
public static final int scout = 5;
public static final int leave = 6;
public static final int choice = 7;
}

View File

@ -1,30 +0,0 @@
package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
import org.springframework.stereotype.Component;
@Component
public class MapGetInfoRequestHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.MAP_GET_INFO_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
MapInfoProto.MapGetInfoResponse mapGetInfoResponse = MapInfoProto.MapGetInfoResponse
.newBuilder()
.setMapId(user.getMapManager().getCurMapId())
.build();
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.MAP_GET_INFO_RESPONSE_VALUE, mapGetInfoResponse, true);
}
}

View File

@ -1,28 +1,30 @@
package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.config.SCMap;
import com.ljsd.jieling.config.SCMapEventsConfig;
import com.ljsd.jieling.config.SCMapEventsItemConfig;
import com.ljsd.jieling.logic.dao.MapManager;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CellUtil;
import com.ljsd.jieling.util.MessageUtil;
import com.ljsd.jieling.config.SCMap;
import com.ljsd.jieling.config.SCMapEvent;
import com.ljsd.jieling.util.ToolsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
public class MapLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class);
private MapLogic(){}
private MapLogic() {
}
/**
*
*
@ -38,86 +40,216 @@ public class MapLogic {
/**
*
*
* @param mapId
*/
public void enterMap(ISession iSession, int mapId, MessageTypeProto.MessageType messageType) throws Exception {
public void enterMap(ISession iSession, int mapId, MessageTypeProto.MessageType messageType) throws Exception {
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
MapManager mapManager = user.getMapManager();
if (mapManager.getCurMapId() == 0) {
mapManager = initMap( 1);
user.getPlayerInfoManager().setMapId(101);
mapManager.setCurMapId(101);
initMap(mapManager);
user.setMapManager(mapManager);
} else {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
if (scMap == null) {
return;
}
if (mapId > mapManager.getCurMapId()) {
return;
}
if (mapId != mapManager.getCurMapId()) {
initMap(mapManager);
user.setMapManager(mapManager);
}
}
MapInfoProto.MapEnterResponse mapEnterResponse = MapInfoProto.MapEnterResponse
List<CommonProto.Cell> cells = new ArrayList<>(mapManager.getMapInfo().size());
for (Map.Entry<Integer, Cell> entry : mapManager.getMapInfo().entrySet()) {
List<CommonProto.CellEvent> cellEvents = new ArrayList<>();
Cell cell = entry.getValue();
for (Map.Entry<Integer, Integer> cellEntry : cell.getEventIds().entrySet()) {
CommonProto.CellEvent cellEvent = CommonProto.CellEvent
.newBuilder()
.setEventId(cellEntry.getKey())
.setState(cellEntry.getValue())
.build();
cellEvents.add(cellEvent);
}
CommonProto.Cell cellProto = CommonProto.Cell
.newBuilder()
.setCellId(entry.getKey())
.addAllCellEvents(cellEvents)
.build();
cells.add(cellProto);
}
MapInfoProto.MapEnterResponse mapEnterResponse = MapInfoProto.MapEnterResponse
.newBuilder()
.addAllMapList(cells)
.setCurXY(mapManager.getCurXY())
.build();
MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), mapEnterResponse, true);
}
private MapManager initMap(int mapId) throws Exception {
if (mapId == 0) {
mapId = 1;
}
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
if (scMap == null) {
return null;
}
MapManager mapManager = new MapManager();
mapManager.setCurMapId(mapId);
Map<Integer, Cell> mapInfo = mapManager.getMapInfo();
mapInfo.clear();
private void initMap(MapManager mapManager) throws Exception {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapManager.getCurMapId());
Map<Integer, Cell> newMap = new HashMap<>();
Map<Integer, Cell> spicelMap = new HashMap<>();
Random random = new Random();
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue();
Cell cellValue = new Cell();
cellValue.getEventIds().add(scMap1.getEvent());
cellValue.getEventIds().put(scMap1.getEvent(), 0);
int randomIndex = random.nextInt(scMap1.getGroups().length);
int x = scMap1.getGroups()[randomIndex][0];
int y = scMap1.getGroups()[randomIndex][1];
int xy = ToolsUtil.xy2Pos(x, y);
SCMapEvent scMapEvent = SCMapEvent.scMapEventMap.get(scMap1.getEvent());
int xy = CellUtil.xy2Pos(x, y);
SCMapEventsConfig scMapEvent = SCMapEventsConfig.scMapEventMap.get(scMap1.getEvent());
if (scMapEvent.getStyle() == EventType.enter) {
mapManager.setCurXY(xy);
}
mapInfo.put(xy, cellValue);
if (scMapEvent.getStyle() == EventType.allEvents) {
spicelMap.put(xy, cellValue);
} else {
newMap.put(xy, cellValue);
}
}
return mapManager;
mapManager.setMapInfo(newMap);
mapManager.setTypeEight(spicelMap);
}
/**
*
*/
public void fightStart(ISession session, int bigEventId){
}
/**
*
*/
public void fightEnd(ISession session, int bigEventId){
}
/**
* 使buff
*/
public void useItem(ISession session, int bigEventId){
}
/**
*
*/
public void leave(ISession session, int bigEventId){
}
/**
*
* @param uid
*
*
* @param session
* @param xy
*/
public void finishEvent(int uid, int xy) throws Exception {
// get db
MapManager cMap = null;
Cell cell = cMap.getMapInfo().get(xy);
public void updateEvent(ISession session, int xy, int bigEventId, int choice, List<Integer> cells) throws Exception {
Set<Integer> cellSet = new HashSet<>(cells);
if (cells.size() != cellSet.size()) {
LOGGER.info("cells has repeated");
return;
}
int uid = session.getUid();
User user = UserManager.getUser(uid);
MapManager mapManager = user.getMapManager();
Cell cell = mapManager.getMapInfo().get(xy);
if (cell == null) {
LOGGER.info("xy is wrong =>{}", xy);
return;
}
if (cell.getEventIds().isEmpty()) {
LOGGER.info("no event eventId");
return;
}
cMap.setCurXY(xy);
cell.setFinish(true);
SCMapEvent scMapEvent = SCMapEvent.scMapEventMap.get(cell.getEventIds());
// 如果是出口开启跳转到下个关卡
if (scMapEvent.getStyle() == EventType.disposable) {
Map<Integer, List<Integer>> crossMapInfos = cMap.getCrossMapInfos();
if (!crossMapInfos.containsKey(cMap.getCurMapId())) {
crossMapInfos.put(cMap.getCurMapId(), new ArrayList<>());
mapManager.setCurXY(xy);
Map<Integer, Integer> eventIds = cell.getEventIds();
if (!eventIds.containsKey(bigEventId)) {
LOGGER.info("no this event eventId=>{}", bigEventId);
return;
}
int schedule = eventIds.get(bigEventId);
if (schedule == -1) {
LOGGER.info("event is finished,bigEventId=>{} smallEventId=>{}", bigEventId, -1);
return;
}
SCMapEventsConfig scMapEvent = SCMapEventsConfig.scMapEventMap.get(bigEventId);
SCMapEventsItemConfig scMapEventsItemConfig = SCMapEventsItemConfig.scMapEventsItemConfigs.get(bigEventId).get(schedule);
if (scMapEventsItemConfig == null) {
LOGGER.info("no scMapEventsItemConfig bigEventId=>{} smallEventId=>{}", bigEventId, schedule);
return;
}
String[] contents = scMapEventsItemConfig.getContents().split("\\|");
if (choice < contents.length - 1 || contents.length - 1 < choice) {
LOGGER.info("no this choice =>{} scMapEventsItemConfig.getContents()=>{}", choice, scMapEventsItemConfig.getContents());
return;
}
String[] eventArr = contents[choice].split("#");
switch (Integer.parseInt(eventArr[0])) {
case EventType.fight: {
fightStart(session, bigEventId);
break;
}
case EventType.attribute: {
break;
}
case EventType.useItem:
case EventType.scout: {
break;
}
case EventType.leave: {
break;
}
case EventType.dialogue: {
break;
}
case EventType.jump: {
break;
}
case EventType.eatBuff: {
break;
}
default: {
return;
}
crossMapInfos.get(cMap.getCurMapId()).addAll(cell.getEventIds());
}
if (scMapEvent.getStyle() == EventType.exit) {
initMap(cMap.getCurMapId() + 1);
if (schedule + 1 >= contents.length - 1) {
cell.getEventIds().put(bigEventId, -1);
} else {
cell.getEventIds().put(bigEventId, schedule + 1);
}
// 如果是传送门开启跳转到下个关卡
// if (scMapEvent.getStyle() == EventType.exit) {
// Map<Integer, List<Integer>> crossMapInfos = cMap.getCrossMapInfos();
// if (!crossMapInfos.containsKey(cMap.getCurMapId())) {
// crossMapInfos.put(cMap.getCurMapId(), new ArrayList<>());
// }
// crossMapInfos.get(cMap.getCurMapId()).addAll(cell.getEventIds());
// }
if (scMapEvent.getStyle() == EventType.portal) {
user.getPlayerInfoManager().setMapId(user.getPlayerInfoManager().getMapId() + 1);
return;
}
cell.setFinish(true);
// save db
}
}

View File

@ -0,0 +1,20 @@
package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
//@Component
public class MapUpdateEventRequestHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return null;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
}
}

View File

@ -159,7 +159,7 @@ public class STableManager {
lineNum++;
}
map.put(i, mapConf);
tableName = tableName.substring(0, 5);
tableName = tableName.substring(0, 3);
}
return map;
}

View File

@ -0,0 +1,13 @@
package com.ljsd.jieling.logic.dao;
import java.util.Map;
import java.util.Set;
public class CardRandomManager {
private Set<Integer> heroIids;
private Map<Integer,Integer> totalConuntByType;
}

View File

@ -1,8 +1,10 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.config.SCHero;
import com.ljsd.jieling.protocols.CommonProto;
import java.util.ArrayList;
import java.util.List;
public class Hero extends MongoBase {
@ -10,28 +12,44 @@ public class Hero extends MongoBase {
private int templateId; //模板ID
private int heroType;
private int level;//等级
private int star;
private int quality;
private int hp;
private float hp;
private int attack;
private float attack;
private int pDefence;
private float pDefence;
private int mDefence;
private float mDefence;
private int speed;
private float speed;
private List<Skill> skillList;
private List<Equip> equipList;
public Hero(){}
public Hero(String uid,int heroTid){
this.id = uid + "" + heroTid;
SCHero scHero = SCHero.getsCHero().get(heroTid);
this.templateId = scHero.getId();
this.level = 1;
this.star = 1;
this.hp = scHero.getHp();
this.attack = scHero.getAttack();
this.pDefence = scHero.getPhysicalDefence();
this.mDefence = scHero.getMagicDefence();
this.speed = scHero.getSpeed();
this.skillList = new ArrayList<>();
this.equipList = new ArrayList<>();
}
public void setId(String id) {
this.id = id;
}
@ -41,10 +59,6 @@ public class Hero extends MongoBase {
this.templateId = templateId;
}
public void setHeroType(int heroType) throws Exception {
updateString("heroType",heroType);
this.heroType = heroType;
}
public void setLevel(int level) throws Exception {
updateString("level",level);
@ -56,32 +70,27 @@ public class Hero extends MongoBase {
this.star = star;
}
public void setQuality(int quality) throws Exception {
updateString("quality",quality);
this.quality = quality;
}
public void setHp(int hp) throws Exception {
public void setHp(float hp) throws Exception {
updateString("hp",hp);
this.hp = hp;
}
public void setAttack(int attack) throws Exception {
public void setAttack(float attack) throws Exception {
updateString("attack",attack);
this.attack = attack;
}
public void setpDefence(int pDefence) throws Exception {
public void setpDefence(float pDefence) throws Exception {
updateString("pDefence",pDefence);
this.pDefence = pDefence;
}
public void setmDefence(int mDefence) throws Exception {
public void setmDefence(float mDefence) throws Exception {
updateString("mDefence",mDefence);
this.mDefence = mDefence;
}
public void setSpeed(int speed) throws Exception {
public void setSpeed(float speed) throws Exception {
updateString("speed",speed);
this.speed = speed;
}
@ -94,10 +103,6 @@ public class Hero extends MongoBase {
return templateId;
}
public int getHeroType() {
return heroType;
}
public int getLevel() {
return level;
}
@ -106,43 +111,40 @@ public class Hero extends MongoBase {
return star;
}
public int getQuality() {
return quality;
}
public int getHp() {
public float getHp() {
return hp;
}
public int getAttack() {
public float getAttack() {
return attack;
}
public int getpDefence() {
public float getpDefence() {
return pDefence;
}
public int getmDefence() {
public float getmDefence() {
return mDefence;
}
public int getSpeed() {
public float getSpeed() {
return speed;
}
public List<Skill> getSkillList() {
return skillList;
}
public void setSkillList(List<Skill> skillList) {
this.skillList = skillList;
}
public List<Equip> getEquipList() {
return equipList;
}
public void setEquipList(List<Equip> equipList) {
this.equipList = equipList;
}
public List<Skill> getSkillList() {
return skillList;
}
public List<Equip> getEquipList() {
return equipList;
}
}

View File

@ -35,4 +35,7 @@ public class HeroManager extends MongoBase {
heroMap.remove(heroId);
}
public Map<String, Hero> getHeroMap() {
return heroMap;
}
}

View File

@ -18,6 +18,8 @@ public class MapManager extends MongoBase {
private Map<Integer, Cell> mapInfo = new ConcurrentHashMap<>();
private Map<Integer, Cell> typeEight = new ConcurrentHashMap<>();
private Map<Integer, List<Integer>> crossMapInfos = new ConcurrentHashMap<>();
public Map<Integer, Cell> getMapInfo() {
@ -33,7 +35,7 @@ public class MapManager extends MongoBase {
}
public void setCurMapId(int curMapId) throws Exception {
updateString("curMapId", curXY);
updateString("curMapId", curMapId);
this.curMapId = curMapId;
}
@ -47,13 +49,26 @@ public class MapManager extends MongoBase {
}
public void addOrUpdateCell(int key, Cell cell) throws Exception {
updateString(getMongoKey() + ".mapInfo." + key, mapInfo);
updateString( "mapInfo." + key, cell);
this.mapInfo.put(key, cell);
}
public void removeCell(int key) {
removeString(getMongoKey() + ".mapInfo." + key);
this.mapInfo.remove(key);
public void setMapInfo(Map<Integer, Cell> mapInfo) throws Exception {
updateString( "mapInfo", mapInfo);
this.mapInfo = mapInfo;
}
public void removeAllCell() {
removeString("mapInfo");
this.mapInfo.clear();
}
public Map<Integer, Cell> getTypeEight() {
return typeEight;
}
public void setTypeEight(Map<Integer, Cell> typeEight) throws Exception {
updateString( "typeEight", typeEight);
this.typeEight = typeEight;
}
}

View File

@ -25,6 +25,8 @@ public class PlayerManager extends MongoBase {
private int chargeGem;
private int mapId;
public String getOpenId() {
return openId;
@ -114,4 +116,13 @@ public class PlayerManager extends MongoBase {
updateString("chargeGem", chargeGem);
this.chargeGem = chargeGem;
}
public int getMapId() {
return mapId;
}
public void setMapId(int mapId) throws Exception {
updateString("mapId", mapId);
this.mapId = mapId;
}
}

View File

@ -0,0 +1,45 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TeamPosManager extends MongoBase {
private Map<Integer, List<String>> teamPosForHero;
private Map<Integer,String> teamNames;
private Map<Integer,List<Integer>> teamPosForPoken;
public TeamPosManager(){
teamNames = new HashMap<>(3);
teamPosForHero = new HashMap<>(3);
teamPosForPoken = new HashMap<>(3);
}
public void changeName(int teamId,String teamName) throws Exception {
teamNames.put(teamId,teamName);
updateString("teamNames",teamNames);
}
public void changeTeamInfo(int teamId,List<String> heroIds,List<Integer> pokenIds) throws Exception {
teamPosForHero.put(teamId,heroIds);
teamPosForPoken.put(teamId,pokenIds);
updateString("teamPosForHero",teamPosForHero);
updateString("teamPosForPoken",teamPosForPoken);
}
public Map<Integer, List<String>> getTeamPosForHero() {
return teamPosForHero;
}
public Map<Integer, String> getTeamNames() {
return teamNames;
}
public Map<Integer, List<Integer>> getTeamPosForPoken() {
return teamPosForPoken;
}
}

View File

@ -15,6 +15,10 @@ public class User extends MongoRoot {
private MapManager mapManager;
private TeamPosManager teamPosManager;
public User(int uid, PlayerManager playerManager, ItemManager itemManager,
HeroManager heroManager, MapManager mapManager){
setMyMongoDBPool(_myMongoDBPool);
@ -23,11 +27,14 @@ public class User extends MongoRoot {
this.itemManager = itemManager;
this.heroManager = heroManager;
this.mapManager = mapManager;
this.teamPosManager = new TeamPosManager();
//綁定关系
playerManager.init(this, "playerManager", false);
itemManager.init(this, "itemManager", false);
heroManager.init(this, "heroManager", false);
mapManager.init(this, "mapManager", false);
teamPosManager.init(this,"teamPosManager",false);
}
public User(){
@ -87,4 +94,12 @@ public class User extends MongoRoot {
public void setMapManager(MapManager mapManager) {
this.mapManager = mapManager;
}
public TeamPosManager getTeamPosManager() {
return teamPosManager;
}
public void setTeamPosManager(TeamPosManager teamPosManager) {
this.teamPosManager = teamPosManager;
}
}

View File

@ -0,0 +1,198 @@
package com.ljsd.jieling.logic.hero;
import com.ljsd.GameApplication;
import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.config.SLotteryRewardConfig;
import com.ljsd.jieling.config.SLotterySetting;
import com.ljsd.jieling.config.ServerConfig;
import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.MessageUtil;
import org.apache.commons.lang.math.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class HeroLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(HeroLogic.class);
private HeroLogic(){}
public static class Instance {
public final static HeroLogic instance = new HeroLogic();
}
public static HeroLogic getInstance() {
return HeroLogic.Instance.instance;
}
public void random(ISession session,int type) throws Exception {
int uid = session.getUid();
SLotterySetting sLotterySetting = SLotterySetting.getsLotterySettingMap().get(type);
//检验消耗
//筛选卡池
StringBuilder reward = new StringBuilder();
int pooId =0;
int perCount = sLotterySetting.getPerCount();
boolean isSpecial = false;
if(sLotterySetting.getOrderBoxPool()!=null && sLotterySetting.getOrderBoxPool().length>0){
pooId = getOrderBoxPoolId(sLotterySetting);
isSpecial = true;
}
for(int i=0;i<perCount;i++){
if(!isSpecial){
pooId = getPooId(sLotterySetting, pooId);
}
LOGGER.info("the uid={},the type={},the poolId={}",uid,type,pooId);
reward.append(randomHeroByPoolId(pooId)).append("|");
}
//额外获取
reward.append( extraReward(sLotterySetting));
User user = UserManager.getUser(uid);
HeroInfoProto.HeroRandResponse heroRandResponse = addItem(user, reward.toString());
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.HERO_RAND_RESPONSE_VALUE, heroRandResponse, true);
}
private int getPooId(SLotterySetting sLotterySetting, int pooId) throws Exception {
int[][] diamondBoxContain = sLotterySetting.getDiamondBoxContain();
int totalWeight = 0;
for(int i=0;i<diamondBoxContain.length;i++){
int[] poolWeightInfo = diamondBoxContain[i];
totalWeight += poolWeightInfo[1];
}
int randWeight = RandomUtils.nextInt(totalWeight) + 1;
int weight = 0;
for(int i=0;i<diamondBoxContain.length;i++){
int[] poolWeightInfo = diamondBoxContain[i];
weight += poolWeightInfo[1];
if(randWeight<weight){
pooId = poolWeightInfo[0];
break;
}
}
return pooId;
}
public HeroInfoProto.HeroRandResponse addItem(User user, String rewards) throws Exception {
HeroInfoProto.HeroRandResponse.Builder builder = HeroInfoProto.HeroRandResponse.newBuilder();
List<CommonProto.Hero> heros = new ArrayList<>();
List<CommonProto.Item> items = new ArrayList<>();
ItemManager itemManager = user.getItemManager();
HeroManager heroManager = user.getHeroManager();
String[] rewardItems = rewards.split("\\|");
for(String heroOrItem : rewardItems){
String[] splitReward = heroOrItem.split("#");
int itemId = Integer.parseInt(splitReward[0]);
int itemNum = Integer.parseInt(splitReward[1]);
SItem sItem = SItem.getsItemMap().get(itemId);
int itemType = sItem.getItemType();
if(itemType == 1){ //hero
Hero hero = new Hero(user.getId(), itemId);
heroManager.addHero(hero);
CommonProto.Hero hero1 = CBean2Proto.getHero(hero);
heros.add(hero1);
}
if( itemType == 2) {
Item item = itemManager.getItem(itemId);
if (item == null){
item = itemManager.newItem(itemId, itemNum);
}else{
if(sItem.isStacking()){
item.setItemNum(item.getItemNum() + itemNum);
}
}
items.add(CBean2Proto.getItem(item));
}
}
builder.addAllHeroList(heros);
builder.addAllItemList(items);
//todo 为了测试 日后要删掉
UserManager.ljsdMongoTemplate.lastUpdate();
return builder.build();
}
public int getOrderBoxPoolId(SLotterySetting sLotterySetting) throws Exception {
int[] orderBoxPool = sLotterySetting.getOrderBoxPool();
int orderBoxOpenTime = sLotterySetting.getOrderBoxOpenTime();
int orderBoxContinue = sLotterySetting.getOrderBoxContinue();
long now = System.currentTimeMillis();
ServerConfig serverConfig = GameApplication.serverConfig;
int diffHours = (int)((now - serverConfig.getCacheOpenTime())%( (orderBoxContinue + orderBoxContinue) * 1000*60*60));
int diffSeaseon = (int)((now - serverConfig.getCacheOpenTime())/( (orderBoxContinue + orderBoxContinue) * 1000*60*60));
if(diffHours<=orderBoxOpenTime){
return orderBoxPool[diffSeaseon%orderBoxPool.length];
}
return 0;
}
public String randomHeroByPoolId(int poolId){
List<SLotteryRewardConfig> sLotteryRewardConfigListByPoolId = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId);
int totalCountByPoolId = SLotteryRewardConfig.getTotalCountByPoolId(poolId);
int randCount = RandomUtils.nextInt(totalCountByPoolId) + 1;
int weight =0;
for(SLotteryRewardConfig sLotteryRewardConfig :sLotteryRewardConfigListByPoolId){
weight += sLotteryRewardConfig.getWeight();
if(weight>randCount){
int[] reward = sLotteryRewardConfig.getReward();
return reward[0] + "#" + reward[1];
}
}
return null;
}
public String extraReward(SLotterySetting sLotterySetting){
if(sLotterySetting.getTenTimesMustGetItem()!=null){
int[] tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem();
return tenTimesMustGetItem[0] + "#" + tenTimesMustGetItem[1];
// tenTimesMustGetItem
}
return "";
}
public void saveTeamPos(int uid,int teamId,List<String> heroIds ,List<Integer> pokenIds) throws Exception {
User user = UserManager.getUser(uid);
user.getTeamPosManager().changeTeamInfo(teamId,heroIds,pokenIds);
}
public boolean checkTeamPos(User user,int teamId,List<String> heroIds){
if(heroIds ==null || heroIds.isEmpty()){
return false;
}
Set<String> cacheHeroIds = new HashSet<>();
Collection<List<String>> values = user.getTeamPosManager().getTeamPosForHero().values();
for(String heroId : heroIds){
if(user.getHeroManager().getHero(heroId) == null) {
// 卡牌不存在
return false;
}
// 卡牌重复
if(cacheHeroIds.contains(heroId)){
return false;
}
// 卡牌已上阵
if(values.contains(heroId)){
return false;
}
cacheHeroIds.add(heroId);
}
return true;
}
}

View File

@ -217,6 +217,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
return;
} else {
try {
LOGGER.info("request uid=>{} commond=>{} msgId=>{}: ", packetNetData.getUserId(), baseHandler.getMessageCode(), packetNetData.getMsgId());
baseHandler.execute(session, packetNetData);
} catch (Exception e) {
//TODO

View File

@ -41,17 +41,15 @@ public class CBean2Proto {
.newBuilder()
.setId(hero.getId())
.setHeroId(hero.getTemplateId())
.setHeroType(hero.getHeroType())
.setLevel(hero.getLevel())
.setStar(hero.getStar())
.setQuality(1)
.setHp(hero.getHp())
.setAttack(hero.getAttack())
.setPDefence(hero.getpDefence())
.setMDefence(hero.getmDefence())
.setSpeed(hero.getSpeed())
.setHp((int)hero.getHp())
.setAttack((int)hero.getAttack())
.setPDefence((int)hero.getpDefence())
.setMDefence((int)hero.getmDefence())
.setSpeed((int)hero.getSpeed())
.addAllSkillList(getHeroSkill(hero.getSkillList()))
.addAllEquipList(getHeroEquip(hero.getEquipList()))
.addAllEquipIdList(getHeroEquip(hero.getEquipList()))
.build();
return heroProto;
}
@ -63,18 +61,15 @@ public class CBean2Proto {
CommonProto.Skill skill1 = CommonProto.Skill
.newBuilder()
.setSkillId(skill.getSkillId())
.setSkillType(skill.getSkillType())
.setLevel(skill.getLevel())
.setStar(skill.getStar())
.addAllEffectId(skill.getEffectIdList())
.build();
skills.add(skill1);
}
return skills;
}
private static List<CommonProto.Equip> getHeroEquip(List<Equip> equipList) {
List<CommonProto.Equip> equips = new ArrayList<>();
private static List<String> getHeroEquip(List<Equip> equipList) {
List<String> equips = new ArrayList<>();
return equips;
}

View File

@ -0,0 +1,92 @@
package com.ljsd.jieling.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CellUtil {
public static int xy2Pos(int x, int y) {
if (x < 0 || y < 0){
return 0;
}
return (x << 8) | y;
}
public static int[] pos2XY(int pos) {
int[] xy = new int[2];
xy[0] = (pos >> 8) & 0xff;
xy[1] = pos & 0xff;
return xy;
}
public static void main(String[] args) {
int xx = 19;
int yy = 14;
int pos = xy2Pos(xx,yy);
System.out.println("======> pos : "+pos);
int[] xy = pos2XY(pos);
System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
System.out.println("=====================================");
Set<Integer> cells = getOneOpenCell(21,18, pos);
for(Integer i : cells){
int[] new_xy = pos2XY(i);
System.out.println("=======> nX : "+new_xy[0]+" , nY : "+new_xy[1]);
}
}
public static Set<Integer> getOneOpenCell(int width, int height, int pos){
int[] xy = pos2XY(pos);
int x = xy[0];
int y = xy[1];
Set<Integer> openCells = new HashSet<>();
for (int i = -2; i <= 2; i++) {
if (0 <= x+i && x+i < width && i!=0){
openCells.add(xy2Pos(x+i,y));
// System.out.println("=======> nX : "+(x+i)+" , nY : "+y);
}
if (0 <= y+i && y+i < height && i!=0){
openCells.add(xy2Pos(x,y+i));
// System.out.println("=======> nX : "+x+" , nY : "+(y+i));
}
}
if (x+1 < width && y+1 < height){
openCells.add(xy2Pos(x+1,y+1));
// System.out.println("===============> nX : "+(x+1)+" , nY : "+(y+1));
}
if (x+1 < width && y-1 >= 0){
openCells.add(xy2Pos(x+1,y-1));
// System.out.println("===============> nX : "+(x+1)+" , nY : "+(y-1));
}
if (x-1 >= 0 && y+1 < height){
openCells.add(xy2Pos(x-1,y+1));
// System.out.println("===============> nX : "+(x-1)+" , nY : "+(y+1));
}
if (x-1 >= 0 && y-1 >= 0){
openCells.add(xy2Pos(x-1,y-1));
// System.out.println("===============> nX : "+(x-1)+" , nY : "+(y-1));
}
System.out.println("=====================================");
return openCells;
}
/**
* -
* @param s1
* @param s2
* @return
*/
public static Set<Integer> union(Set<Integer> s1 , Set<Integer> s2){
for(Integer s : s2){
if(!s1.contains(s))
s1.add(s);
}
return s1 ;
}
}

View File

@ -46,6 +46,7 @@ public class MessageUtil {
public static void sendMessage(ISession session, int result, int msgId, GeneratedMessage generatedMessage, boolean flush) throws Exception {
byte[] byteBuf = wrappedBuffer(session.getUid(), session.getToken(), session.getIndex(), result, msgId, generatedMessage);
UserManager.ljsdMongoTemplate.lastUpdate();
System.out.println("-----> msgId : "+ msgId+"; length : "+byteBuf.length+"; content : "+byteBuf);
if (flush) {
session.writeAndFlush(byteBuf);
} else {

View File

@ -3,26 +3,6 @@ package com.ljsd.jieling.util;
public class ToolsUtil {
public static int xy2Pos(int x, int y) {
return (x << 8) | y;
}
public static int[] pos2XY(int pos) {
int[] xy = new int[2];
xy[0] = (pos >> 8) & 0xff;
xy[1] = pos & 0xff;
return xy;
}
public static void main(String[] args) {
int xx = 12;
int yy = 5;
int pos = xy2Pos(xx,yy);
System.out.println("======> pos : "+pos);
int[] xy = pos2XY(pos);
System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
}
}

View File

@ -18,7 +18,7 @@ public class NettyClient {
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClient.class);
private static int uid = 10000001;
private static int uid = 10000009;
private static int msgIndex = 1;
private static int token=543242;
@ -43,12 +43,17 @@ public class NettyClient {
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE));
handler.sendRequest_jieling(makeFinalMessage(getHero(), MessageTypeProto.MessageType.GET_HEROINFO_REQUEST_VALUE));
handler.sendRequest_jieling(makeFinalMessage(getRandomHero(), MessageTypeProto.MessageType.HERO_RAND_REQQUEST_VALUE));
}
public static HeroInfoProto.GetHeroListInfoRequest getHero(){
return HeroInfoProto.GetHeroListInfoRequest.newBuilder().setNum(1).setStr("111").build();
}
public static HeroInfoProto.HeroRandRequest getRandomHero(){
return HeroInfoProto.HeroRandRequest.newBuilder().setType(11).build();
}
private static byte[] makeFinalMessage(MessageLite request, int msgNum) {
byte[] messageData = request.toByteArray();