# Conflicts:
#	serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java
back_recharge
jiahuiwen 2019-01-22 09:51:12 +08:00
commit c658c1f5a0
32 changed files with 1264 additions and 176 deletions

View File

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

View File

@ -0,0 +1,10 @@
Id Name Position Include
int string mut,float#float,1 mut,float#float,1
1 北部 null 101#102
2 西部 null 103#104
3 0.0 null null
4 0.0 null null
5 0.0 null null
6 0.0 null null
7 0.0 null null
8 0.0 null null

View File

@ -0,0 +1,2 @@
Id BornItem
int mut,int#int,2

View File

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

View File

@ -0,0 +1,43 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name ="ArenaConfig")
public class SArenaConfig implements BaseConfig {
private int id;
private String name;
private float[] position;
private float[] include;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public float[] getPosition() {
return position;
}
public float[] getInclude() {
return include;
}
}

View File

@ -22,6 +22,8 @@ public class SCHero implements BaseConfig{
private int maxRank; //角色最高星级 private int maxRank; //角色最高星级
private int star;
private float hp; private float hp;
private float attack; //攻击力 private float attack; //攻击力
@ -39,7 +41,7 @@ public class SCHero implements BaseConfig{
@Override @Override
public void init() throws Exception { public void init() throws Exception {
// sCHero = STableManager.getConfig(SCHero.class); sCHero = STableManager.getConfig(SCHero.class);
} }

View File

@ -0,0 +1,41 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name = "drop")
public class SDrop implements BaseConfig {
public static Map<Integer, SDrop> sDropMap;
private int id;
private int dropType; // 掉落type
private int[][] item;
private int[] weight;
@Override
public void init() throws Exception {
sDropMap = STableManager.getConfig(SDrop.class);
}
public int getId() {
return id;
}
public int[][] getItem() {
return item;
}
public static Map<Integer, SDrop> getsDropMap() {
return sDropMap;
}
public int getDropType() {
return dropType;
}
public int[] getWeight() {
return weight;
}
}

View File

@ -0,0 +1,31 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name ="GameSetting")
public class SGameSetting implements BaseConfig {
private int id;
private int[][] bornItem;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int[][] getBornItem() {
return bornItem;
}
}

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

@ -0,0 +1,11 @@
package com.ljsd.jieling.globals;
public interface GlobalItemType {
//掉落物品类型
int ALL_DROP = 0; //全部掉落
int WEIGHT_DROP = 1; //随机掉落
// 物品类型
int ITEM = 10; //道具类型
}

View File

@ -8,6 +8,7 @@ import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager; import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.netty.cocdex.PacketNetData; import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.GMCommandProto; import com.ljsd.jieling.protocols.GMCommandProto;
import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.ItemUtil; import com.ljsd.jieling.util.ItemUtil;
@ -49,8 +50,9 @@ public class GMRequestHandler extends BaseHandler{
} }
private void giveItem(User cUser,int itemId,int itemNum) throws Exception { private void giveItem(User cUser,int itemId,int itemNum) throws Exception {
CommonProto.Drop.Builder dropBuilder = CommonProto.Drop.newBuilder();
Map<Integer,Integer> itemMap = new ConcurrentHashMap<>(); Map<Integer,Integer> itemMap = new ConcurrentHashMap<>();
itemMap.put(itemId,itemNum); itemMap.put(itemId,itemNum);
ItemUtil.addItem(cUser,itemMap); ItemUtil.addItem(cUser,itemMap,dropBuilder);
} }
} }

View File

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

@ -12,9 +12,9 @@ import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto; import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto; import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CellUtil;
import com.ljsd.jieling.util.ItemUtil; import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.MessageUtil; import com.ljsd.jieling.util.MessageUtil;
import com.ljsd.jieling.util.ToolsUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -107,7 +107,7 @@ public class MapLogic {
int randomIndex = random.nextInt(scMap1.getGroups().length); int randomIndex = random.nextInt(scMap1.getGroups().length);
int x = scMap1.getGroups()[randomIndex][0]; int x = scMap1.getGroups()[randomIndex][0];
int y = scMap1.getGroups()[randomIndex][1]; int y = scMap1.getGroups()[randomIndex][1];
int xy = ToolsUtil.xy2Pos(x, y); int xy = CellUtil.xy2Pos(x, y);
SCMapEventsConfig scMapEvent = SCMapEventsConfig.scMapEventMap.get(scMap1.getEvent()); SCMapEventsConfig scMapEvent = SCMapEventsConfig.scMapEventMap.get(scMap1.getEvent());
if (scMapEvent.getStyle() == EventType.enter) { if (scMapEvent.getStyle() == EventType.enter) {
mapManager.setCurXY(xy); mapManager.setCurXY(xy);

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

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 MapManager mapManager;
private TeamPosManager teamPosManager;
public User(int uid, PlayerManager playerManager, ItemManager itemManager, public User(int uid, PlayerManager playerManager, ItemManager itemManager,
HeroManager heroManager, MapManager mapManager){ HeroManager heroManager, MapManager mapManager){
setMyMongoDBPool(_myMongoDBPool); setMyMongoDBPool(_myMongoDBPool);
@ -23,11 +27,14 @@ public class User extends MongoRoot {
this.itemManager = itemManager; this.itemManager = itemManager;
this.heroManager = heroManager; this.heroManager = heroManager;
this.mapManager = mapManager; this.mapManager = mapManager;
this.teamPosManager = new TeamPosManager();
//綁定关系 //綁定关系
playerManager.init(this, "playerManager", false); playerManager.init(this, "playerManager", false);
itemManager.init(this, "itemManager", false); itemManager.init(this, "itemManager", false);
heroManager.init(this, "heroManager", false); heroManager.init(this, "heroManager", false);
mapManager.init(this, "mapManager", false); mapManager.init(this, "mapManager", false);
teamPosManager.init(this,"teamPosManager",false);
} }
public User(){ public User(){
@ -87,4 +94,12 @@ public class User extends MongoRoot {
public void setMapManager(MapManager mapManager) { public void setMapManager(MapManager mapManager) {
this.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

@ -43,11 +43,11 @@ public class CBean2Proto {
.setHeroId(hero.getTemplateId()) .setHeroId(hero.getTemplateId())
.setLevel(hero.getLevel()) .setLevel(hero.getLevel())
.setStar(hero.getStar()) .setStar(hero.getStar())
.setHp(hero.getHp()) .setHp((int)hero.getHp())
.setAttack(hero.getAttack()) .setAttack((int)hero.getAttack())
.setPDefence(hero.getpDefence()) .setPDefence((int)hero.getpDefence())
.setMDefence(hero.getmDefence()) .setMDefence((int)hero.getmDefence())
.setSpeed(hero.getSpeed()) .setSpeed((int)hero.getSpeed())
.addAllSkillList(getHeroSkill(hero.getSkillList())) .addAllSkillList(getHeroSkill(hero.getSkillList()))
.addAllEquipIdList(getHeroEquip(hero.getEquipList())) .addAllEquipIdList(getHeroEquip(hero.getEquipList()))
.build(); .build();

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

@ -1,6 +1,8 @@
package com.ljsd.jieling.util; package com.ljsd.jieling.util;
import com.ljsd.jieling.config.SDrop;
import com.ljsd.jieling.config.SItem; import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.globals.GlobalItemType;
import com.ljsd.jieling.logic.dao.Item; import com.ljsd.jieling.logic.dao.Item;
import com.ljsd.jieling.logic.dao.ItemManager; import com.ljsd.jieling.logic.dao.ItemManager;
import com.ljsd.jieling.logic.dao.User; import com.ljsd.jieling.logic.dao.User;
@ -10,11 +12,56 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
public class ItemUtil { public class ItemUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtil.class); private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtil.class);
//掉落
public static CommonProto.Drop.Builder drop(User user, int dropId, CommonProto.Drop.Builder drop) throws Exception {
SDrop sDrop = SDrop.getsDropMap().get(dropId);
if (sDrop == null){
return drop;
}
int dropType = sDrop.getDropType();
Map<Integer, Integer> itemMap = new HashMap<>();
selectDrop(sDrop, dropType, itemMap);
addItem(user,itemMap,drop);
return drop;
}
private static void selectDrop(SDrop sDrop, int dropType, Map<Integer, Integer> itemMap) {
int[][] itemIds = sDrop.getItem();
if (dropType == GlobalItemType.ALL_DROP){
for (int[] itemId : itemIds) {
getMap(itemId, itemMap);
}
}else{
int[] weights = sDrop.getWeight();
int index = MathUtils.randomForStrArray(weights);
getMap(itemIds[index], itemMap);
}
}
private static void getMap(int[] itemInfo, Map<Integer, Integer> itemMap) {
SItem sItem = SItem.getsItemMap().get(itemInfo[1]);
int itemType = sItem.getItemType();
switch (itemType) {
case GlobalItemType.ITEM:
putcountMap(itemInfo, itemMap);
break;
default:
break;
}
}
private static void putcountMap(int[] itemInfo, Map<Integer, Integer> map) {
map.merge(itemInfo[0], itemInfo[1], (a, b) -> b + a);
}
/** /**
* *
@ -22,7 +69,8 @@ public class ItemUtil {
* @param itemMap * @param itemMap
* @throws Exception * @throws Exception
*/ */
public static void addItem(User user, Map<Integer, Integer> itemMap) throws Exception { public static void addItem(User user, Map<Integer, Integer> itemMap,CommonProto.Drop.Builder dropBuilder) throws Exception {
List<CommonProto.Item> itemProtoList = new CopyOnWriteArrayList<>();
ItemManager itemManager = user.getItemManager(); ItemManager itemManager = user.getItemManager();
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) { for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
SItem sItem = SItem.getsItemMap().get(entry.getKey()); SItem sItem = SItem.getsItemMap().get(entry.getKey());
@ -34,7 +82,12 @@ public class ItemUtil {
item.setItemNum(item.getItemNum() + entry.getValue()); item.setItemNum(item.getItemNum() + entry.getValue());
} }
} }
if (dropBuilder != null) {
CommonProto.Item itemProto = CommonProto.Item.newBuilder().setItemId(item.getItemId()).setItemNum(item.getItemNum()).build();
itemProtoList.add(itemProto);
}
} }
dropBuilder.addAllItemlist(itemProtoList);
//todo 为了测试 日后要删掉 //todo 为了测试 日后要删掉
UserManager.ljsdMongoTemplate.lastUpdate(); UserManager.ljsdMongoTemplate.lastUpdate();
} }

View File

@ -0,0 +1,85 @@
package com.ljsd.jieling.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ThreadLocalRandom;
/**
* Created by admin on 2014/11/14.
*
*/
public class MathUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(MathUtils.class);
/**
*
* @param rateArray
* @return
*/
public static int randomForStrArray(int[] rateArray) {
return randomStrArray(rateArray, -1);
}
public static int randomStrArray(int[] rateArray, int minSum) {
if (null == rateArray) {
throw new IllegalArgumentException(
"The random array must not be null!");
}
int arrayLength = rateArray.length;
if (arrayLength == 0) {
throw new IllegalArgumentException(
"The random array's length must not be zero!");
}
// 依次累加的和
int rateSum = 0;
// 从头开始 依次累加之后的各个元素和 的临时数组
int[] rateSumArray = new int[arrayLength];
for (int i = 0; i < arrayLength; i++) {
if (rateArray[i] < 0) {
throw new IllegalArgumentException(
"The array's element must not be equal or greater than zero!");
}
rateSum += rateArray[i];
rateSumArray[i] = rateSum;
}
if (rateSum <= 0) {
// 所有概率都为零,必然没有选中的元素,返回无效索引:-1
return -1;
}
//如果有保底分母设置,当所有权值之和小于保底分母时,则启用保底分母
if(minSum < rateSum) {
minSum = rateSum;
}
int randomInt = MathUtils.random(1, minSum);
if(randomInt > rateSum) {
return -1;
}
int bingoIndex = -1;
for (int i = 0; i < arrayLength; i++) {
if (randomInt <= rateSumArray[i]) {
bingoIndex = i;
break;
}
}
if (bingoIndex == -1) {
throw new IllegalStateException("Cannot find out bingo index!");
}
return bingoIndex;
}
/**
* >=low, <=hi
*
* @param low
* @param hi
* @return
*/
public static int random(int low, int hi) {
// return (int) (low + (hi - low + 0.9) * Math.random());
return low + ThreadLocalRandom.current().nextInt(hi - low + 1);
}
}

View File

@ -3,26 +3,6 @@ package com.ljsd.jieling.util;
public class ToolsUtil { 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 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 msgIndex = 1;
private static int token=543242; 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(gameMessage, MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE));
handler.sendRequest_jieling(makeFinalMessage(getHero(), MessageTypeProto.MessageType.GET_HEROINFO_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(){ public static HeroInfoProto.GetHeroListInfoRequest getHero(){
return HeroInfoProto.GetHeroListInfoRequest.newBuilder().setNum(1).setStr("111").build(); 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) { private static byte[] makeFinalMessage(MessageLite request, int msgNum) {
byte[] messageData = request.toByteArray(); byte[] messageData = request.toByteArray();