初始化框架
commit
d7145b6be8
|
|
@ -0,0 +1,93 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serverSetting>
|
||||||
|
<dbSetting>
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxActive>80</maxActive>
|
||||||
|
<!-- 初始连接池大小, 默认0个 -->
|
||||||
|
<initialSize>2</initialSize>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>10</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认-1 -->
|
||||||
|
<maxWait>-1</maxWait>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 配置连接在池中最小生存的时间,默认180000-->
|
||||||
|
<minEvictableIdleTimeMillis>180000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒, 默认60000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>60000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 配置发生错误时多久重连,默认300000 -->
|
||||||
|
<timeBetweenConnectErrorMillis>30000</timeBetweenConnectErrorMillis>
|
||||||
|
<!-- 是否打开连接泄露自动检测, 默认false -->
|
||||||
|
<removeAbandoned>false</removeAbandoned>
|
||||||
|
<!-- 连接长时间没有使用,被认为发生泄露时长, 默认300000 -->
|
||||||
|
<removeAbandonedTimeoutMillis>300000</removeAbandonedTimeoutMillis>
|
||||||
|
<!-- 发生泄露时是否需要输出 log,建议在开启连接泄露检测时开启,方便排错 -->
|
||||||
|
<logAbandoned>false</logAbandoned>
|
||||||
|
<!-- 只要maxPoolPreparedStatementPerConnectionSize>0,poolPreparedStatements就会被自动设定为true,使用oracle时可以设定此值。 默认 10-->
|
||||||
|
<maxPoolPreparedStatementPerConnectionSize>-1</maxPoolPreparedStatementPerConnectionSize>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<dbList>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.jdbc.Driver</driverName>
|
||||||
|
<connectionString>jdbc:mysql://127.0.0.1:8060/wb_game</connectionString>
|
||||||
|
<userName>root</userName>
|
||||||
|
<password>root</password>
|
||||||
|
</db>
|
||||||
|
</dbList>
|
||||||
|
</dbSetting>
|
||||||
|
|
||||||
|
<redisSetting>
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>8</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>2</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="127.0.0.1" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="127.0.0.1" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="127.0.0.1" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="127.0.0.1" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="127.0.0.1" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="127.0.0.1" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</redisSetting>
|
||||||
|
</serverSetting>
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.data</groupId>
|
||||||
|
<artifactId>data_cache</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-core</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用redis时导入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>data_cache</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* account bean class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AccountBean extends BaseBean{
|
||||||
|
|
||||||
|
public String nick;
|
||||||
|
public String portrait;
|
||||||
|
public int type;
|
||||||
|
public int mng;
|
||||||
|
public int sex;
|
||||||
|
public String ip;
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> redis_map) {
|
||||||
|
String _id = redis_map.get("id");
|
||||||
|
if(StringUtil.isEmpty(_id)) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id =Integer.parseInt(_id);
|
||||||
|
this.nick = redis_map.get("nick");
|
||||||
|
this.portrait = redis_map.get("portrait");
|
||||||
|
this.ip = redis_map.get("ip");
|
||||||
|
this.type = Integer.parseInt(redis_map.get("type"));
|
||||||
|
this.sex = Integer.parseInt(redis_map.get("sex"));
|
||||||
|
if(this.sex == 0)this.sex = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* base bean class.
|
||||||
|
*/
|
||||||
|
public class BaseBean {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
public int id;
|
||||||
|
/**
|
||||||
|
* redis key
|
||||||
|
*/
|
||||||
|
public String redis_key;
|
||||||
|
/**
|
||||||
|
* cache version.
|
||||||
|
*/
|
||||||
|
public volatile long cache_ver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cache last time.
|
||||||
|
*/
|
||||||
|
public volatile long cache_time;
|
||||||
|
/**
|
||||||
|
* 标记是否删除
|
||||||
|
*/
|
||||||
|
public volatile boolean del;
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* game bean class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GameBean extends BaseBean{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* name
|
||||||
|
*/
|
||||||
|
public String name;
|
||||||
|
/**
|
||||||
|
* 最大人数
|
||||||
|
*/
|
||||||
|
public int maxPlayers;
|
||||||
|
/**
|
||||||
|
* 体力值类型
|
||||||
|
*/
|
||||||
|
public int hpType;
|
||||||
|
/**
|
||||||
|
* 包名
|
||||||
|
*/
|
||||||
|
public String bundle;
|
||||||
|
/**
|
||||||
|
* 局数设置
|
||||||
|
*/
|
||||||
|
public Map<Integer,Integer> opt;
|
||||||
|
/**
|
||||||
|
* 版本
|
||||||
|
*/
|
||||||
|
public String version;
|
||||||
|
|
||||||
|
public int gameType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器列表
|
||||||
|
*/
|
||||||
|
public Set<String> svr_list;
|
||||||
|
/**
|
||||||
|
* 支付设置
|
||||||
|
*/
|
||||||
|
public Map<String,Integer> pay;
|
||||||
|
/**不可负分*/
|
||||||
|
public int isNonnegative ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> redis_map) {
|
||||||
|
// Map<String,String> redis_map = jedis.hgetAll(redis_key);
|
||||||
|
if(redis_map.isEmpty()) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(redis_map.get("id"));
|
||||||
|
this.name = redis_map.get("name");
|
||||||
|
this.bundle = redis_map.get("bundle");
|
||||||
|
this.maxPlayers =Integer.parseInt(redis_map.get("maxPlayers"));
|
||||||
|
this.hpType =Integer.parseInt(redis_map.get("hpType"));
|
||||||
|
this.opt = new HashMap<>();
|
||||||
|
for(int i=1;i<=5;++i) {
|
||||||
|
String key = "opt"+i;
|
||||||
|
this.opt.put(i, Integer.parseInt(redis_map.get(key)));
|
||||||
|
}
|
||||||
|
this.version = redis_map.get("version");
|
||||||
|
this.gameType =Integer.parseInt( redis_map.get("gameType"));
|
||||||
|
this.isNonnegative = Integer.parseInt(redis_map.get("isNonnegative"));
|
||||||
|
this.svr_list = Redis.use("group1_db1").smembers("game_svr:" + id);
|
||||||
|
|
||||||
|
this.pay = new HashMap<>();
|
||||||
|
for (Entry<String, String> entry : redis_map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if(key.startsWith("pay")) {
|
||||||
|
this.pay.put(key, Integer.parseInt(entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getTObject() {
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putInt("game_id", id);
|
||||||
|
obj.putString("name", name);
|
||||||
|
obj.putString("bundle", bundle);
|
||||||
|
obj.putInt("hpType", hpType);
|
||||||
|
obj.putString("version", version);
|
||||||
|
obj.putInt("gameType", gameType);
|
||||||
|
obj.putInt("isNonnegative", isNonnegative);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "game:" + gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.cache.GroupPlayCache;
|
||||||
|
|
||||||
|
public class GroupBean extends BaseBean{
|
||||||
|
/**
|
||||||
|
* name
|
||||||
|
*/
|
||||||
|
public String name;
|
||||||
|
public int owner;
|
||||||
|
public int type;
|
||||||
|
public int create_time;
|
||||||
|
public int ban;
|
||||||
|
public int gms;
|
||||||
|
public int pay_type;
|
||||||
|
public int stop;
|
||||||
|
public int ban_apply;
|
||||||
|
public int dissolve_opt;
|
||||||
|
public int kick_opt;
|
||||||
|
public boolean ban_chat1;
|
||||||
|
public boolean ban_chat2;
|
||||||
|
public int exit_opt;
|
||||||
|
public int option;
|
||||||
|
public int show_num;
|
||||||
|
public GroupMemberCache memberCache;
|
||||||
|
|
||||||
|
public GroupPlayCache playCache;
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
if(map.isEmpty()) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int opt = Integer.parseInt(map.get("opt"));
|
||||||
|
if(opt!=1) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(map.get("id"));
|
||||||
|
this.name = map.get("name");
|
||||||
|
this.type = Integer.parseInt(map.get("type"));
|
||||||
|
this.create_time = Integer.parseInt(map.get("create_time"));
|
||||||
|
this.ban = Integer.parseInt(map.get("ban"));
|
||||||
|
this.gms = Integer.parseInt(map.get("gms"));
|
||||||
|
this.owner = Integer.parseInt(map.get("owner"));
|
||||||
|
this.pay_type = Integer.parseInt(map.get("pay_type"));
|
||||||
|
if(map.containsKey("stop")) {
|
||||||
|
this.stop = Integer.parseInt(map.get("stop"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("ban_apply")) {
|
||||||
|
this.ban_apply = Integer.parseInt(map.get("ban_apply"));
|
||||||
|
}
|
||||||
|
kick_opt = Integer.parseInt(map.get("kick_opt"));
|
||||||
|
dissolve_opt = Integer.parseInt(map.get("dissolve_opt"));
|
||||||
|
if(map.containsKey("ban_chat1")) {
|
||||||
|
this.ban_chat1 = Boolean.parseBoolean(map.get("ban_chat1"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("ban_chat2")) {
|
||||||
|
this.ban_chat2 = Boolean.parseBoolean(map.get("ban_chat2"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("exit_opt")) {
|
||||||
|
this.exit_opt = Integer.parseInt(map.get("exit_opt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(map.containsKey("option")) {
|
||||||
|
this.option = Integer.parseInt(map.get("option"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(map.containsKey("show_num")) {
|
||||||
|
this.show_num = Integer.parseInt(map.get("show_num"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GroupMemberBean extends BaseBean{
|
||||||
|
public int groupId;
|
||||||
|
public int parentId;
|
||||||
|
public int partnerLev;
|
||||||
|
public int lev;
|
||||||
|
public int ban;
|
||||||
|
public int top_time;
|
||||||
|
public int join_time;
|
||||||
|
public int last_time;
|
||||||
|
public int permission;
|
||||||
|
public int score;
|
||||||
|
|
||||||
|
public int queueid=0; //分组号用于幸运号看到对应的用户分组号
|
||||||
|
public int seeid; //幸运号看到的分组id
|
||||||
|
|
||||||
|
public GroupMemberBean(int gid) {
|
||||||
|
this.groupId = gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
if(map.isEmpty()) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int opt = Integer.parseInt(map.get("opt"));
|
||||||
|
if(opt!=1) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(map.get("uid"));
|
||||||
|
this.parentId = Integer.parseInt(map.get("parentId"));
|
||||||
|
this.partnerLev = Integer.parseInt(map.get("partnerLev"));
|
||||||
|
this.lev = Integer.parseInt(map.get("lev"));
|
||||||
|
this.ban = Integer.parseInt(map.get("ban"));
|
||||||
|
this.top_time = Integer.parseInt(map.get("top_time"));
|
||||||
|
this.join_time = Integer.parseInt(map.get("join_time"));
|
||||||
|
if(map.containsKey("last_time")) {
|
||||||
|
this.last_time = Integer.parseInt(map.get("last_time"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("permission")) {
|
||||||
|
this.permission = Integer.parseInt(map.get("permission"));
|
||||||
|
}
|
||||||
|
if(map.containsKey("score")) {
|
||||||
|
this.score = Integer.parseInt(map.get("score"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(map.containsKey("queueid")) {
|
||||||
|
this.queueid = Integer.parseInt(map.get("queueid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(map.containsKey("seeid")) {
|
||||||
|
this.seeid = Integer.parseInt(map.get("seeid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
package com.data.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.data.cache.GameCache;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
public class GroupPlayBean extends BaseBean {
|
||||||
|
public ITObject data = null;
|
||||||
|
public ITObject simp_data = null;
|
||||||
|
public int pay_type;
|
||||||
|
public int gameType;
|
||||||
|
public int gameId;
|
||||||
|
public int maxPlayers;
|
||||||
|
public String config;
|
||||||
|
public String hpConfig;
|
||||||
|
public int hp_times;
|
||||||
|
public int hpOnOff;
|
||||||
|
public int ban;
|
||||||
|
public boolean mark;
|
||||||
|
public String name;
|
||||||
|
public int deskId;
|
||||||
|
public int reward;
|
||||||
|
public int xipai_reward;
|
||||||
|
public int rewardType;
|
||||||
|
public int rewardValueType;
|
||||||
|
public int xipai_rewardType;
|
||||||
|
public int xipai_rewardValueType;
|
||||||
|
public int robot_room;
|
||||||
|
public ITObject configData;
|
||||||
|
|
||||||
|
public void fillData(Map<String,String> map) {
|
||||||
|
if(!map.get("opt").equals("1")) {
|
||||||
|
this.del = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ITObject obj = data;
|
||||||
|
if(obj==null) {
|
||||||
|
obj = TObject.newInstance();
|
||||||
|
this.data = obj;
|
||||||
|
}
|
||||||
|
this.id = Integer.parseInt(map.get("id"));
|
||||||
|
this.name = map.get("name");
|
||||||
|
this.gameId = Integer.parseInt(map.get("gameId"));
|
||||||
|
this.config = map.get("config");
|
||||||
|
this.hpConfig = map.get("hpData");
|
||||||
|
this.hpOnOff = Integer.parseInt(map.get("hpOnOff"));
|
||||||
|
this.hp_times = Integer.parseInt(map.get("hp_times"));
|
||||||
|
this.ban = map.containsKey("ban") ? Integer.parseInt(map.get("ban")) : 0;
|
||||||
|
|
||||||
|
int iMark = map.containsKey("mark") ? Integer.parseInt(map.get("mark")) : 0;
|
||||||
|
this.mark = iMark==1 ? true : false;
|
||||||
|
|
||||||
|
this.reward = Integer.parseInt(map.get("reward"));
|
||||||
|
this.xipai_reward = 100000000;
|
||||||
|
if(map.get("xipai_reward") != null) {
|
||||||
|
this.xipai_reward = Integer.parseInt(map.get("xipai_reward"));
|
||||||
|
}
|
||||||
|
this.rewardType = Integer.parseInt(map.get("rewardType"));
|
||||||
|
this.rewardValueType = 1;
|
||||||
|
if(map.get("rewardValueType") != null) {
|
||||||
|
this.rewardValueType = Integer.parseInt(map.get("rewardValueType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.xipai_rewardType = 1;
|
||||||
|
if(map.get("xipai_rewardType") != null) {
|
||||||
|
this.xipai_rewardType = Integer.parseInt(map.get("xipai_rewardType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.xipai_rewardValueType = 1;
|
||||||
|
if(map.get("xipai_rewardValueType") != null) {
|
||||||
|
this.xipai_rewardValueType = Integer.parseInt(map.get("xipai_rewardValueType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.robot_room = 0;
|
||||||
|
if(map.get("robot_room") != null) {
|
||||||
|
this.robot_room = Integer.parseInt(map.get("robot_room"));
|
||||||
|
}
|
||||||
|
if(map.get("deskId") != null) {
|
||||||
|
this.deskId = Integer.parseInt(map.get("deskId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.putInt("id", this.id);
|
||||||
|
obj.putString("name", this.name);
|
||||||
|
obj.putInt("gameId", gameId);
|
||||||
|
obj.putInt("deskId", this.deskId);
|
||||||
|
obj.putString("config", config);
|
||||||
|
obj.putString("hpData", hpConfig);
|
||||||
|
obj.putInt("hp_times", hp_times);
|
||||||
|
obj.putInt("hpOnOff", hpOnOff);
|
||||||
|
obj.putInt("reward", reward);
|
||||||
|
obj.putInt("xipai_reward", xipai_reward);
|
||||||
|
obj.putInt("rewardType", rewardType);
|
||||||
|
obj.putInt("rewardValueType", rewardValueType);
|
||||||
|
obj.putInt("xipai_rewardType", xipai_rewardType);
|
||||||
|
obj.putInt("xipai_rewardValueType", xipai_rewardValueType);
|
||||||
|
obj.putInt("ban", ban);
|
||||||
|
obj.putBoolean("mark", mark);
|
||||||
|
|
||||||
|
GameBean gb = GameCache.getGame(gameId);
|
||||||
|
obj.putString("game_name", gb.name);
|
||||||
|
|
||||||
|
configData = TObject.newFromJsonData(map.get("config"));
|
||||||
|
maxPlayers = gb.maxPlayers;
|
||||||
|
if(configData.containsKey("maxPlayers")) {
|
||||||
|
maxPlayers = configData.getInt("maxPlayers");
|
||||||
|
}
|
||||||
|
obj.putInt("maxPlayers", maxPlayers);
|
||||||
|
|
||||||
|
if(simp_data==null) {
|
||||||
|
simp_data = TObject.newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
simp_data.putInt("gameId", gameId);
|
||||||
|
simp_data.putInt("id", this.id);
|
||||||
|
simp_data.putInt("hpOnOff", obj.getInt("hpOnOff"));
|
||||||
|
simp_data.putInt("maxPlayers", maxPlayers);
|
||||||
|
simp_data.putString("name", obj.getString("name"));
|
||||||
|
simp_data.putInt("deskId", this.deskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.AccountBean;
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* account cache class.
|
||||||
|
*/
|
||||||
|
public class AccountCache extends BaseCache{
|
||||||
|
|
||||||
|
protected AccountCache() {
|
||||||
|
super("{user}:","group1_db0");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static AccountCache inst;
|
||||||
|
|
||||||
|
|
||||||
|
public static AccountBean getAccount(int id) {
|
||||||
|
if(inst==null)inst = new AccountCache();
|
||||||
|
return inst.getBean(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccountBean getAccount(String session) {
|
||||||
|
if(inst==null)inst = new AccountCache();
|
||||||
|
return inst.getBean(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new AccountBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearData() {
|
||||||
|
if(inst==null)inst = new AccountCache();
|
||||||
|
inst.clearExpireData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "{user}:" + gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,222 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* base cache class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class BaseCache {
|
||||||
|
private static final String VER_KEY= "cache_ver";
|
||||||
|
private static final String MAIN_KEY= "id";
|
||||||
|
protected ConcurrentMap<String, BaseBean> mapByKey = new ConcurrentHashMap<>();
|
||||||
|
protected ConcurrentMap<Integer, BaseBean> mapById = new ConcurrentHashMap<>();
|
||||||
|
protected String key;
|
||||||
|
protected String cacheKey;
|
||||||
|
protected int fillSize;
|
||||||
|
/**默认1秒*/
|
||||||
|
protected int readTime = 1000;
|
||||||
|
|
||||||
|
protected BaseCache(String key,String cacheKey) {
|
||||||
|
this.key = key;
|
||||||
|
this.cacheKey = cacheKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long readVersion(String str_ver) {
|
||||||
|
if(StringUtil.isEmpty(str_ver)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int cache_ver = Integer.parseInt(str_ver);
|
||||||
|
return cache_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本KEY更新
|
||||||
|
* @param jedis
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public static void updateCacheVer(Jedis jedis,String key) {
|
||||||
|
jedis.hincrBy(key, VER_KEY, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* new bean class
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract BaseBean newBean();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键KEY
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String mainKey() {
|
||||||
|
return MAIN_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BaseBean fillBean(BaseBean bean){
|
||||||
|
Jedis jedis = Redis.use(cacheKey).getJedis();
|
||||||
|
try {
|
||||||
|
String str_ver = null;
|
||||||
|
long cache_ver = -1;
|
||||||
|
if(System.currentTimeMillis() - bean.cache_time >= readTime) {
|
||||||
|
List<String> list = jedis.hmget(bean.redis_key, mainKey(),VER_KEY);
|
||||||
|
if(StringUtil.isEmpty(list.get(0))) {
|
||||||
|
bean.del = true;
|
||||||
|
}else {
|
||||||
|
str_ver = list.get(1);
|
||||||
|
cache_ver = readVersion(str_ver);
|
||||||
|
if(bean.cache_ver > 0 && cache_ver==-1) {
|
||||||
|
cache_ver = bean.cache_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
bean.cache_time = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
cache_ver = bean.cache_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!bean.del && (cache_ver == -1 || bean.cache_ver < cache_ver)) {
|
||||||
|
Map<String,String> map = jedis.hgetAll(bean.redis_key);
|
||||||
|
try {
|
||||||
|
if(map==null || map.size() == 0){
|
||||||
|
bean.del = true;
|
||||||
|
}else {
|
||||||
|
bean.fillData(map);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(bean.redis_key, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!bean.del) {
|
||||||
|
mapById.put(bean.id, bean);
|
||||||
|
mapByKey.put(bean.redis_key, bean);
|
||||||
|
bean.del = false;
|
||||||
|
str_ver = map.get(VER_KEY);
|
||||||
|
cache_ver = readVersion(str_ver);
|
||||||
|
bean.cache_ver = bean.cache_ver > cache_ver ? bean.cache_ver : cache_ver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bean.del) {
|
||||||
|
mapById.remove(bean.id);
|
||||||
|
mapByKey.remove(bean.redis_key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String genKey(int id) {
|
||||||
|
String s_id = fillSize>0?(String.format("%0"+fillSize+"d", id)):(id+StringUtil.Empty);
|
||||||
|
String key = this.key + s_id;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get bean by id
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends BaseBean> T getBean(int id){
|
||||||
|
String key = genKey(id);
|
||||||
|
synchronized (key) {
|
||||||
|
BaseBean bean = mapById.get(id);
|
||||||
|
if(bean==null) {
|
||||||
|
bean = newBean();
|
||||||
|
bean.id = id;
|
||||||
|
bean.redis_key = key;
|
||||||
|
}else {
|
||||||
|
if(bean.del) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (T) fillBean(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get bean by key
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends BaseBean> T getBean(String key){
|
||||||
|
synchronized (key) {
|
||||||
|
BaseBean bean = mapByKey.get(key);
|
||||||
|
if(bean==null) {
|
||||||
|
bean = newBean();
|
||||||
|
bean.redis_key = key;
|
||||||
|
}else {
|
||||||
|
if(bean.del) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (T) fillBean(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete bean by id
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean delBean(int id) {
|
||||||
|
BaseBean bean = mapById.get(id);
|
||||||
|
if(bean!=null) {
|
||||||
|
bean.del = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete bean by key
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean delBean(String key) {
|
||||||
|
BaseBean bean = mapByKey.get(key);
|
||||||
|
if(bean!=null) {
|
||||||
|
bean.del = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clear expire data
|
||||||
|
*/
|
||||||
|
public synchronized void clearExpireData() {
|
||||||
|
List<BaseBean> list = new ArrayList<>(mapById.values());
|
||||||
|
for(BaseBean bean : list) {
|
||||||
|
if(bean.del || System.currentTimeMillis() - bean.cache_time > 180000) {
|
||||||
|
bean.del = true;
|
||||||
|
mapById.remove(bean.id);
|
||||||
|
mapByKey.remove(bean.redis_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clear all
|
||||||
|
*/
|
||||||
|
public synchronized void clear() {
|
||||||
|
this.mapById.clear();
|
||||||
|
this.mapByKey.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GameBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* game cache class.
|
||||||
|
*/
|
||||||
|
public class GameCache extends BaseCache{
|
||||||
|
|
||||||
|
protected GameCache() {
|
||||||
|
super("game:","group1_db1");
|
||||||
|
}
|
||||||
|
|
||||||
|
static GameCache inst;
|
||||||
|
|
||||||
|
public static GameBean getGame(int id) {
|
||||||
|
if(inst==null) {
|
||||||
|
inst = new GameCache();
|
||||||
|
}
|
||||||
|
return inst.getBean(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameBean getGame(String key) {
|
||||||
|
if(inst==null) {
|
||||||
|
inst = new GameCache();
|
||||||
|
}
|
||||||
|
return inst.getBean(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new GameBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearData() {
|
||||||
|
if(inst==null)inst = new GameCache();
|
||||||
|
inst.clearExpireData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "game_" + gid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupBean;
|
||||||
|
import com.data.bean.GroupMemberBean;
|
||||||
|
import com.data.bean.GroupPlayBean;
|
||||||
|
|
||||||
|
public class GroupCache extends BaseCache{
|
||||||
|
static GroupCache inst;
|
||||||
|
|
||||||
|
protected GroupCache() {
|
||||||
|
super("group:", "group1_db11");
|
||||||
|
this.readTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new GroupBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GroupCache me() {
|
||||||
|
if (inst == null) {
|
||||||
|
inst = new GroupCache();
|
||||||
|
}
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearData() {
|
||||||
|
me().clearExpireData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupBean getGroup(int id) {
|
||||||
|
return me().getBean(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupBean getGroup(String key) {
|
||||||
|
return me().getBean(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupMemberBean getMember(int gid, int uid) {
|
||||||
|
GroupBean gb = getGroup(gid);
|
||||||
|
if (gb != null) {
|
||||||
|
synchronized (gb) {
|
||||||
|
if (gb.memberCache == null) {
|
||||||
|
gb.memberCache = new GroupMemberCache(gid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gb.memberCache.getBean(uid);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroupPlayBean getPlay(int gid, int pid) {
|
||||||
|
GroupBean gb = getGroup(gid);
|
||||||
|
if (gb != null) {
|
||||||
|
synchronized (gb) {
|
||||||
|
if (gb.playCache == null) {
|
||||||
|
gb.playCache = new GroupPlayCache(gid,gb.pay_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gb.playCache.getBean(pid);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genGroupsKey(int uid) {
|
||||||
|
return "groups:" + uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid) {
|
||||||
|
return "group:" + gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genRewardKey(int gid,int pid) {
|
||||||
|
return "g{" + gid+"}:reward:"+pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genXiPaiRewardKey(int gid,int pid) {
|
||||||
|
return "g{" + gid+"}:xipai_reward:"+pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genRoomsKey(int gid) {
|
||||||
|
return "g{" + gid+"}:rooms";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genPidsKey(int gid) {
|
||||||
|
return "g{" + gid + "}:pids";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genPlayKey(int gid,int pid) {
|
||||||
|
return "g{" + gid + "}:play:" + pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genBanKey(int gid,int uid) {
|
||||||
|
return "g{" + gid+"}:ban:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genMemberListKey(int gid,int uid) {
|
||||||
|
return "g{"+gid+"}:member_list:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genParListKey(int gid,int uid) {
|
||||||
|
return "g{"+gid+"}:par_list:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genJoinsKey(int gid) {
|
||||||
|
return "gmjs_"+gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genMailKey(int gid,int uid) {
|
||||||
|
return "g{"+gid+"}:mail:"+uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genMailTipKey(int gid) {
|
||||||
|
return "g{"+gid+"}:mail_tip";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupMemberBean;
|
||||||
|
|
||||||
|
public class GroupMemberCache extends BaseCache{
|
||||||
|
private static final String MAIN_KEY= "join_time";
|
||||||
|
private int groupId;
|
||||||
|
|
||||||
|
public GroupMemberCache(int gid) {
|
||||||
|
super("g{"+gid+"}:m", "group1_db10");
|
||||||
|
this.groupId = gid;
|
||||||
|
this.readTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
return new GroupMemberBean(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键KEY
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String mainKey() {
|
||||||
|
return MAIN_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String genKey(int gid, int uid) {
|
||||||
|
return String.format("g{%s}:m%s", gid, uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
package com.data.cache;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.data.bean.BaseBean;
|
||||||
|
import com.data.bean.GroupPlayBean;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupPlayCache extends BaseCache{
|
||||||
|
private ITArray playList;
|
||||||
|
private ITArray simpPlayList;
|
||||||
|
private int groupId;
|
||||||
|
private long last_time;
|
||||||
|
private int pay_type;
|
||||||
|
private int gameType;
|
||||||
|
|
||||||
|
public GroupPlayCache(int groupId,int pay_type) {
|
||||||
|
super("g{"+groupId+"}:play:","group1_db11");
|
||||||
|
this.groupId = groupId;
|
||||||
|
this.pay_type = pay_type;
|
||||||
|
playList = TArray.newInstance();
|
||||||
|
simpPlayList = TArray.newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseBean newBean() {
|
||||||
|
GroupPlayBean p = new GroupPlayBean();
|
||||||
|
p.pay_type = pay_type;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update play data.
|
||||||
|
* @param play_data
|
||||||
|
*/
|
||||||
|
public void updatePlay() {
|
||||||
|
playList.clear();
|
||||||
|
simpPlayList.clear();
|
||||||
|
Set<Entry<Integer, BaseBean>> set = this.mapById.entrySet();
|
||||||
|
for(Entry<Integer, BaseBean> entry : set) {
|
||||||
|
GroupPlayBean gp =(GroupPlayBean)entry.getValue();
|
||||||
|
if(!gp.del) {
|
||||||
|
playList.addTObject(gp.data);
|
||||||
|
simpPlayList.addTObject(gp.simp_data);
|
||||||
|
}else {
|
||||||
|
this.mapById.remove(gp.id);
|
||||||
|
this.mapByKey.remove(gp.redis_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取玩法列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final ITArray getPlayList(int lev,int uid){
|
||||||
|
/*if(System.currentTimeMillis() - last_time < 180000) {
|
||||||
|
if(lev < 3) {
|
||||||
|
return playList;
|
||||||
|
}else {
|
||||||
|
return simpPlayList;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
last_time = System.currentTimeMillis();
|
||||||
|
playList.clear();
|
||||||
|
simpPlayList.clear();
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis1 = Redis.use("group1_db1").getJedis();
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
String gpids_key = GroupCache.genPidsKey(groupId);
|
||||||
|
Set<String> pids = jedis11.zrangeByScore(gpids_key, 10, 11);
|
||||||
|
String key = "g{"+this.groupId + "}:play:";
|
||||||
|
|
||||||
|
String gm_key = GroupMemberCache.genKey(groupId, uid);
|
||||||
|
String gameids = jedis10.hget(gm_key, "games");
|
||||||
|
if (StringUtil.isNotEmpty(gameids)){
|
||||||
|
String[] games = gameids.split(",");
|
||||||
|
List<String> list = new ArrayList<>(Arrays.asList(games));
|
||||||
|
for(String tem : pids) {
|
||||||
|
String gp_key = key+tem;
|
||||||
|
GroupPlayBean gp = this.getBean(gp_key);
|
||||||
|
if(gp!=null) {
|
||||||
|
if (!list.contains(gp.gameId+"")){
|
||||||
|
String gkey = "game:"+gp.gameId ;
|
||||||
|
int gameType = Integer.parseInt(jedis1.hget(gkey,"gameType"));
|
||||||
|
//gp.gameType = gameType;
|
||||||
|
gp.data.putInt("gameType",gameType);
|
||||||
|
playList.addTObject(gp.data);
|
||||||
|
simpPlayList.addTObject(gp.simp_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
for(String tem : pids) {
|
||||||
|
String gp_key = key+tem;
|
||||||
|
GroupPlayBean gp = this.getBean(gp_key);
|
||||||
|
if(gp!=null) {
|
||||||
|
String gkey = "game:"+gp.gameId ;
|
||||||
|
int gameType = Integer.parseInt(jedis1.hget(gkey,"gameType"));
|
||||||
|
//gp.gameType = gameType;
|
||||||
|
gp.data.putInt("gameType",gameType);
|
||||||
|
playList.addTObject(gp.data);
|
||||||
|
simpPlayList.addTObject(gp.simp_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis11.close();
|
||||||
|
jedis1.close();
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if(lev < 3) {
|
||||||
|
// return playList;
|
||||||
|
// }else {
|
||||||
|
// return simpPlayList;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return playList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
public class ConsumeCode {
|
||||||
|
|
||||||
|
/** 普通创建房间 **/
|
||||||
|
public final static int DIAMO_CREAT_ROOM = 1;
|
||||||
|
/** AA加入房 **/
|
||||||
|
public final static int DIAMO_JOIN_ROOM = 4;
|
||||||
|
/** 反还**/
|
||||||
|
public final static int DIAMO_REFUND = 5;
|
||||||
|
/** 代开房 **/
|
||||||
|
public final static int DIAMO_AGENT_ROOM = 2;
|
||||||
|
/** 结算 **/
|
||||||
|
public final static int HP_CLEARING = 6;
|
||||||
|
/** 抽水 **/
|
||||||
|
public final static int HP_PUMP = 7; //抽水
|
||||||
|
/** 管理员上分 **/
|
||||||
|
public final static int HP_MGR_UPPER = 8;
|
||||||
|
/** 管理员下分 **/
|
||||||
|
public final static int HP_MGR_SUB = 9;
|
||||||
|
/** 合伙人上分 **/
|
||||||
|
public final static int HP_PARTNER_UPPER = 10;
|
||||||
|
/** 合伙人下分 **/
|
||||||
|
public final static int HP_PARTNER_SUB = 11;
|
||||||
|
/** 合伙人奖励 **/
|
||||||
|
public final static int HP_PARTNER_REWARD = 12;
|
||||||
|
/** 转账 **/
|
||||||
|
public final static int HP_TRADE = 13;
|
||||||
|
/** 体力值提取 **/
|
||||||
|
public final static int HP_TAKE_REWARD = 14;
|
||||||
|
/**大局游戏hp的变化总值*/
|
||||||
|
public final static int HP_PUMP_TOTAL = 15;
|
||||||
|
/***/
|
||||||
|
public final static int HP_TAKE_BANK = 16;
|
||||||
|
|
||||||
|
public final static int HP_SAVE_BANK = 17;
|
||||||
|
|
||||||
|
/** 洗牌 **/
|
||||||
|
public final static int HP_XIPAI_PUMP = 20;
|
||||||
|
/** 合伙人洗牌奖励 **/
|
||||||
|
public final static int HP_PARTNER_XIPAI_REWARD = 21;
|
||||||
|
|
||||||
|
/** 合伙人按抽奖励 **/
|
||||||
|
public final static int HP_PARTNER_ANCHOU_REWARD = 22;
|
||||||
|
|
||||||
|
/** 邮件 **/
|
||||||
|
public final static int DIAMO_MAIL = 50;
|
||||||
|
/** 转盘**/
|
||||||
|
public final static int DIAMO_WHEEL = 51;
|
||||||
|
/** 分享**/
|
||||||
|
public final static int DIAMO_SH = 52;
|
||||||
|
/** 后台充值**/
|
||||||
|
public final static int DIAMO_ADD = 99;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,264 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class CountUtil {
|
||||||
|
|
||||||
|
public static final int LOG_FOREVER = 0;
|
||||||
|
public static final int LOG_DAY = 1;
|
||||||
|
public static final int LOG_LASTDAY = 2;
|
||||||
|
public static final int LOG_WEEK = 3;
|
||||||
|
public static final int LOG_LASTWEEK = 4;
|
||||||
|
public static final int LOG_MONTH = 5;
|
||||||
|
public static final int LOG_LASTMONTH = 6;
|
||||||
|
|
||||||
|
private static final int DAY2 = 172800;
|
||||||
|
private static final int DAY3 = 259200;
|
||||||
|
private static final int DAY10 = 864000;
|
||||||
|
// private static final int MONTH = 2592000;
|
||||||
|
// private static final int WEEK2 = 1209600;
|
||||||
|
// private static final int MONTH2 = 2678400;
|
||||||
|
private static final int MONTH = 1209600;
|
||||||
|
private static final int MONTH2 = 1209600;
|
||||||
|
|
||||||
|
public static int getCountLog(String key,int type,Jedis jedis) {
|
||||||
|
String value = jedis.get(key);
|
||||||
|
if(StringUtil.isNotEmpty(value)) {
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取天数据
|
||||||
|
* @param key
|
||||||
|
* @param jedis
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getCountLogByDay(String key,Jedis jedis) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
String value = jedis.get(day_key);
|
||||||
|
if(StringUtil.isEmpty(value))return 0;
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLog(String key,int num,Jedis jedis) {
|
||||||
|
countLog(key,num,jedis,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void countLog(String key,int num,Pipeline pipeline) {
|
||||||
|
countLog(key,num,pipeline,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
* @param day_expire_month 天数据保存一个月
|
||||||
|
*/
|
||||||
|
public static void countLog(String key,int num,Jedis jedis,boolean day_expire_month) {
|
||||||
|
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
// String week_key = key + ":w"+DateUtils.getBeginWeek();
|
||||||
|
// String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, day_expire_month?MONTH2:DAY10);
|
||||||
|
// jedis.incrBy(week_key,num);
|
||||||
|
// jedis.expire(week_key, WEEK2);
|
||||||
|
// jedis.incrBy(month_key,num);
|
||||||
|
// jedis.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
* @param day_expire_month 天数据保存一个月
|
||||||
|
*/
|
||||||
|
public static void countLog(String key,int num,Pipeline pipeline,boolean day_expire_month) {
|
||||||
|
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
// String week_key = key + ":w"+DateUtils.getBeginWeek();
|
||||||
|
// String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
pipeline.incrBy(day_key,num);
|
||||||
|
pipeline.expire(day_key, day_expire_month?MONTH2:DAY10);
|
||||||
|
// pipeline.incrBy(week_key,num);
|
||||||
|
// pipeline.expire(week_key, WEEK2);
|
||||||
|
// pipeline.incrBy(month_key,num);
|
||||||
|
// pipeline.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void countLog(String key,int num,Jedis jedis,boolean day_expire_month,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
jedis.incrBy(key,num);
|
||||||
|
}
|
||||||
|
countLog(key,num,jedis,day_expire_month);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void countLog(String key,int num,Pipeline pipeline,boolean day_expire_month,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
pipeline.incrBy(key,num);
|
||||||
|
}
|
||||||
|
countLog(key,num,pipeline,day_expire_month);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay(String key,int num,Jedis jedis) {
|
||||||
|
return countLogByDay(key,num,jedis,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay(String key,int num,Pipeline pipeline) {
|
||||||
|
countLogByDay(key,num,pipeline,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay30(String key,int num,Pipeline pipeline) {
|
||||||
|
|
||||||
|
countLogByDay(key,num,pipeline,MONTH);
|
||||||
|
|
||||||
|
String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
pipeline.incrBy(month_key,num);
|
||||||
|
pipeline.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay(String key,int num,Pipeline pipeline,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
pipeline.incrBy(key,num);
|
||||||
|
}
|
||||||
|
|
||||||
|
countLogByDay(key,num,pipeline,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存30天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay30(String key,int num,Pipeline pipeline,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
pipeline.incrBy(key,num);
|
||||||
|
}
|
||||||
|
|
||||||
|
countLogByDay(key,num,pipeline,MONTH);
|
||||||
|
|
||||||
|
String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
pipeline.incrBy(month_key,num);
|
||||||
|
pipeline.expire(month_key, MONTH2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存10天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay(String key,int num,Jedis jedis,boolean total) {
|
||||||
|
|
||||||
|
if(total) {
|
||||||
|
jedis.incrBy(key,num);
|
||||||
|
}
|
||||||
|
|
||||||
|
return countLogByDay(key,num,jedis,DAY10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay(String key,int num,Jedis jedis,int time) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
|
||||||
|
long value = jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, time);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static void countLogByDay(String key,int num,Pipeline pipeline,int time) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
|
||||||
|
pipeline.incrBy(day_key,num);
|
||||||
|
pipeline.expire(day_key, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存2天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay2(String key,int num,Jedis jedis) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
long value = jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, DAY2);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计天数据(存2天)
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @param jedis
|
||||||
|
*/
|
||||||
|
public static long countLogByDay3(String key,int num,Jedis jedis) {
|
||||||
|
String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
long value = jedis.incrBy(day_key,num);
|
||||||
|
jedis.expire(day_key, DAY3);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,167 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
public class ErrorCode {
|
||||||
|
// 成功
|
||||||
|
public final static int _SUCC = 0;
|
||||||
|
// 失败
|
||||||
|
public final static int _FAILED = 1;
|
||||||
|
/** session 不存在 */
|
||||||
|
public final static int _NO_SESSION = 2;
|
||||||
|
// 已经在房间可重连(创建房间协议)
|
||||||
|
public final static int BE_IN_ROOM = 3;
|
||||||
|
// 已创建房间可进入(创建房间协议)
|
||||||
|
public final static int CREATED_ROOM = 4;
|
||||||
|
// 不可选游<E98089>?
|
||||||
|
public final static int NO_GAME = 5;
|
||||||
|
// 无游戏服<E6888F>?
|
||||||
|
public final static int NO_SERVICE = 6;
|
||||||
|
// 缺钻<E7BCBA>?
|
||||||
|
public final static int NO_DIAMO = 7;
|
||||||
|
// 房间不可进入
|
||||||
|
public final static int ROOM_CLOSE = 10;
|
||||||
|
// 房间号错<E58FB7>?
|
||||||
|
public final static int NO_ROOM_NUM = 11;
|
||||||
|
// 邮件不存<E4B88D>?
|
||||||
|
public final static int NO_MAIL = 12;
|
||||||
|
// 邮件已领<E5B7B2>?
|
||||||
|
public final static int RECEIVED_MAIL = 13;
|
||||||
|
// 任务不存<E4B88D>?
|
||||||
|
public final static int NO_TASK = 14;
|
||||||
|
// 任务已领<E5B7B2>?
|
||||||
|
public final static int TASK_COMPLETE = 16;
|
||||||
|
// 缺奖<E7BCBA>?
|
||||||
|
public final static int NO_RAFFLE = 17;
|
||||||
|
// 没有战绩
|
||||||
|
public final static int NO_MILITARY = 19;
|
||||||
|
|
||||||
|
// 设备号已经被锁定
|
||||||
|
public final static int IS_LOCK = 20;
|
||||||
|
|
||||||
|
// 没有回放
|
||||||
|
public final static int NO_REC = 25;
|
||||||
|
//多次登录失败,禁止登录, 半个小时后再试
|
||||||
|
public final static int BAN_LOGIN = 28;
|
||||||
|
|
||||||
|
/** 无效的手机号码 **/
|
||||||
|
public final static int INVALID_PHONE = 58;
|
||||||
|
/** 无效的验证码 **/
|
||||||
|
public final static int INVALID_CODE = 59;
|
||||||
|
/** 手机号码已发短信手机不一致 **/
|
||||||
|
public final static int ATYPISM_PHONE = 60;
|
||||||
|
/** 手机号码已绑定玩家 **/
|
||||||
|
public final static int BINDED_PHONE = 61;
|
||||||
|
/** 该手机号码未绑定游戏 **/
|
||||||
|
public final static int NO_BINDED_PHONE = 62;
|
||||||
|
/** ACC已存在 **/
|
||||||
|
public final static int EXIST_ACC = 63;
|
||||||
|
|
||||||
|
|
||||||
|
/** 房间已删除 */
|
||||||
|
public final static int ROOM_DEL = 80;
|
||||||
|
/** 是圈子房间 */
|
||||||
|
public final static int ROOM_IS_GROUP = 81;
|
||||||
|
/** 玩家申请解散已达上限次数 **/
|
||||||
|
public final static int ROOM_DIS_UPPER_LIMIT = 82;
|
||||||
|
/** 坐下体力值不足*/
|
||||||
|
public final static int ROOM_NOT_HP = 83;
|
||||||
|
/** 是否禁止解散房间*/
|
||||||
|
public final static int ROOM_DIS_NOT_ALLOWED = 84;
|
||||||
|
|
||||||
|
|
||||||
|
/** 是否已申请加入 */
|
||||||
|
public final static int GROUP_JOIN_EXIST = 1000;
|
||||||
|
/** 成员已存在 */
|
||||||
|
public final static int GROUP_MEMBER_EXIST = 1001;
|
||||||
|
/** 成员不存在 */
|
||||||
|
public final static int GROUP_NOT_MEMBER = 1002;
|
||||||
|
/** 成员存在上级合伙人 */
|
||||||
|
public final static int GROUP_MEMBER_EXIST_PARTENER = 1003;
|
||||||
|
/** 玩法已满 */
|
||||||
|
public final static int GROUP_PLAY_FULL = 1004;
|
||||||
|
/** 房间被删除 */
|
||||||
|
public final static int GROUP_ROOM_DEL = 1005;
|
||||||
|
/** 玩法不存在 */
|
||||||
|
public final static int GROUP_PLAY_EXIST = 1007;
|
||||||
|
/** 不是管理员 */
|
||||||
|
public final static int GROUP_MGR_EXIST = 1008;
|
||||||
|
/** 合伙人有成员 */
|
||||||
|
public final static int GROUP_PARTNER_MEMBERS = 1009;
|
||||||
|
/** 目标是管理员 */
|
||||||
|
public final static int GROUP_TAG_ISMGR = 1010;
|
||||||
|
/** 目标是合伙人 */
|
||||||
|
public final static int GROUP_TAG_ISPARTENER = 1011;
|
||||||
|
/** 目标体力值不够 */
|
||||||
|
public final static int GROUP_TAG_NO_HP = 1012;
|
||||||
|
/** 操作人体力值不够 */
|
||||||
|
public final static int GROUP_TAG_MGR_HP = 1013;
|
||||||
|
/** 没有权限 */
|
||||||
|
public final static int GROUP_NOT_PERMISSION = 1014;
|
||||||
|
/** 体力值不为0 */
|
||||||
|
public final static int GROUP_HP_NOT_0 = 1015;
|
||||||
|
/** 成员在房间内 */
|
||||||
|
public final static int GROUP_MEMBER_ROOM_EXIST = 1016;
|
||||||
|
/** 成员体力值事件正在执行 */
|
||||||
|
public final static int GROUP_MEMBER_HPEVT_RUNING = 1017;
|
||||||
|
/** 圈子不存在 */
|
||||||
|
public final static int GROUP_NO_EXIST = 1018;
|
||||||
|
/** 圈子已满 */
|
||||||
|
public final static int GROUP_FULL = 1019;
|
||||||
|
/** 圈子还有房间 */
|
||||||
|
public final static int GROUP_EXIST_ROOMS = 1020;
|
||||||
|
/** 圈子禁止娱乐 */
|
||||||
|
public final static int GROUP_BAN = 1021;
|
||||||
|
/** 不是圈主 */
|
||||||
|
public final static int GROUP_NOT_OWNER = 1022;
|
||||||
|
/** 目標玩家是合伙人 */
|
||||||
|
public final static int GROUP_ALREADY_PARTNER = 1023;
|
||||||
|
/** 目標玩家不是合伙人 */
|
||||||
|
public final static int GROUP_NOT_PARTNER = 1024;
|
||||||
|
/** 圈子成员禁止娱乐 */
|
||||||
|
public final static int GROUP_MEMBER_BAN = 1025;
|
||||||
|
/** 进入房间体力值不足 */
|
||||||
|
public final static int GROUP_LIMIT_NO_HP = 1026;
|
||||||
|
/** 大联盟只能创建一个 */
|
||||||
|
public final static int GROUP_TYPE2_ONLY_1 = 1027;
|
||||||
|
/** 大联盟必须开启体力值 */
|
||||||
|
public final static int GROUP_TYPE2_MUST_HP = 1028;
|
||||||
|
/** 改玩法还存在房间 */
|
||||||
|
public final static int GROUP_PLAY_EXIST_ROOM = 1029;
|
||||||
|
/** 不在此圈子房间中 */
|
||||||
|
public final static int GROUP_NOT_CURGROUP_ROOM = 1030;
|
||||||
|
/** 玩家关闭被邀请 */
|
||||||
|
public final static int GROUP_CLOSE_INVITATION = 1031;
|
||||||
|
/** 圈子已满 */
|
||||||
|
public final static int GROUP_IS_FULL = 1032;
|
||||||
|
/** 圈子成员已满 */
|
||||||
|
public final static int GROUP_MEMBER_IS_FULL = 1033;
|
||||||
|
/** 玩家正在游戏 不能上下分 **/
|
||||||
|
public final static int GROUP_DONOT_SUB_HP = 1034;
|
||||||
|
/** 奖励池体力值不足 **/
|
||||||
|
public final static int GROUP_REWARD_NO_HP = 1035;
|
||||||
|
/** 奖励池没提取 **/
|
||||||
|
public final static int GROUP_REWARD_NO_TAKE = 1036;
|
||||||
|
/** 禁止同桌 **/
|
||||||
|
public final static int GROUP_BAN_DESK = 1037;
|
||||||
|
/** 玩法禁止娱乐 **/
|
||||||
|
public final static int GROUP_BAN_PLAY = 1038;
|
||||||
|
/** 禁止申请加入圈子 **/
|
||||||
|
public final static int GROUP_BAN_APPLY = 1039;
|
||||||
|
/** 圈子停止服务 **/
|
||||||
|
public final static int GROUP_STOP_SERVICE = 1040;
|
||||||
|
/** 大联盟不能退出 **/
|
||||||
|
public final static int GROUP_TYPE2_NOT_EXIT = 1041;
|
||||||
|
/** 玩法存在推广奖励 **/
|
||||||
|
public final static int GROUP_PAY_TYPE3_EXIST = 1042;
|
||||||
|
/** 全民推广已开启,不能转移 **/
|
||||||
|
public final static int GROUP_PROMOTION_ACTIVE = 1043;
|
||||||
|
/** 全民推广为开启 **/
|
||||||
|
public final static int GROUP_PROMOTION_NOT_ACTIVE = 1044;
|
||||||
|
/** 有下级合伙人给其合伙人的分成高于此比例 **/
|
||||||
|
public final static int GROUP_HAS_MEMBER_OVERFLOW = 1045;
|
||||||
|
/** 合伙人体力值不足 **/
|
||||||
|
public final static int GROUP_PARTNER_HP_NOT_ENOUGH = 1046;
|
||||||
|
/** 体力值超越上线, 请保存到保险箱里 **/
|
||||||
|
public final static int GROUP_PARTNER_HP_THAN_LIMIET = 1047;
|
||||||
|
/** 玩家体力值超越上线, 请提醒他保存到上线 **/
|
||||||
|
public final static int GROUP_PARTNER_OTHER_HP_THAN_LIMIET = 1048;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
public class EventType {
|
||||||
|
/**
|
||||||
|
* 扣房卡事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_PAY = 1;
|
||||||
|
/**
|
||||||
|
* 反还房卡事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_BACK_PAY = 4;
|
||||||
|
/**
|
||||||
|
* 赢事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_WIN = 2;
|
||||||
|
/**
|
||||||
|
* 输事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_LOSE = 3;
|
||||||
|
/**
|
||||||
|
* 游戏结束事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_OVER = 5;
|
||||||
|
/**
|
||||||
|
* 牌友圈局数事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_ROUND = 6;
|
||||||
|
/**
|
||||||
|
* 牌友圈成员局数事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_MEMBER_ROUND = 7;
|
||||||
|
/**
|
||||||
|
* 牌友圈体力值事件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_HP = 8;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_HP_DB = 90;
|
||||||
|
/**
|
||||||
|
* 邮件
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_MAIL = 95;
|
||||||
|
/**
|
||||||
|
* 转盘
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_WHEEL = 96;
|
||||||
|
/**
|
||||||
|
* 圈子创房
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_GROUP_ROOM = 97;
|
||||||
|
/**
|
||||||
|
* 普通创房
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_CREATE_ROOM = 98;
|
||||||
|
/**
|
||||||
|
* 后台充钻石
|
||||||
|
*/
|
||||||
|
public static final int REDIS_EVENT_ADDPAY = 99;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,414 @@
|
||||||
|
|
||||||
|
package com.data.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.data.bean.GameBean;
|
||||||
|
import com.data.bean.GroupMemberBean;
|
||||||
|
import com.data.cache.GameCache;
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
|
||||||
|
public class Utility {
|
||||||
|
/**
|
||||||
|
* API 版本
|
||||||
|
*/
|
||||||
|
public static int API_VER = 2;
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(Utility.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取战绩数据
|
||||||
|
* @param jedis5
|
||||||
|
* @param key
|
||||||
|
* @param platform
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public final static ITObject getMilitaryList(Jedis jedis5,String key,String platform) {
|
||||||
|
Map<String, String> military = jedis5.hgetAll(key);
|
||||||
|
if (military == null || military.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putString("military_id", key);
|
||||||
|
String strData = military.get("game_id");
|
||||||
|
if (strData == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
obj.putString("game_id", strData);
|
||||||
|
obj.putString("room_id", military.get("room_id"));
|
||||||
|
obj.putString("round", military.get("round"));
|
||||||
|
int hp_times = 10;
|
||||||
|
if(military.containsKey("hp_times")) {
|
||||||
|
hp_times = Integer.parseInt(military.get("hp_times"));
|
||||||
|
}
|
||||||
|
int groupPid = 0;
|
||||||
|
if(military.containsKey("groupPid")) {
|
||||||
|
groupPid = Integer.parseInt(military.get("groupPid"));
|
||||||
|
}
|
||||||
|
obj.putInt("hp_times", hp_times);
|
||||||
|
obj.putInt("groupPid", groupPid);
|
||||||
|
GameBean gb = GameCache.getGame(Integer.parseInt(strData));
|
||||||
|
ITObject gameObj = gb.getTObject();
|
||||||
|
obj.putTObject("game_info",gameObj);
|
||||||
|
obj.putString("create_time", military.get("create_time"));
|
||||||
|
strData = military.get("totalScore");
|
||||||
|
if (strData != null) {
|
||||||
|
//查询对应的seeid
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
ITArray usobj = TArray.newFromJsonData(strData);
|
||||||
|
ITArray arr = TArray.newInstance();
|
||||||
|
try {
|
||||||
|
for (int i=0;i < usobj.size();i++){
|
||||||
|
ITObject obsj = usobj.getTObject(i);
|
||||||
|
String gm_key = GroupMemberCache.genKey(Integer.parseInt(military.get("groupId")), obsj.getInt("accId"));
|
||||||
|
String queueid = jedis10.hget(gm_key, "queueid");
|
||||||
|
obsj.putInt("queueid",Integer.parseInt(queueid==null?"0":queueid));
|
||||||
|
arr.addTObject(obsj);
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
obj.putString("totalScore", arr.toJson());
|
||||||
|
}
|
||||||
|
String hpOnOff = military.get("hpOnOff");
|
||||||
|
if(StringUtil.isNotEmpty(hpOnOff)) {
|
||||||
|
obj.putInt("hpOnOff", Integer.parseInt(hpOnOff));
|
||||||
|
}else {
|
||||||
|
obj.putInt("hpOnOff", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
strData = military.get("groupId");
|
||||||
|
if (strData == null) {
|
||||||
|
strData = "0";
|
||||||
|
}
|
||||||
|
obj.putString("groupId", strData);
|
||||||
|
for (int i = 1; i <= Integer.parseInt(military.get("round")); i++) {
|
||||||
|
String roundKey = "round_" + i;
|
||||||
|
try {
|
||||||
|
obj.putString(roundKey, military.get(roundKey));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员上级列表
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMemberParents(int groupId,int uid){
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
return getMemberParents(jedis10,groupId,uid,false);
|
||||||
|
}finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员上级列表
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMemberParents(Jedis jedis10,int groupId,int uid,boolean self){
|
||||||
|
return getMemberParents(jedis10,groupId,uid,self,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int getParentsinfo(int groupId,int uid){
|
||||||
|
//Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
|
||||||
|
if (gmb == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int parentId = 0;
|
||||||
|
parentId =gmb.parentId;
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取成员上级列表
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMemberParents(Jedis jedis10,int groupId,int uid,boolean self,int start_par_lev){
|
||||||
|
GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
|
||||||
|
if (gmb == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int partnerLev = 0;
|
||||||
|
int parentId = 0;
|
||||||
|
if(self) {
|
||||||
|
partnerLev = gmb.partnerLev;
|
||||||
|
if(partnerLev>0) {
|
||||||
|
parentId = uid;
|
||||||
|
}else {
|
||||||
|
parentId =gmb.parentId;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
parentId =gmb.parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parentId>0) {
|
||||||
|
if(parentId!=uid) {
|
||||||
|
gmb = GroupCache.getMember(groupId, parentId);
|
||||||
|
partnerLev = gmb.partnerLev;
|
||||||
|
}
|
||||||
|
if(partnerLev==0)return null;
|
||||||
|
List<Integer> list = new ArrayList<Integer>(partnerLev);
|
||||||
|
for(int i=start_par_lev-1;i<partnerLev;++i) {
|
||||||
|
list.add(parentId);
|
||||||
|
parentId =gmb.parentId;
|
||||||
|
gmb = GroupCache.getMember(groupId, parentId);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子合伙人Sql
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getChildParentSql(int groupId,int uid,boolean self) {
|
||||||
|
String pl_key = String.format("g{%s}:par_list:%s",groupId,uid);
|
||||||
|
Set<String> child_list = Redis.use("group1_db10").smembers(pl_key);
|
||||||
|
String p = self ? uid+"" : StringUtil.Empty;
|
||||||
|
for(String str:child_list) {
|
||||||
|
p +=","+str;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子合伙人Sql
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getChildParentList(int groupId,int uid,boolean self) {
|
||||||
|
String pl_key = String.format("g{%s}:par_list:%s",groupId,uid);
|
||||||
|
Set<String> child_list = Redis.use("group1_db10").smembers(pl_key);
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
if(self) {
|
||||||
|
list.add(uid);
|
||||||
|
}
|
||||||
|
for(String str:child_list) {
|
||||||
|
list.add(Integer.parseInt(str));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有member Sql
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getMembersList(int groupId,int uid,boolean self) {
|
||||||
|
String pl_key = String.format("g{%s}:member_list:%s",groupId,uid);
|
||||||
|
Set<String> child_list = Redis.use("group1_db10").smembers(pl_key);
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
if(self) {
|
||||||
|
list.add(uid);
|
||||||
|
}
|
||||||
|
for(String str:child_list) {
|
||||||
|
list.add(Integer.parseInt(str));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type 1 update 2 call
|
||||||
|
* @param sql
|
||||||
|
*/
|
||||||
|
public static void evtdb(int gid, int type, String sql) {
|
||||||
|
if (StringUtil.isEmpty(sql))
|
||||||
|
return;
|
||||||
|
String str = type + sql;
|
||||||
|
Redis.use(CHACHE_KEY).lpush("evt_db_" + (gid % 10), str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type 1 update 2 call 插入不是很重要的LOG, 可以走随机线程
|
||||||
|
* @param sql
|
||||||
|
*/
|
||||||
|
public static void evtdbLog(int gid, int type, String sql) {
|
||||||
|
if (StringUtil.isEmpty(sql))
|
||||||
|
return;
|
||||||
|
String str = type + sql;
|
||||||
|
int id = (int)(gid * Math.random() * 100);
|
||||||
|
id = id % 10;
|
||||||
|
Redis.use(CHACHE_KEY).lpush("evt_db_" + (id), str);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static String EVT_TYPE = "E";
|
||||||
|
private final static String EVT_UID = "uid";
|
||||||
|
private final static String CHACHE_KEY ="group1_db8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付钻石事件
|
||||||
|
* @param type
|
||||||
|
* @param uid
|
||||||
|
* @param game
|
||||||
|
* @param pay
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
*/
|
||||||
|
public static void payDiamo(int type,int uid,int game,int pay,int gid,int pid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", pay);
|
||||||
|
data.putInt("game", game);
|
||||||
|
data.putInt("group", gid);
|
||||||
|
if(pid > 0) {
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
}
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush("event_"+(uid%10),data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付钻石事件
|
||||||
|
* @param type
|
||||||
|
* @param uid
|
||||||
|
* @param game
|
||||||
|
* @param pay
|
||||||
|
* @param cur_diamo
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
*/
|
||||||
|
public static void payDiamo(int type,int uid,int game,int pay,int cur_diamo,int gid,int pid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", pay);
|
||||||
|
data.putInt("game", game);
|
||||||
|
data.putInt("diamo", cur_diamo);
|
||||||
|
data.putInt("group", gid);
|
||||||
|
if(pid > 0) {
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
}
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush("event_"+(uid%10),data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final static String pay_lua="local diamo = tonumber(redis.call('hget', KEYS[1],'diamo'))\n"
|
||||||
|
+ "local pay = tonumber(ARGV[1]) \n"
|
||||||
|
+ "if pay > diamo then \n"
|
||||||
|
+ "return {2,0}\n"
|
||||||
|
+ "end\n"
|
||||||
|
+ "diamo = redis.call('hincrBy',KEYS[1],'diamo',-pay)\n"
|
||||||
|
+ "return {0,diamo}";
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static ArrayList<Long> payDiamo(Jedis jedis0,String session,int pay) {
|
||||||
|
Object obj = jedis0.eval(pay_lua, Arrays.asList(session),Arrays.asList(pay + ""));
|
||||||
|
if(obj==null)return null;
|
||||||
|
return (ArrayList<Long>) obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测房间钻石
|
||||||
|
* @param jedis0
|
||||||
|
* @param session
|
||||||
|
* @param pay
|
||||||
|
* @param opt
|
||||||
|
* @param AA
|
||||||
|
* @param maxPlayers
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static int checkRoomDiamo(Jedis jedis0,String session,int pay) throws Exception {
|
||||||
|
if(pay <=0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int p_diamo = Integer.parseInt(jedis0.hget(session, "diamo"));
|
||||||
|
if(p_diamo<pay) {
|
||||||
|
return ErrorCode.NO_DIAMO;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取session 已在房间
|
||||||
|
* @param jedis0
|
||||||
|
* @param groupId
|
||||||
|
* @param session
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String getOldRoomV2(Jedis jedis0,int groupId,String session,int uid) {
|
||||||
|
String oldRoom = jedis0.hget(session, "room");
|
||||||
|
boolean enter_old = false;
|
||||||
|
if (StringUtil.isNotEmpty(oldRoom)) {
|
||||||
|
enter_old = true;
|
||||||
|
}
|
||||||
|
if (enter_old) {
|
||||||
|
List<String> _list = jedis0.hmget(oldRoom, "status","score_"+uid);
|
||||||
|
String status = _list.get(0);
|
||||||
|
if (StringUtil.isEmpty(status) || status.equals("2") || status.equals("3")) {
|
||||||
|
jedis0.hdel(session, "room");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String s_uid = _list.get(1);
|
||||||
|
if(StringUtil.isNotEmpty(s_uid)) {
|
||||||
|
return oldRoom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除session房间
|
||||||
|
* @param jedis0
|
||||||
|
* @param session_key
|
||||||
|
* @param room_key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean delRoomBySession(Jedis jedis0,String session_key, String room_key) {
|
||||||
|
String cur_room = jedis0.hget(session_key, "room");
|
||||||
|
if (StringUtil.isNotEmpty(cur_room)) {
|
||||||
|
if (cur_room.equals(room_key)) {
|
||||||
|
if(API_VER==1) {
|
||||||
|
jedis0.hdel(session_key, "room", "seat");
|
||||||
|
}else {
|
||||||
|
jedis0.hdel(session_key, "room");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="event_mgr" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://8.138.220.239:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>root</userName>
|
||||||
|
<password>root</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>8</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>2</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="8.138.220.239" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="8.138.220.239" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db2" host="8.138.220.239" password="cssq@2020" port="6379" database="2" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="8.138.220.239" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="8.138.220.239" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="8.138.220.239" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="8.138.220.239" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="8.138.220.239" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
<info name="group1_db15" host="8.138.220.239" password="cssq@2020" port="6379" database="15" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
|
||||||
|
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://8.138.220.239:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>root</userName>
|
||||||
|
<password>root</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>8</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>2</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="8.138.220.239" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="8.138.220.239" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db2" host="8.138.220.239" password="cssq@2020" port="6379" database="2" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="8.138.220.239" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="8.138.220.239" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="8.138.220.239" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="8.138.220.239" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="8.138.220.239" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
<info name="group1_db15" host="8.138.220.239" password="cssq@2020" port="6379" database="15" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
|
||||||
|
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://8.138.220.239:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>root</userName>
|
||||||
|
<password>root</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>8</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>2</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="8.138.220.239" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="8.138.220.239" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db2" host="8.138.220.239" password="cssq@2020" port="6379" database="2" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="8.138.220.239" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="8.138.220.239" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="8.138.220.239" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="8.138.220.239" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="8.138.220.239" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
<info name="group1_db15" host="8.138.220.239" password="cssq@2020" port="6379" database="15" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
|
||||||
|
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.evt</groupId>
|
||||||
|
<artifactId>event_mgr</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<build.type>pro</build.type>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 data_cache -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.data</groupId>
|
||||||
|
<artifactId>data_cache</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-core</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-web</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用redis时导入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用HikariCP时导入 ,自己在项目中添加 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用mysql时导入 ,自己在项目中添加 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.16</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/jdom/jdom -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jdom</groupId>
|
||||||
|
<artifactId>jdom</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.quartz-scheduler</groupId>
|
||||||
|
<artifactId>quartz</artifactId>
|
||||||
|
<version>2.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-webapp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-webapp</artifactId>
|
||||||
|
<version>8.2.0.v20160908</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>ROOT</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<warSourceExcludes>logs/**,config/**</warSourceExcludes>
|
||||||
|
<webResources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>config/</targetPath>
|
||||||
|
<directory>${project.basedir}/build/${build.type}/</directory>
|
||||||
|
</resource>
|
||||||
|
</webResources>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class EventController {
|
||||||
|
private static final String EVENT_TYPE = "E";
|
||||||
|
private static final String EVENT_GID = "gid";
|
||||||
|
private static final String EVENT_UID = "uid";
|
||||||
|
|
||||||
|
public static final int execEvt(String key,boolean isGroupEvt) {
|
||||||
|
int count = 0;
|
||||||
|
do {
|
||||||
|
|
||||||
|
String jsonStr = Redis.use(EventReceiver.CHACHE_KEY).rpop(key);
|
||||||
|
if(StringUtil.isEmpty(jsonStr))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
ITObject data = null;
|
||||||
|
try {
|
||||||
|
data = TObject.newFromJsonData(jsonStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
EventServer.log.error(jsonStr + ":event json error!", e);
|
||||||
|
}
|
||||||
|
int type = 0;
|
||||||
|
int uid = 0;
|
||||||
|
int groupId =0;
|
||||||
|
int reulst = 0;
|
||||||
|
try {
|
||||||
|
type = data.getInt(EVENT_TYPE);
|
||||||
|
|
||||||
|
if(isGroupEvt) {
|
||||||
|
groupId = data.getInt(EVENT_GID);
|
||||||
|
}else {
|
||||||
|
uid = data.getInt(EVENT_UID);
|
||||||
|
}
|
||||||
|
|
||||||
|
IHandler handler = EventServer.eventReceiver.getHandler(type);
|
||||||
|
if(handler!=null) {
|
||||||
|
if(isGroupEvt) {
|
||||||
|
reulst = handler.processGroup(groupId, data);
|
||||||
|
EventServer.log.info(jsonStr + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}else {
|
||||||
|
reulst = handler.process(uid, data);
|
||||||
|
EventServer.log.info(jsonStr + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}
|
||||||
|
if(reulst!=0) {
|
||||||
|
if(reulst == -1) {
|
||||||
|
jsonStr = data.toJson();
|
||||||
|
}
|
||||||
|
Redis.use(EventReceiver.CHACHE_KEY).lpush(key, jsonStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Redis.use("group1_db15").lpush(key, jsonStr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reulst == 0) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
} while(true);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param pay
|
||||||
|
* @param cur_diamo
|
||||||
|
* @param reason
|
||||||
|
* @param gameId
|
||||||
|
* @param groupId
|
||||||
|
* @param pid
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public static final void payDiamo(int uid,int pay,int cur_diamo,int reason,int gameId,int groupId,int pid) throws SQLException{
|
||||||
|
ITArray data = TArray.newInstance();
|
||||||
|
data.addInt(uid);
|
||||||
|
data.addInt(pay);
|
||||||
|
data.addInt(reason);
|
||||||
|
data.addInt(gameId);
|
||||||
|
data.addInt(groupId);
|
||||||
|
data.addInt(cur_diamo);
|
||||||
|
DataBase.use().prepareCallNonResult("sp_transfer_diamo", data);
|
||||||
|
if(groupId>0) {
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
CountUtil.countLog(String.format("g%s:diamo_cost",groupId), pay, jedis9);
|
||||||
|
if(pid > 0) {
|
||||||
|
CountUtil.countLog(String.format("g%s:diamo_cost:p%s",groupId,pid), pay, jedis9,false,true);
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int execSql(String key) {
|
||||||
|
int count = 0;
|
||||||
|
do {
|
||||||
|
String str = Redis.use(EventReceiver.CHACHE_KEY).rpop(key);
|
||||||
|
if(str==null || str.equalsIgnoreCase("null")) {
|
||||||
|
|
||||||
|
}else {
|
||||||
|
EventServer.log.info( " execsql:"+str);
|
||||||
|
|
||||||
|
}
|
||||||
|
if(StringUtil.isEmpty(str))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reulst = 0;
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
int type = Integer.parseInt(str.substring(0,1));
|
||||||
|
String sql = str.substring(1);
|
||||||
|
if(type==1) {
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
EventServer.log.info(sql + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}else {
|
||||||
|
DataBase.use().executeCall(sql, false);
|
||||||
|
EventServer.log.info(sql + " use time:" + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Redis.use("group1_db15").lpush(key, str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reulst == 0) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
} while(true);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class EventReceiver {
|
||||||
|
private final static String GROUP_EVT_KEY = "evt_group_";
|
||||||
|
private final static String EVT_KEY = "event_";
|
||||||
|
private final static String EVT_DB_KEY = "evt_db_";
|
||||||
|
public final static String CHACHE_KEY = "group1_db8";
|
||||||
|
|
||||||
|
Map<Integer, IHandler> handlerMap;
|
||||||
|
volatile boolean run;
|
||||||
|
|
||||||
|
public EventReceiver() {
|
||||||
|
handlerMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
run = true;
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
new GroupRunnable(i, this, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
new GroupRunnable(i, this, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
new GroupRunnable(i, this, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy() {
|
||||||
|
run = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
IHandler getHandler(int type) {
|
||||||
|
IHandler handler = handlerMap.get(type);
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class GroupRunnable implements Runnable {
|
||||||
|
private Logger log = Logger.getLogger(GroupRunnable.class);
|
||||||
|
EventReceiver receiver;
|
||||||
|
int type;
|
||||||
|
int id;
|
||||||
|
Thread thread;
|
||||||
|
|
||||||
|
public GroupRunnable(int id, EventReceiver receiver, int type) {
|
||||||
|
this.receiver = receiver;
|
||||||
|
this.type = type;
|
||||||
|
this.id = id;
|
||||||
|
this.thread = new Thread(this, id + "");
|
||||||
|
this.thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (receiver.run) {
|
||||||
|
int count=0;
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
count = EventController.execEvt(GROUP_EVT_KEY + this.id, true);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
count = EventController.execEvt(EVT_KEY + id, false);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
count = EventController.execSql(EVT_DB_KEY+id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
long useTime = (System.currentTimeMillis() - startTime);
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
EventServer.log.info("handle event:" + count + " use time:" + useTime + " ms");
|
||||||
|
}
|
||||||
|
if (useTime >= 30 || count >= 30)
|
||||||
|
{
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
|
else if (count > 0){
|
||||||
|
Thread.sleep(5);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Thread.sleep(20);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import static org.quartz.CronScheduleBuilder.cronSchedule;
|
||||||
|
import static org.quartz.JobBuilder.newJob;
|
||||||
|
import static org.quartz.TriggerBuilder.newTrigger;
|
||||||
|
|
||||||
|
import com.evt.mgr.job.CleanGroupLogJob;
|
||||||
|
import org.quartz.CronTrigger;
|
||||||
|
import org.quartz.JobDetail;
|
||||||
|
import org.quartz.Scheduler;
|
||||||
|
import org.quartz.SchedulerFactory;
|
||||||
|
import org.quartz.impl.StdSchedulerFactory;
|
||||||
|
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.evt.mgr.handler.HandlerGroupMemberRound;
|
||||||
|
import com.evt.mgr.handler.HandlerGroupRound;
|
||||||
|
import com.evt.mgr.handler.HandlerHpConsume;
|
||||||
|
import com.evt.mgr.handler.HandlerLose;
|
||||||
|
import com.evt.mgr.handler.HandlerOver;
|
||||||
|
import com.evt.mgr.handler.HandlerPay;
|
||||||
|
import com.evt.mgr.handler.HandlerWin;
|
||||||
|
import com.evt.mgr.job.CleanTimeOutRoomJob;
|
||||||
|
import com.taurus.core.routes.Extension;
|
||||||
|
import com.taurus.core.routes.Routes;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class EventServer extends Extension{
|
||||||
|
static EventReceiver eventReceiver;
|
||||||
|
public static Logger log;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
log = Logger.getLogger(EventServer.class);
|
||||||
|
eventReceiver = new EventReceiver();
|
||||||
|
initHandler();
|
||||||
|
|
||||||
|
initJob();
|
||||||
|
|
||||||
|
eventReceiver.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configRoute(Routes me) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initJob() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("clean invalid room, no diamond");
|
||||||
|
|
||||||
|
SchedulerFactory sf = new StdSchedulerFactory();
|
||||||
|
Scheduler sched = sf.getScheduler();
|
||||||
|
|
||||||
|
JobDetail job = newJob(CleanTimeOutRoomJob.class).withIdentity("clean_group_room", "group").build();
|
||||||
|
CronTrigger trigger= newTrigger().withIdentity("clean_group_room_trigger", "group").withSchedule(cronSchedule("0 0 5 * * ? ")).build();
|
||||||
|
sched.scheduleJob(job, trigger);
|
||||||
|
|
||||||
|
job = newJob(CleanTimeOutRoomJob.class).withIdentity("clean_invalid_room", "group").build();
|
||||||
|
trigger= newTrigger().withIdentity("clean_invalid_room_trigger", "group").withSchedule(cronSchedule("0 30 5 * * ? ")).build();
|
||||||
|
sched.scheduleJob(job, trigger);
|
||||||
|
|
||||||
|
JobDetail log_job = newJob(CleanGroupLogJob.class).withIdentity("clean_group_member_log", "group").build();
|
||||||
|
CronTrigger log_trigger= newTrigger().withIdentity("clean_group_member_log_trigger", "group").withSchedule(cronSchedule("0 0 0/1 * * ? ")).build();
|
||||||
|
sched.scheduleJob(log_job, log_trigger);
|
||||||
|
|
||||||
|
log_job = newJob(CleanGroupLogJob.class).withIdentity("clean_group_hp_log", "group").build();
|
||||||
|
log_trigger= newTrigger().withIdentity("clean_group_hp_log_trigger", "group").withSchedule(cronSchedule("0 0 0/1 * * ? ")).build();
|
||||||
|
sched.scheduleJob(log_job, log_trigger);
|
||||||
|
|
||||||
|
log_job = newJob(CleanGroupLogJob.class).withIdentity("clean_rec_room_log", "group").build();
|
||||||
|
log_trigger= newTrigger().withIdentity("clean_rec_room_log_trigger", "group").withSchedule(cronSchedule("0 0 0/1 * * ? ")).build();
|
||||||
|
sched.scheduleJob(log_job, log_trigger);
|
||||||
|
|
||||||
|
sched.start();
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initHandler() {
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_OVER, new HandlerOver());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_LOSE, new HandlerLose());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_WIN, new HandlerWin());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_PAY, new HandlerPay(ConsumeCode.DIAMO_JOIN_ROOM,true));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_BACK_PAY, new HandlerPay(ConsumeCode.DIAMO_REFUND,false));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_ROOM, new HandlerPay(ConsumeCode.DIAMO_AGENT_ROOM,true));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_CREATE_ROOM, new HandlerPay(ConsumeCode.DIAMO_CREAT_ROOM,true));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_MAIL, new HandlerPay(ConsumeCode.DIAMO_MAIL,false));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_WHEEL, new HandlerPay(ConsumeCode.DIAMO_WHEEL,false));
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_ROUND, new HandlerGroupRound());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_MEMBER_ROUND, new HandlerGroupMemberRound());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_GROUP_HP, new HandlerHpConsume());
|
||||||
|
eventReceiver.handlerMap.put(EventType.REDIS_EVENT_ADDPAY, new HandlerPay(ConsumeCode.DIAMO_ADD,false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
eventReceiver.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
public class GroupPublisherService {
|
||||||
|
public static final String CHANNEL_NAME = "mgr_group";
|
||||||
|
|
||||||
|
private static final String CMD_UPDATE_MEMBER = "update_member";
|
||||||
|
|
||||||
|
private static final String CMD_DEL_ROOM = "del_room";
|
||||||
|
|
||||||
|
private final static String EVT_TYPE = "E";
|
||||||
|
private final static String EVT_UID = "uid";
|
||||||
|
|
||||||
|
private final static String EVT_KEY = "event_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1 hp 2 等级 3 合伙人等级
|
||||||
|
*
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public static void updateMemberEvt(int groupId, int uid, int type, int value) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putInt("uid", uid);
|
||||||
|
data.putInt("type", type);
|
||||||
|
data.putInt("value", value);
|
||||||
|
data.putString("cmd", CMD_UPDATE_MEMBER);
|
||||||
|
Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void delRoomEvt(int groupId, String roomid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putString("roomid", roomid);
|
||||||
|
data.putString("cmd", CMD_DEL_ROOM);
|
||||||
|
Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返还钻石
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param pay
|
||||||
|
* @param groupId
|
||||||
|
*/
|
||||||
|
public static void refundDiamo(int uid, int pay, int groupId, int gameId) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", -pay);
|
||||||
|
data.putInt("game", gameId);
|
||||||
|
if (groupId > 0) {
|
||||||
|
data.putInt("group", groupId);
|
||||||
|
}
|
||||||
|
//sendEvt(EventType.REDIS_EVENT_BACK_PAY, uid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendEvt(int type, int uid, ITObject data) {
|
||||||
|
int id = uid % 10;
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(EventReceiver.CHACHE_KEY).lpush(EVT_KEY + id, data.toJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
public interface IHandler {
|
||||||
|
|
||||||
|
public int process(int uid,ITObject param) throws Exception;
|
||||||
|
|
||||||
|
public int processGroup(int groupId,ITObject param) throws Exception;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,236 @@
|
||||||
|
package com.evt.mgr;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
public static final void countValidAndTotal(Jedis jedis10, Pipeline pipeline9, int uid, int groupId, int pid,
|
||||||
|
int valid_count, int valid_diamo, int all_count,int playerCount) {
|
||||||
|
|
||||||
|
if (valid_count > 0) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:valid_round", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_count, pipeline9);
|
||||||
|
CountUtil.countLogByDay30(gmv + "_self", valid_count, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid_diamo > 0) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:valid_diamo", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_diamo, pipeline9);
|
||||||
|
CountUtil.countLogByDay30(gmv + "_self", valid_diamo, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
String gmr = String.format("g{%s}:m%s:round_log", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(gmr, 1, pipeline9, true);
|
||||||
|
CountUtil.countLogByDay30(gmr + "_self", 1, pipeline9, true);
|
||||||
|
|
||||||
|
List<Integer> temp = Utility.getMemberParents(jedis10, groupId, uid, true);
|
||||||
|
if (temp != null && temp.size() > 0) {
|
||||||
|
|
||||||
|
if (valid_count > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < temp.size(); ++i) {
|
||||||
|
|
||||||
|
int par = temp.get(i);
|
||||||
|
if (par != uid) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:valid_round", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_count, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
String gmvp = String.format("g{%s}:m%s:valid_round:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmvp, valid_count, pipeline9);
|
||||||
|
|
||||||
|
String gmvp2 = String.format("g{%s}:m%s:valid_round2:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmvp2, valid_count, pipeline9);
|
||||||
|
|
||||||
|
// boolean add_uid = (uid == par || i == 0);
|
||||||
|
// if (add_uid == true) {
|
||||||
|
String gmv = String.format("g{%s}:m%s:d_valid_round", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmv, valid_count, pipeline9);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < temp.size(); ++i) {
|
||||||
|
if (all_count > 0) {
|
||||||
|
int par = temp.get(i);
|
||||||
|
if (par != uid) {
|
||||||
|
gmr = String.format("g{%s}:m%s:round_log", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmr, 1, pipeline9, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
gmr = String.format("g{%s}:m%s:valid_diamo:p%s", groupId, par, pid);
|
||||||
|
CountUtil.countLogByDay30(gmr, valid_diamo, pipeline9);
|
||||||
|
|
||||||
|
gmr = String.format("g{%s}:m%s:all_count:p%s", groupId, par, pid);
|
||||||
|
|
||||||
|
CountUtil.countLogByDay30(gmr, all_count, pipeline9, true);
|
||||||
|
|
||||||
|
// boolean add_uid = (uid == par || i == 0);
|
||||||
|
// if (add_uid == true) {
|
||||||
|
gmr = String.format("g{%s}:m%s:d_round_log", groupId, par);
|
||||||
|
CountUtil.countLogByDay30(gmr, 1, pipeline9, true);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void countValidAndTotal(Pipeline pipeline9, ITArray playerList, int groupId, int pid,
|
||||||
|
int valid_count, int valid_diamo, int all_count, int win_player) {
|
||||||
|
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
for (int i = 0; i < playerList.size(); i++) {
|
||||||
|
|
||||||
|
int uid = playerList.getInt(i);
|
||||||
|
EventServer.log.info("uid:" + uid);
|
||||||
|
EventServer.log.info("win_player:" + win_player);
|
||||||
|
|
||||||
|
if (win_player == uid) {
|
||||||
|
// 大赢家增加场次
|
||||||
|
EventServer.log.info("win_player:" + uid);
|
||||||
|
countValidAndTotal(jedis10, pipeline9, uid, groupId, pid, valid_count, valid_diamo, all_count,1);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
EventServer.log.info("lost_player:" + uid);
|
||||||
|
countValidAndTotal(jedis10, pipeline9, uid, groupId, pid, 0, valid_diamo, all_count,1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计合伙人局数和赢
|
||||||
|
*
|
||||||
|
* @param jedis9
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @param win
|
||||||
|
*/
|
||||||
|
public static final void countRoundWin(Pipeline pipeline9, int groupId, int pid, int uid, boolean win, int score) {
|
||||||
|
List<Integer> par_list = null;
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
par_list = Utility.getMemberParents(jedis10, groupId, uid, true);
|
||||||
|
|
||||||
|
Pipeline pipeline10 = jedis10.pipelined();
|
||||||
|
|
||||||
|
if (par_list == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String key = String.format("g{%s}:m%s:total_win", groupId, uid);
|
||||||
|
CountUtil.countLogByDay30(key, score, pipeline9);
|
||||||
|
CountUtil.countLogByDay30(key + "_self", score, pipeline9);
|
||||||
|
|
||||||
|
for (int i = 0; i < par_list.size(); ++i) {
|
||||||
|
|
||||||
|
int par = par_list.get(i);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == par || i == 0);
|
||||||
|
if (add_uid == true) {
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:d_total_win", groupId, par);
|
||||||
|
EventServer.log.info("par:" + par+"获得:"+score);
|
||||||
|
|
||||||
|
CountUtil.countLogByDay30(key, score, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mlk = GroupCache.genMemberListKey(groupId, par);
|
||||||
|
pipeline10.sadd(mlk, uid + "");
|
||||||
|
|
||||||
|
if (par != uid) {
|
||||||
|
key = String.format("g{%s}:m%s:total_win", groupId, par);
|
||||||
|
EventServer.log.info("par:" + par+"获得:"+score);
|
||||||
|
|
||||||
|
CountUtil.countLogByDay30(key, score, pipeline9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline10.sync();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计合伙人体力值消耗,输赢统计
|
||||||
|
*
|
||||||
|
* @param jedis9
|
||||||
|
* @param groupId
|
||||||
|
* @param uid
|
||||||
|
* @param pump
|
||||||
|
* @param hp
|
||||||
|
*/
|
||||||
|
public static final void countHpconsume(Pipeline pipeline9, int groupId, int uid, int pump, int hp) {
|
||||||
|
List<Integer> par_list = null;
|
||||||
|
Jedis jedis10 = Redis.use("group1_db10").getJedis();
|
||||||
|
try {
|
||||||
|
par_list = Utility.getMemberParents(jedis10, groupId, uid, true);
|
||||||
|
} finally {
|
||||||
|
jedis10.close();
|
||||||
|
}
|
||||||
|
if (par_list == null)
|
||||||
|
return;
|
||||||
|
String key;
|
||||||
|
|
||||||
|
if (hp != 0) {
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:hp_consume_log", groupId, uid);
|
||||||
|
CountUtil.countLogByDay(key, hp, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
int day = DateUtils.getBeginDay();
|
||||||
|
boolean self = par_list.get(0) == uid;
|
||||||
|
for (int i = 0; i < par_list.size(); ++i) {
|
||||||
|
|
||||||
|
int par = par_list.get(i);
|
||||||
|
boolean add_uid = i == 0 || (i <= 1 && self);
|
||||||
|
|
||||||
|
if (pump > 0) {
|
||||||
|
|
||||||
|
key = String.format("g%s:hp_cost:par%s_%s", groupId, par, day);
|
||||||
|
pipeline9.hincrBy(key, "total", pump);
|
||||||
|
if (add_uid) {
|
||||||
|
pipeline9.hincrBy(key, uid + "", pump);
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline9.expire(key, 3600 * 24 * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hp != 0) {
|
||||||
|
|
||||||
|
if (uid != par) {
|
||||||
|
key = String.format("g{%s}:m%s:hp_consume_log", groupId, par);
|
||||||
|
CountUtil.countLogByDay(key, hp, pipeline9);
|
||||||
|
}
|
||||||
|
|
||||||
|
key = String.format("g%s:hp_consume:par%s_%s", groupId, par, day);
|
||||||
|
pipeline9.hincrBy(key, "total", hp);
|
||||||
|
if (add_uid) {
|
||||||
|
pipeline9.hincrBy(key, uid + "", hp);
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline9.expire(key, 3600 * 24 * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.EventServer;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.evt.mgr.Utils;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class HandlerGroupMemberRound implements IHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean addMemberLog(int gid, int pid, int uid, int score, int win, int time, int perfectRound,
|
||||||
|
int valid_count) throws SQLException {
|
||||||
|
String sql = String.format("{call sp_add_member_log(%s,%s,%s,%s,%s,%s,%s,%s)}", gid, pid, uid, score, win, time,
|
||||||
|
perfectRound, valid_count);
|
||||||
|
Utility.evtdbLog(gid, 2, sql);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
// EventServer.log.info("processGroup begin:" + param);
|
||||||
|
|
||||||
|
int pid = param.getInt("pid");
|
||||||
|
int score = param.getInt("score");
|
||||||
|
int uid = param.getInt("uid");
|
||||||
|
int win = param.getInt("win");
|
||||||
|
int time = DateUtils.getBeginDay();
|
||||||
|
int perfectRound = param.getInt("perfect_round");
|
||||||
|
int valid_count = param.getInt("valid_count");
|
||||||
|
int pump = param.getInt("pump");
|
||||||
|
int pumpBase = 0;
|
||||||
|
if (pump == 0) {
|
||||||
|
pumpBase = param.getInt("pumpBase");
|
||||||
|
}
|
||||||
|
int pumpReal = param.getInt("pumpReal");
|
||||||
|
|
||||||
|
int cur_hp = param.getInt("cur_hp");
|
||||||
|
int xipai_total = param.getInt("xi_pai_total");
|
||||||
|
String roomid = param.getString("room");
|
||||||
|
int cur_time = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
if (param.containsKey("time")) {
|
||||||
|
cur_time = param.getInt("time");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITArray param1 = TArray.newInstance();
|
||||||
|
// param1.addInt(groupId);
|
||||||
|
// param1.addInt(pid);
|
||||||
|
// param1.addInt(uid);
|
||||||
|
// param1.addInt(score - pump - xipai_total);
|
||||||
|
// param1.addInt(win);
|
||||||
|
// param1.addInt(time);
|
||||||
|
// param1.addInt(perfectRound);
|
||||||
|
// param1.addInt(valid_count);
|
||||||
|
// DataBase.use().prepareCallNonResult("sp_add_member_log", param1);
|
||||||
|
addMemberLog(groupId, pid, uid, score > 0 ? score - pumpReal - xipai_total : score - xipai_total, win, time,
|
||||||
|
perfectRound, valid_count);
|
||||||
|
EventServer.log.info("pumpReal end:" + pumpReal);
|
||||||
|
|
||||||
|
String sql = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||||
|
groupId, uid, ConsumeCode.HP_PUMP_TOTAL,
|
||||||
|
score > 0 ? score - pumpReal - xipai_total : score - xipai_total - pumpBase, cur_hp, pid, roomid,
|
||||||
|
(int) (cur_time));
|
||||||
|
Utility.evtdb(groupId, 1, sql);
|
||||||
|
// DataBase.use().executeUpdate(sql);
|
||||||
|
|
||||||
|
String gmrp_key = String.format("g%s:m%s:round:p%s", groupId, uid, pid);
|
||||||
|
String gmr_key = String.format("g%s:m%s:round", groupId, uid);
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CountUtil.countLog(gmrp_key, 1, jedis9);
|
||||||
|
CountUtil.countLog(gmr_key, 1, jedis9);
|
||||||
|
|
||||||
|
Pipeline pipeline9 = jedis9.pipelined();
|
||||||
|
if(score>0) {
|
||||||
|
Utils.countRoundWin(pipeline9, groupId, pid, uid, win == 1, score - pumpReal);
|
||||||
|
}else {
|
||||||
|
Utils.countRoundWin(pipeline9, groupId, pid, uid, win == 1, score);
|
||||||
|
|
||||||
|
}
|
||||||
|
pipeline9.sync();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.evt.mgr.Utils;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class HandlerGroupRound implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
int pid = param.getInt("pid");
|
||||||
|
int valid = param.getInt("valid");
|
||||||
|
ITArray playerList = param.getTArray("player_list");
|
||||||
|
int win_player = param.getInt("win_player");
|
||||||
|
|
||||||
|
int valid_count = param.getInt("valid_count");
|
||||||
|
int valid_diamo = 0;
|
||||||
|
int all_count = 0;
|
||||||
|
if (param.containsKey("valid_diamo"))
|
||||||
|
{
|
||||||
|
valid_diamo = param.getInt("valid_diamo");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.containsKey("all_count"))
|
||||||
|
{
|
||||||
|
all_count = param.getInt("all_count");
|
||||||
|
}
|
||||||
|
|
||||||
|
String rp_key = String.format("g%s:round:p%s",groupId,pid);
|
||||||
|
String round_key = String.format("g%s:round",groupId);
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
Pipeline pipeline9 = jedis9.pipelined();
|
||||||
|
|
||||||
|
CountUtil.countLog(rp_key, playerList.size(), pipeline9,false,true);
|
||||||
|
CountUtil.countLog(round_key, playerList.size(), pipeline9,true);
|
||||||
|
|
||||||
|
if(valid == 1) {
|
||||||
|
|
||||||
|
String valid_key = String.format("g%s:valid_room",groupId);
|
||||||
|
String p_valid_key = String.format("g%s:valid_room:p%s",groupId,pid);
|
||||||
|
CountUtil.countLogByDay(p_valid_key, 1, pipeline9,true);
|
||||||
|
CountUtil.countLog(valid_key, 1, pipeline9);
|
||||||
|
}else {
|
||||||
|
|
||||||
|
String no_valid_key = String.format("g%s:no_valid_room",groupId);
|
||||||
|
String p_no_valid_key = String.format("g%s:no_valid_room:p%s",groupId,pid);
|
||||||
|
CountUtil.countLogByDay(p_no_valid_key, playerList.size(), pipeline9,true);
|
||||||
|
CountUtil.countLog(no_valid_key, playerList.size(), pipeline9);
|
||||||
|
}
|
||||||
|
Utils.countValidAndTotal(pipeline9, playerList, groupId, pid, valid_count, valid_diamo, all_count,win_player);
|
||||||
|
|
||||||
|
pipeline9.sync();
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,650 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElementDecl.GLOBAL;
|
||||||
|
|
||||||
|
import com.data.bean.GroupBean;
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.CountUtil;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.EventServer;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class HandlerHpConsume implements IHandler {
|
||||||
|
static Logger log = Logger.getLogger(HandlerHpConsume.class);
|
||||||
|
final static String DB = "group1_db10";
|
||||||
|
|
||||||
|
private static boolean hpConsume(int gid, int uid, int pid, int hp, int cur_hp, int reason, String roomid, int time,
|
||||||
|
String desc) throws SQLException {
|
||||||
|
String sql = String.format("{call sp_update_hp(%s,%s,%s,%s,%s,%s,'%s',%s,'%s')}", gid, uid, hp, cur_hp, reason,
|
||||||
|
pid, roomid, time, desc);
|
||||||
|
Utility.evtdb(gid, 2, sql);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void to_reward(Pipeline pipeline, int uid, String prs, int rewardType, int valueType, int real_pump,
|
||||||
|
int pump, int groupId, int pid, String roomid, int time, int max_player) throws Exception {
|
||||||
|
EventServer.log.info("to_reward begin:" + uid);
|
||||||
|
EventServer.log.info("prs:" + prs);
|
||||||
|
|
||||||
|
int useValue = 0;
|
||||||
|
if (StringUtil.isNotEmpty(prs)) {
|
||||||
|
|
||||||
|
int round = 100 / max_player;
|
||||||
|
ITArray list = TArray.newFromJsonData(prs);
|
||||||
|
|
||||||
|
for (int i = list.size() - 1; i >= 0; --i) {
|
||||||
|
|
||||||
|
ITObject obj1 = list.getTObject(i);
|
||||||
|
int parentId = obj1.getInt("p");
|
||||||
|
int rewardPercent = 0;
|
||||||
|
if (obj1.containsKey("r")) {
|
||||||
|
rewardPercent = obj1.getInt("r");
|
||||||
|
}
|
||||||
|
int rv = 0;
|
||||||
|
if (i > 0) {
|
||||||
|
ITObject obj2 = list.getTObject(i - 1);
|
||||||
|
if (!obj2.containsKey("r")) {
|
||||||
|
rv = rewardPercent - 0;
|
||||||
|
} else {
|
||||||
|
rv = rewardPercent - obj2.getInt("r");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
rv = rewardPercent;
|
||||||
|
}
|
||||||
|
int reward_value = rv;
|
||||||
|
EventServer.log.info("rewardType:" + rewardType);
|
||||||
|
EventServer.log.info("valueType:" + valueType);
|
||||||
|
EventServer.log.info("reward_value:" + reward_value);
|
||||||
|
|
||||||
|
if (valueType == 1) {
|
||||||
|
// EventServer.log.info("reward_value:" + reward_value);
|
||||||
|
reward_value = Math.round(pump * (rv / 100f));
|
||||||
|
} else {
|
||||||
|
if (rewardType == 2) {
|
||||||
|
reward_value = reward_value / max_player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EventServer.log.info("reward_value:" + reward_value);
|
||||||
|
if (reward_value > 1000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (reward_value < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId, parentId);
|
||||||
|
Redis.use(DB).incrBy(key, reward_value);
|
||||||
|
String rewardsql = String.format(
|
||||||
|
"update group_member set reward_hp = %s where uid = %s AND groupId = %s",
|
||||||
|
Redis.use(DB).get(key), parentId, groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
|
||||||
|
// Redis.use(DB).incrBy(all_key, reward_value);
|
||||||
|
useValue += reward_value;
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s", groupId, parentId),
|
||||||
|
reward_value, jedis9);
|
||||||
|
EventServer.log.info("ConsumeCode.HP_PARTNER_REWARD:" + reward_value);
|
||||||
|
|
||||||
|
String sql = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round, info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||||
|
groupId, parentId, ConsumeCode.HP_PARTNER_REWARD, reward_value, cur_hp, pid, roomid, time,
|
||||||
|
round, desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
} finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:reward_log", groupId, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:reward_log", groupId, parentId, pid);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, uid, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == parentId || i == 0);
|
||||||
|
// if (add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_reward", groupId, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, obj1.getInt("r"), pipeline);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
|
||||||
|
for (int j = i - 1; j >= 0; j--) {
|
||||||
|
|
||||||
|
ITObject obj2 = list.getTObject(j);
|
||||||
|
int temp = obj2.getInt("p");
|
||||||
|
if (temp != uid) {
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, temp, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, reward_value, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 某个玩法的抽水总值
|
||||||
|
CountUtil.countLogByDay30(String.format("g%s:hp_cost:m%s:p%s", groupId, parentId, pid), pump, pipeline);
|
||||||
|
|
||||||
|
CountUtil.countLogByDay30(String.format("g%s:hp_reward", groupId), reward_value, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
if (gb != null) {
|
||||||
|
|
||||||
|
int round = 100 / max_player;
|
||||||
|
int leftValue = real_pump - useValue;
|
||||||
|
if (leftValue < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventServer.log.info("群主抽水开始:" + leftValue);
|
||||||
|
EventServer.log.info("群主抽水开始:" + real_pump + "-" + useValue);
|
||||||
|
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId, gb.owner);
|
||||||
|
Redis.use(DB).incrBy(key, leftValue);
|
||||||
|
String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s",
|
||||||
|
Redis.use(DB).get(key), gb.owner, groupId);
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
|
||||||
|
// Redis.use(DB).incrBy(all_key, leftValue);
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:reward_log", groupId, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:reward_log", groupId, gb.owner, pid);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, uid, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == gb.owner);
|
||||||
|
if (add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_reward", groupId, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
}
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
EventServer.log.info("leftValue:" + leftValue);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s", groupId, gb.owner), leftValue,
|
||||||
|
jedis9);
|
||||||
|
String sql = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||||
|
groupId, gb.owner, ConsumeCode.HP_PARTNER_REWARD, leftValue, cur_hp, pid, roomid, time, round,
|
||||||
|
desc);
|
||||||
|
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
EventServer.log.info("群主抽水结束:" + leftValue);
|
||||||
|
EventServer.log.info("群主抽水结束:" + real_pump + "-" + useValue);
|
||||||
|
log.info("盟主分层后积分:" + Redis.use(DB).get(key));
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EventServer.log.info("to_reward end:" + uid);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void to_reward_base(Pipeline pipeline, int uid, String prs, int pump, int groupId, boolean isPumpBaseWin)
|
||||||
|
throws Exception {
|
||||||
|
EventServer.log.info("to_reward_base begin:" + uid);
|
||||||
|
EventServer.log.info("prs:" + prs);
|
||||||
|
EventServer.log.info("pump:" + pump);
|
||||||
|
|
||||||
|
if (StringUtil.isNotEmpty(prs)) {
|
||||||
|
|
||||||
|
ITArray list = TArray.newFromJsonData(prs);
|
||||||
|
|
||||||
|
for (int i = list.size() - 1; i >= 0; --i) {
|
||||||
|
|
||||||
|
ITObject obj1 = list.getTObject(i);
|
||||||
|
int parentId = obj1.getInt("p");
|
||||||
|
int rewardPercent = 0;
|
||||||
|
if (obj1.containsKey("r")) {
|
||||||
|
rewardPercent = obj1.getInt("r");
|
||||||
|
}
|
||||||
|
int rv = 0;
|
||||||
|
if (i > 0) {
|
||||||
|
ITObject obj2 = list.getTObject(i - 1);
|
||||||
|
if (!obj2.containsKey("r")) {
|
||||||
|
rv = rewardPercent - 0;
|
||||||
|
} else {
|
||||||
|
rv = rewardPercent - obj2.getInt("r");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
rv = rewardPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
|
||||||
|
// Redis.use(DB).incrBy(all_key, reward_value);
|
||||||
|
if (!isPumpBaseWin) {
|
||||||
|
String key = String.format("g{%s}:m%s:total_win", groupId, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, pump, pipeline);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void xipai_to_reward(Pipeline pipeline, int uid, String prs, int rewardType, int valueType, int real_pump,
|
||||||
|
int pump, int groupId, int pid, String roomid, int time, int max_player) throws Exception {
|
||||||
|
|
||||||
|
int useValue = 0;
|
||||||
|
if (StringUtil.isNotEmpty(prs)) {
|
||||||
|
|
||||||
|
ITArray list = TArray.newFromJsonData(prs);
|
||||||
|
|
||||||
|
for (int i = list.size() - 1; i >= 0; --i) {
|
||||||
|
|
||||||
|
ITObject obj1 = list.getTObject(i);
|
||||||
|
int parentId = obj1.getInt("p");
|
||||||
|
int rewardPercent = 0;
|
||||||
|
if (obj1.containsKey("r")) {
|
||||||
|
rewardPercent = obj1.getInt("r");
|
||||||
|
}
|
||||||
|
int rv = 0;
|
||||||
|
if (i > 0) {
|
||||||
|
ITObject obj2 = list.getTObject(i - 1);
|
||||||
|
if (!obj2.containsKey("r")) {
|
||||||
|
rv = rewardPercent - 0;
|
||||||
|
} else {
|
||||||
|
rv = rewardPercent - obj2.getInt("r");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
rv = rewardPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
|
||||||
|
// Redis.use(DB).incrBy(all_key, reward_value);
|
||||||
|
String key = String.format("g{%s}:m%s:total_win", groupId, parentId);
|
||||||
|
CountUtil.countLogByDay30(key, -real_pump, pipeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("洗牌分给到盟主");
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
if (gb != null) {
|
||||||
|
int round = 100 / 2;
|
||||||
|
int leftValue = real_pump - useValue;
|
||||||
|
String key = String.format("g{%s}:m%s:reward_hp", groupId, gb.owner);
|
||||||
|
Redis.use(DB).incrBy(key, leftValue);
|
||||||
|
String rewardsql = String.format(
|
||||||
|
"update group_member set reward_hp=reward_hp+ %s where uid = %s AND groupId = %s", leftValue,
|
||||||
|
gb.owner, groupId);
|
||||||
|
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
|
||||||
|
// String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s",
|
||||||
|
// Redis.use(DB).get(key), gb.owner, groupId);
|
||||||
|
// Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
log.info("盟主洗牌后积分:" + Redis.use(DB).get(key));
|
||||||
|
|
||||||
|
// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
|
||||||
|
// Redis.use(DB).incrBy(all_key, leftValue);
|
||||||
|
// 记录代理每天的推广奖励
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log", groupId, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
key = String.format("g{%s}:m%s:p%s:xipai_reward_log", groupId, gb.owner, pid);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
// 记录每个人对上级的推广奖励是多少
|
||||||
|
key = String.format("g{%s}:m%s:xipai_reward_log_to:par%s", groupId, uid, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
|
||||||
|
boolean add_uid = (uid == gb.owner);
|
||||||
|
if (add_uid == true) {
|
||||||
|
key = String.format("g{%s}:m%s:d_xipai_reward", groupId, gb.owner);
|
||||||
|
CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
}
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
String desc = "" + uid;
|
||||||
|
long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s", groupId, gb.owner), leftValue,
|
||||||
|
jedis9);
|
||||||
|
String sql = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||||
|
groupId, gb.owner, ConsumeCode.HP_PARTNER_XIPAI_REWARD, leftValue, cur_hp, pid, roomid, time,
|
||||||
|
round, desc);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
} finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void to_mengzhu_reward(Pipeline pipeline, int uid, String prs,int rewardType, int valueType, int real_pump, int pump,int groupId,int pid,String roomid,int time,int max_player) throws Exception {
|
||||||
|
// GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
// if (gb != null) {
|
||||||
|
// int round = 100 / max_player;
|
||||||
|
// int leftValue = real_pump;
|
||||||
|
// String key = String.format("g{%s}:m%s:reward_hp", groupId,gb.owner);
|
||||||
|
// Redis.use(DB).incrBy(key, leftValue);
|
||||||
|
// String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), gb.owner,groupId);
|
||||||
|
// Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
// //String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
|
||||||
|
// //Redis.use(DB).incrBy(all_key, leftValue);
|
||||||
|
// // 记录代理每天的推广奖励
|
||||||
|
// CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
//
|
||||||
|
// key = String.format("g{%s}:m%s:reward_log", groupId,gb.owner);
|
||||||
|
// CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
//
|
||||||
|
// key = String.format("g{%s}:m%s:p%s:reward_log", groupId,gb.owner,pid);
|
||||||
|
// CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
//
|
||||||
|
// // 记录每个人对上级的推广奖励是多少
|
||||||
|
// key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,uid, gb.owner);
|
||||||
|
// CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
//
|
||||||
|
// boolean add_uid = (uid == gb.owner);
|
||||||
|
// if(add_uid == true) {
|
||||||
|
// key = String.format("g{%s}:m%s:d_reward", groupId,gb.owner);
|
||||||
|
// CountUtil.countLogByDay30(key, leftValue, pipeline);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
// try {
|
||||||
|
// String desc = "" + uid;
|
||||||
|
// long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,gb.owner), leftValue, jedis9);
|
||||||
|
// String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
|
||||||
|
// + "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,gb.owner,ConsumeCode.HP_PARTNER_REWARD,leftValue,cur_hp,pid,roomid,time,round,desc);
|
||||||
|
// DataBase.use().executeUpdate(sql);
|
||||||
|
// }finally {
|
||||||
|
// jedis9.close();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
int uid = param.getInt("uid");
|
||||||
|
EventServer.log.info("jiesuan processGroup begin:" + param);
|
||||||
|
|
||||||
|
try {
|
||||||
|
int hp = param.getInt("hp");
|
||||||
|
// int cur_hp = param.getInt("cur_hp");
|
||||||
|
//查询mysql的hp
|
||||||
|
String hpSql = String.format(
|
||||||
|
"SELECT hp FROM `group_member` WHERE uid=%s and groupId=%s",
|
||||||
|
uid,groupId);
|
||||||
|
|
||||||
|
ITArray arr = DataBase.use().executeQueryByTArray(hpSql);
|
||||||
|
int cur_hp = arr.getTObject(0).getInt("hp").intValue();
|
||||||
|
boolean is_pump = param.containsKey("pump");
|
||||||
|
int pump = 0;// 分成抽水
|
||||||
|
int pumpReal = 0;// 真实抽水
|
||||||
|
int pumpBase = 0;// 保底抽水
|
||||||
|
int pumpBaseWin = 0;// 大赢家保底抽水
|
||||||
|
int hpReal = 0;// 大赢家保底抽水
|
||||||
|
|
||||||
|
|
||||||
|
String roomid = param.getString("room");
|
||||||
|
int pid = param.getInt("pid");
|
||||||
|
int time = param.getInt("time");
|
||||||
|
int reward_value = 0;
|
||||||
|
int xipai_reward_value = 0;
|
||||||
|
int max_player = 0;
|
||||||
|
int rewardValueType = 0;
|
||||||
|
int xipai_rewardValueType = 0;
|
||||||
|
int rewardType = 1;
|
||||||
|
int xipai_rewardType = 1;
|
||||||
|
|
||||||
|
if (param.containsKey("hpReal")) {
|
||||||
|
hpReal = param.getInt("hpReal");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean is_xipai = param.containsKey("xipai");
|
||||||
|
int xipai = 0;
|
||||||
|
pumpBase = param.getInt("pumpBase");
|
||||||
|
if (param.containsKey("pumpBaseWin")) {
|
||||||
|
pumpBaseWin = param.getInt("pumpBaseWin");
|
||||||
|
}
|
||||||
|
|
||||||
|
String prs = null;
|
||||||
|
|
||||||
|
if (is_pump) {
|
||||||
|
pump = param.getInt("pump");
|
||||||
|
pumpReal = param.getInt("pumpReal");
|
||||||
|
|
||||||
|
max_player = param.getInt("max_player");
|
||||||
|
if (param.containsKey("reward_value")) {
|
||||||
|
reward_value = param.getInt("reward_value");
|
||||||
|
prs = param.getString("prs");
|
||||||
|
}
|
||||||
|
if (param.containsKey("reward_type")) {
|
||||||
|
rewardType = param.getInt("reward_type");
|
||||||
|
}
|
||||||
|
if (param.containsKey("rewardValueType")) {
|
||||||
|
rewardValueType = param.getInt("rewardValueType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_xipai) {
|
||||||
|
xipai = param.getInt("xipai");
|
||||||
|
max_player = param.getInt("max_player");
|
||||||
|
if (param.containsKey("xipai_reward_value")) {
|
||||||
|
xipai_reward_value = param.getInt("xipai_reward_value");
|
||||||
|
prs = param.getString("prs");
|
||||||
|
}
|
||||||
|
if (param.containsKey("xipai_reward_type")) {
|
||||||
|
xipai_rewardType = param.getInt("xipai_reward_type");
|
||||||
|
}
|
||||||
|
if (param.containsKey("xipai_rewardValueType")) {
|
||||||
|
xipai_rewardValueType = param.getInt("xipai_rewardValueType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.containsKey("hp_than_max_value")) {
|
||||||
|
int more_hp = param.getInt("hp_than_max_value");
|
||||||
|
String gm_key = GroupMemberCache.genKey(groupId, uid);
|
||||||
|
String bank_hp = Redis.use("group1_db10").hget(gm_key, "bank_hp");
|
||||||
|
String sql = String.format("{call sp_bank_hp(%s,%s,%s,%s)}", groupId, uid, more_hp, cur_hp);
|
||||||
|
Utility.evtdb(groupId, 2, sql);
|
||||||
|
String sql2 = String.format("update group_member set bank_hp = %s where uid = %s AND groupId = %s",
|
||||||
|
bank_hp, uid, groupId);
|
||||||
|
Utility.evtdb(groupId, 1, sql2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String desc = param.getString("desc");
|
||||||
|
desc = StringUtil.isNotEmpty(desc) ? desc : StringUtil.Empty;
|
||||||
|
|
||||||
|
if (hp != 0 && !is_xipai && pumpReal != 0 ) {
|
||||||
|
log.info("结算到这里1:"+cur_hp);
|
||||||
|
cur_hp = cur_hp+hp;
|
||||||
|
if(hp<0) {
|
||||||
|
hpConsume(groupId, uid, pid, hp, cur_hp, ConsumeCode.HP_CLEARING, roomid, time, desc);
|
||||||
|
}else {
|
||||||
|
cur_hp = cur_hp-pumpReal;
|
||||||
|
hpConsume(groupId, uid, pid, hp-pumpReal, cur_hp-pumpReal, ConsumeCode.HP_CLEARING, roomid, time, desc);
|
||||||
|
hpConsume(groupId, uid, pid, -pumpReal, cur_hp, ConsumeCode.HP_PUMP, roomid, time, desc);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (hp > 0 && pumpBase != 0 && !is_xipai) {
|
||||||
|
log.info("抽水到这里cur_hp:"+cur_hp);
|
||||||
|
log.info("抽水到这里pumpBase:"+pumpBase);
|
||||||
|
|
||||||
|
hpConsume(groupId, uid, pid, -pumpBase, cur_hp - pumpBase, ConsumeCode.HP_PUMP, roomid, time, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Jedis jedis9 = Redis.use("group1_db9").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
String key = String.format("g%s:m%s:consume_hp", groupId, uid);
|
||||||
|
if (hp != 0) {
|
||||||
|
CountUtil.countLogByDay(key, hp, jedis9, 691200);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pump > 0 && !is_xipai) {
|
||||||
|
|
||||||
|
CountUtil.countLogByDay(key, -pumpReal, jedis9, 691200);
|
||||||
|
time += 1;
|
||||||
|
// if(hpReal > 0 ) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
CountUtil.countLog(String.format("g%s:hp_cost", groupId), pump, jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:p%s", groupId, pid), pumpReal, jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:m%s", groupId, uid), pumpReal, jedis9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xipai > 0) {
|
||||||
|
CountUtil.countLogByDay(key, -xipai, jedis9, 691200);
|
||||||
|
time += 1;
|
||||||
|
hpConsume(groupId, uid, pid, -xipai, cur_hp-xipai, ConsumeCode.HP_XIPAI_PUMP, roomid, time, desc);
|
||||||
|
|
||||||
|
CountUtil.countLog(String.format("g%s:hp_cost", groupId), xipai, jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:p%s", groupId, pid), xipai, jedis9);
|
||||||
|
CountUtil.countLogByDay(String.format("g%s:hp_cost:m%s", groupId, uid), xipai, jedis9);
|
||||||
|
}
|
||||||
|
|
||||||
|
Pipeline pipeline = jedis9.pipelined();
|
||||||
|
// gid=618028, reward_value=0, reward_type=1, E=8, rewardType=1, hp=7000, pumpReal=0, pid=40,
|
||||||
|
// room=328670, prs=[{"p":241662,"r":242},{"p":139302,"r":245}], uid=241662, cur_hp=256892,
|
||||||
|
// xipai_rewardValueType=1, max_player=2, xipai_rewardType=3, time=1762344428, pump=0,
|
||||||
|
// desc=放炮罚 328670, rewardValueType=2, pumpBase=100
|
||||||
|
log.info("reward_value:" + reward_value);
|
||||||
|
log.info("rewardValueType:" + rewardValueType);
|
||||||
|
log.info("is_pump:" + is_pump);
|
||||||
|
log.info("pumpBase:" + pumpBase);
|
||||||
|
log.info("pumpBaseWin:" + pumpBaseWin);
|
||||||
|
log.info("pumpReal:" + pumpReal);
|
||||||
|
|
||||||
|
if ((reward_value > 0 || (rewardValueType == 2 && is_pump)) && pumpReal != 0 && pumpBaseWin == 0) {
|
||||||
|
log.info("分层抽水");
|
||||||
|
|
||||||
|
time += 1;
|
||||||
|
to_reward(pipeline, uid, prs, rewardType, rewardValueType, pump, reward_value, groupId, pid, roomid,
|
||||||
|
time, max_player);
|
||||||
|
} else {
|
||||||
|
// 平局则把保底分给到群主
|
||||||
|
if (pumpBase > 0 && is_pump && pumpBaseWin != 0) {
|
||||||
|
log.info("平局抽赢家保底分");
|
||||||
|
hpConsume(groupId, uid, pid, -pumpBase, cur_hp - pumpBase, ConsumeCode.HP_PUMP, roomid, time, desc);
|
||||||
|
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
|
||||||
|
// 给到群主时要刷新mysql的hp值
|
||||||
|
String rewardsql = String.format(
|
||||||
|
"update group_member set bank_hp=bank_hp+ %s where uid = %s AND groupId = %s", pumpBase, gb.owner,
|
||||||
|
groupId);
|
||||||
|
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
long qunzhu_cur_hp = CountUtil.countLogByDay3(
|
||||||
|
String.format("g%s:hp_reward:m%s", groupId, gb.owner), pumpBase, jedis9);
|
||||||
|
|
||||||
|
String sql = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,'" + "保底抽水" + "')",
|
||||||
|
groupId, gb.owner, ConsumeCode.HP_PARTNER_REWARD, pumpBase, qunzhu_cur_hp, pid, roomid,
|
||||||
|
time, 0);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
to_reward_base(pipeline, uid, param.getString("prs"), -pumpBase, groupId, true);
|
||||||
|
|
||||||
|
} else if (pumpBase > 0 && !is_xipai && is_pump && pumpBaseWin == 0) {
|
||||||
|
log.info("平局抽双方保底分");
|
||||||
|
hpConsume(groupId, uid, pid, -pumpBase, cur_hp - pumpBase, ConsumeCode.HP_PUMP, roomid, time, desc);
|
||||||
|
|
||||||
|
GroupBean gb = GroupCache.getGroup(groupId);
|
||||||
|
long qunzhu_cur_hp = CountUtil.countLogByDay3(
|
||||||
|
String.format("g%s:hp_reward:m%s", groupId, gb.owner), pumpBase, jedis9);
|
||||||
|
|
||||||
|
// 给到群主时要刷新mysql的hp值
|
||||||
|
String rewardsql = String.format(
|
||||||
|
"update group_member set bank_hp=bank_hp+ %s where uid = %s AND groupId = %s", pumpBase, gb.owner,
|
||||||
|
groupId);
|
||||||
|
|
||||||
|
Utility.evtdb(groupId, 1, rewardsql);
|
||||||
|
String sqllog = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,'" + "保底抽水" + "')",
|
||||||
|
groupId, gb.owner, ConsumeCode.HP_PARTNER_REWARD, pumpBase, qunzhu_cur_hp, pid, roomid,
|
||||||
|
time, 0);
|
||||||
|
Utility.evtdb(groupId, 1, sqllog);
|
||||||
|
// 记录被扣除保底分的用户
|
||||||
|
|
||||||
|
String sqlUserlog = String.format(
|
||||||
|
"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
|
||||||
|
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||||
|
groupId, uid, ConsumeCode.HP_CLEARING, pumpBase, cur_hp, pid, roomid, time, 0, "扣除保底");
|
||||||
|
Utility.evtdb(groupId, 1, sqlUserlog);
|
||||||
|
|
||||||
|
to_reward_base(pipeline, uid, param.getString("prs"), -pumpBase, groupId, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* else { if (is_pump && pump > 0) {
|
||||||
|
* log.error("pump to_mengzhu_reward:"+pump+" uid:" + uid + " groupId:" +
|
||||||
|
* groupId); to_mengzhu_reward(pipeline,uid,prs,rewardType,rewardValueType,
|
||||||
|
* pump, reward_value ,groupId,pid,roomid,time,max_player); } }
|
||||||
|
*/
|
||||||
|
if (xipai_reward_value > 0 || (xipai_rewardValueType == 2 && is_xipai)) {
|
||||||
|
|
||||||
|
time += 1;
|
||||||
|
xipai_to_reward(pipeline, uid, prs, xipai_rewardType, xipai_rewardValueType, xipai,
|
||||||
|
xipai_reward_value, groupId, pid, roomid, time, max_player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* else { if (is_xipai && xipai > 0) {
|
||||||
|
* log.error("xipai to_mengzhu_reward:"+pump+" uid:" + uid + " groupId:" +
|
||||||
|
* groupId);
|
||||||
|
* to_mengzhu_reward(pipeline,uid,prs,xipai_rewardType,xipai_rewardValueType,
|
||||||
|
* xipai, xipai_reward_value ,groupId,pid,roomid,time,max_player); } }
|
||||||
|
*/
|
||||||
|
pipeline.sync();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
jedis9.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
EventServer.log.error("群主保底分sql异常:", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
public class HandlerLose implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
public class HandlerOver implements IHandler {
|
||||||
|
|
||||||
|
public static final int _SHARE_NUM = 20;
|
||||||
|
|
||||||
|
private static void share(String id) throws Exception {
|
||||||
|
if (!Redis.use("group1_db1").sismember("shares", id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String sql = "SELECT succ,playtimes FROM shares WHERE uid = " + id;
|
||||||
|
ITArray resultArray = DataBase.use().executeQueryByTArray(sql);
|
||||||
|
if (resultArray.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ITObject dbData = resultArray.getTObject(0);
|
||||||
|
if (dbData.getInt("succ") != 0) {
|
||||||
|
Redis.use("group1_db1").srem("shares", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int playTimes = dbData.getInt("playtimes") + 1;
|
||||||
|
dbData.putInt("playtimes", playTimes);
|
||||||
|
if (playTimes >= _SHARE_NUM) {
|
||||||
|
dbData.putInt("succ", 1);
|
||||||
|
Redis.use("group1_db1").srem("shares", id);
|
||||||
|
}
|
||||||
|
DataBase.use().update("shares", dbData, "uid=" + id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid,ITObject param) throws Exception {
|
||||||
|
int is_rec = param.getInt("is_rec");
|
||||||
|
if(is_rec == 1) {
|
||||||
|
String roomid =param.getString("roomid");
|
||||||
|
String rec_key =param.getString("rec_key");
|
||||||
|
int gid =param.containsKey("gid")?param.getInt("gid"):0;
|
||||||
|
int time =param.getInt("time");
|
||||||
|
int par = 0;
|
||||||
|
if(gid>0) {
|
||||||
|
String gm_key = GroupMemberCache.genKey(gid, uid);
|
||||||
|
String parentId = Redis.use("group1_db10").hget(gm_key, "parentId");
|
||||||
|
par = StringUtil.isEmpty(parentId)?0:Integer.parseInt(parentId);
|
||||||
|
}
|
||||||
|
String sql =String.format("insert into room_rec_log(roomid,gid,uid,rec_key,time,parentId) values('%s',%s,%s,'%s',%s,%s)",
|
||||||
|
roomid,gid,uid,rec_key,time,par);
|
||||||
|
DataBase.use().executeUpdate(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
share(uid+"");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.data.cache.AccountCache;
|
||||||
|
import com.data.util.ConsumeCode;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.EventController;
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
public class HandlerPay implements IHandler{
|
||||||
|
|
||||||
|
int reason;
|
||||||
|
boolean isPay;
|
||||||
|
public HandlerPay(int reason,boolean isPay) {
|
||||||
|
this.reason = reason;
|
||||||
|
this.isPay = isPay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
int pay = param.getInt("pay");
|
||||||
|
if(pay==0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int result = 1;
|
||||||
|
int gameId =param.getInt("game");
|
||||||
|
int groupId = 0;
|
||||||
|
int pid = 0;
|
||||||
|
if(param.containsKey("group")) {
|
||||||
|
groupId = param.getInt("group");
|
||||||
|
}
|
||||||
|
if(param.containsKey("pid")) {
|
||||||
|
pid = param.getInt("pid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reason == ConsumeCode.DIAMO_JOIN_ROOM) {
|
||||||
|
pay = Math.abs(pay);
|
||||||
|
}
|
||||||
|
if(reason == ConsumeCode.DIAMO_REFUND) {
|
||||||
|
pay = -Math.abs(pay);
|
||||||
|
}
|
||||||
|
if(reason == ConsumeCode.DIAMO_ADD) {
|
||||||
|
pay = -pay;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isPay) {
|
||||||
|
int cur_diamo = param.getInt("diamo");
|
||||||
|
EventController.payDiamo(uid, pay, cur_diamo, reason, gameId, groupId, pid);
|
||||||
|
result = 0;
|
||||||
|
}else {
|
||||||
|
String session = AccountCache.genKey(uid);
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
try {
|
||||||
|
ArrayList<Long> result_list = Utility.payDiamo(jedis0, session,pay);
|
||||||
|
if(result_list!=null) {
|
||||||
|
result = result_list.get(0).intValue();
|
||||||
|
if(result ==0) {
|
||||||
|
long cur_diamo = result_list.get(1);
|
||||||
|
EventController.payDiamo(uid, pay, (int)cur_diamo, reason, gameId, groupId, pid);
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
jedis0.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.evt.mgr.handler;
|
||||||
|
|
||||||
|
import com.evt.mgr.IHandler;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
public class HandlerWin implements IHandler{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process(int uid, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int processGroup(int groupId, ITObject param) throws Exception {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.evt.mgr.job;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobKey;
|
||||||
|
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.GroupPublisherService;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
|
|
||||||
|
public class CleanGroupLogJob implements Job {
|
||||||
|
private Logger logger = Logger.getLogger(CleanGroupLogJob.class);
|
||||||
|
|
||||||
|
public CleanGroupLogJob() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除亲友圈中无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanGroupMemberLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 31 * 24 * 3600;
|
||||||
|
String deleteSql = String.format("delete from group_member_log where time < %s", time);
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
DataBase.use().executeUpdate(deleteSql);
|
||||||
|
logger.info("cleanGroupMemberLog use time:"+(System.currentTimeMillis()-startTime)+ " " + deleteSql);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CleanGroupHpLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 31 * 24 * 3600;
|
||||||
|
String deleteSql3 = String.format("delete from group_hp_log where time < %s limit 1000000", time);
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
DataBase.use().executeUpdate(deleteSql3);
|
||||||
|
logger.info("CleanGroupHpLog use time:"+(System.currentTimeMillis()-startTime)+ " " + deleteSql3);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CleanRecRoomLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 31 * 24 * 3600;
|
||||||
|
String deleteSql2 = String.format("delete from room_rec_log where time < %s limit 1000000", time);
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
DataBase.use().executeUpdate(deleteSql2);
|
||||||
|
logger.info("CleanRecRoomLog use time:"+(System.currentTimeMillis()-startTime) + " " + deleteSql2);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) {
|
||||||
|
JobKey jobKey = context.getJobDetail().getKey();
|
||||||
|
if(jobKey.getName().equals("clean_group_member_log")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
cleanGroupMemberLog();
|
||||||
|
}
|
||||||
|
if(jobKey.getName().equals("clean_group_hp_log")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
CleanGroupHpLog();
|
||||||
|
}
|
||||||
|
if(jobKey.getName().equals("clean_rec_room_log")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
CleanRecRoomLog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,322 @@
|
||||||
|
package com.evt.mgr.job;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.taurus.core.util.DateUtils;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobKey;
|
||||||
|
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.data.util.Utility;
|
||||||
|
import com.evt.mgr.GroupPublisherService;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
|
|
||||||
|
public class CleanTimeOutRoomJob implements Job{
|
||||||
|
|
||||||
|
private Logger logger = Logger.getLogger(CleanTimeOutRoomJob.class);
|
||||||
|
|
||||||
|
public CleanTimeOutRoomJob() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteRoomFromRedis(String tag_key,Jedis jedis0) {
|
||||||
|
|
||||||
|
RedisLock room_lock = new RedisLock(tag_key, jedis0);
|
||||||
|
try {
|
||||||
|
// 0 1 2 3 4 5 6 7 8 9
|
||||||
|
List<String> paramList = jedis0.hmget(tag_key, "AA", "payer", "pay", "group","game","delete_status","status","create_time","id","players");
|
||||||
|
|
||||||
|
if(StringUtil.isEmpty(paramList.get(4))) {
|
||||||
|
Redis.use().expire(tag_key, 20);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String delete_status = paramList.get(5);
|
||||||
|
if(StringUtil.isEmpty(delete_status)) {
|
||||||
|
|
||||||
|
String status = paramList.get(6);
|
||||||
|
int _status = Integer.parseInt(status);
|
||||||
|
if(_status == 2 || _status == 3) {
|
||||||
|
logger.info(tag_key + "房间的状态不对,此时房间的状态["+status + "]");
|
||||||
|
Redis.use().expire(tag_key, 20);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果房间的存活时间小于4个小时,考虑到游戏服务器也在删除 所以延时10分钟
|
||||||
|
String create_time = paramList.get(7);
|
||||||
|
String roomid = paramList.get(8);
|
||||||
|
long now = System.currentTimeMillis() / 1000;
|
||||||
|
if((now - Long.parseLong(create_time)) > 14400 + 600) {
|
||||||
|
|
||||||
|
deleteRoomFromServer(tag_key,jedis0,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean pay_AA = Integer.parseInt(paramList.get(0)) == 1;
|
||||||
|
int payer = Integer.parseInt(paramList.get(1));
|
||||||
|
int pay = Integer.parseInt(paramList.get(2));
|
||||||
|
int gameId = Integer.parseInt(paramList.get(4));
|
||||||
|
String group = paramList.get(3);
|
||||||
|
int _gid = 0;
|
||||||
|
if(StringUtil.isNotEmpty(group)) {
|
||||||
|
_gid = Integer.parseInt(group);
|
||||||
|
}
|
||||||
|
int _delete_status = Integer.parseInt(delete_status);
|
||||||
|
if(_delete_status == 0) {
|
||||||
|
|
||||||
|
// 如果需要支付钻石
|
||||||
|
if(pay > 0) {
|
||||||
|
|
||||||
|
if (pay_AA) {
|
||||||
|
|
||||||
|
String players_json = paramList.get(9);
|
||||||
|
if(StringUtil.isEmpty(players_json) == false) {
|
||||||
|
ITArray players = TArray.newFromJsonData(players_json);
|
||||||
|
for (int i = 0; i < players.size(); i++) {
|
||||||
|
//GroupPublisherService.refundDiamo(players.getInt(i), pay, _gid, gameId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
|
||||||
|
if(_gid == 0) {
|
||||||
|
//GroupPublisherService.refundDiamo(payer, pay, _gid, gameId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Redis.use().hset(tag_key, "status", 3 + "");
|
||||||
|
Redis.use().hincrBy(tag_key, "cache_ver", 1);
|
||||||
|
Redis.use().expire(tag_key, 20);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
logger.info(tag_key + "删除房间发生异常["+e.getMessage() + "]");
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
room_lock.unlock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean deleteRoomFromServer(String roomid,Jedis jedis0,boolean lock) {
|
||||||
|
|
||||||
|
String tag_key = roomid;
|
||||||
|
RedisLock room_lock = null;
|
||||||
|
|
||||||
|
if(lock) {
|
||||||
|
room_lock = new RedisLock(tag_key, jedis0);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if( jedis0.exists(tag_key) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 0 1 2 3 4 5 6 7
|
||||||
|
List<String> paramList = jedis0.hmget(tag_key, "AA", "payer", "pay", "group","game","status","create_time","id");
|
||||||
|
|
||||||
|
String status = paramList.get(5);
|
||||||
|
int _status = Integer.parseInt(status);
|
||||||
|
if(_status == 2 || _status == 3) {
|
||||||
|
logger.info("删除房间" + roomid + "失败,原因状态不对,此时的状态是[" + _status +"]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String group = paramList.get(3);
|
||||||
|
int _gid = 0;
|
||||||
|
if(StringUtil.isNotEmpty(group)) {
|
||||||
|
_gid = Integer.parseInt(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果房间的存活时间小于4个小时,考虑到游戏服务器也在删除 所以延时10分钟
|
||||||
|
String create_time = paramList.get(6);
|
||||||
|
long now = System.currentTimeMillis() / 1000;
|
||||||
|
if((now - Long.parseLong(create_time)) < 14400 + 600) {
|
||||||
|
logger.info("删除房间" + roomid + "失败,房间距离创建没有超过4个小时");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_gid != 0) {
|
||||||
|
|
||||||
|
// 如果游戏没有开始_status = 0
|
||||||
|
// 不是aa支付,则退出回创建者创建钻石的费用
|
||||||
|
// aa支付,设置status=2之后,则交给游戏服务器去做(如果游戏服务器挂了呢,或者房间在游戏服务器中根本就不存在呢),
|
||||||
|
// 如果游戏已经开始_status = 1,则不用考虑钻石回退的问题,下一次执行的时候,如果redis还存在房间的信息,则直接从redis删除就可以了
|
||||||
|
if(_status==0) {
|
||||||
|
|
||||||
|
int gameId = Integer.parseInt(paramList.get(4));
|
||||||
|
boolean pay_AA = Integer.parseInt(paramList.get(0)) == 1;
|
||||||
|
if (!pay_AA) {
|
||||||
|
int payer = Integer.parseInt(paramList.get(1));
|
||||||
|
int pay = Integer.parseInt(paramList.get(2));
|
||||||
|
//Utility.payDiamo(EventType.REDIS_EVENT_BACK_PAY, payer, gameId, pay, _gid,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String strRoomID = "";
|
||||||
|
if(StringUtil.isNotEmpty(paramList.get(7))) {
|
||||||
|
strRoomID =paramList.get(7);
|
||||||
|
}
|
||||||
|
GroupPublisherService.delRoomEvt(_gid, strRoomID);
|
||||||
|
}
|
||||||
|
|
||||||
|
jedis0.hset(tag_key, "status", "2");
|
||||||
|
jedis0.hset(tag_key, "delete_status", "" + status);
|
||||||
|
jedis0.hincrBy(tag_key, "cache_ver", 1);
|
||||||
|
|
||||||
|
logger.info("删除房间" + roomid + "成功");
|
||||||
|
}
|
||||||
|
catch(Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
|
||||||
|
if(room_lock != null) {
|
||||||
|
room_lock.unlock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanInvalidRoom() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
String cursor = ScanParams.SCAN_POINTER_START;
|
||||||
|
String key = "room:*";
|
||||||
|
ScanParams scanParams = new ScanParams();
|
||||||
|
scanParams.match(key);
|
||||||
|
scanParams.count(1000);
|
||||||
|
|
||||||
|
// 处理所有redis的房间
|
||||||
|
while (true){
|
||||||
|
|
||||||
|
ScanResult<String> scanResult = jedis0.scan(cursor, scanParams);
|
||||||
|
cursor = scanResult.getStringCursor();
|
||||||
|
List<String> list = scanResult.getResult();
|
||||||
|
|
||||||
|
for(int m = 0; m < list.size(); m++){
|
||||||
|
|
||||||
|
String mapentry = list.get(m);
|
||||||
|
logger.info("正在检查房间 " + mapentry);
|
||||||
|
deleteRoomFromRedis(mapentry,jedis0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("0".equals(cursor)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
jedis0.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除亲友圈中无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanGroupRoom() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
|
||||||
|
RedisLock lock = new RedisLock("room_clean", jedis11);
|
||||||
|
try {
|
||||||
|
|
||||||
|
String cursor = ScanParams.SCAN_POINTER_START;
|
||||||
|
String key = "*:rooms*";
|
||||||
|
ScanParams scanParams = new ScanParams();
|
||||||
|
scanParams.match(key);
|
||||||
|
scanParams.count(1000);
|
||||||
|
|
||||||
|
// 处理亲友圈的房间
|
||||||
|
while (true){
|
||||||
|
|
||||||
|
ScanResult<String> scanResult = jedis11.scan(cursor, scanParams);
|
||||||
|
cursor = scanResult.getStringCursor();
|
||||||
|
List<String> list = scanResult.getResult();
|
||||||
|
|
||||||
|
for(int m = 0; m < list.size(); m++){
|
||||||
|
|
||||||
|
|
||||||
|
String mapentry = list.get(m);
|
||||||
|
logger.info("正在查询群" +mapentry + "的无效房间");
|
||||||
|
Set<String> rooms = jedis11.zrangeByScore(mapentry, 100000, 1000000);
|
||||||
|
|
||||||
|
for (String roomId : rooms) {
|
||||||
|
logger.info("正在查询群" +mapentry + "的无效房间" + roomId);
|
||||||
|
boolean existed = deleteRoomFromServer(roomId,jedis0,true);
|
||||||
|
if(!existed) {
|
||||||
|
jedis11.zrem(mapentry, roomId);
|
||||||
|
logger.info("删除群" +mapentry + "的无效房间" + roomId + "因为房间不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("0".equals(cursor)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
jedis0.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除亲友圈中无效的房间
|
||||||
|
*/
|
||||||
|
private void cleanGroupMemberLog() {
|
||||||
|
int time = DateUtils.getBeginDay() - 5 * 24 * 3600;
|
||||||
|
String deleteSql = String.format("delete from group_member_log where time < %s", time);
|
||||||
|
Utility.evtdbLog(1, 1, deleteSql);
|
||||||
|
String deleteSql2 = String.format("delete from room_rec_log where time < %s and time > %s", time, time - 24 * 3600);
|
||||||
|
Utility.evtdbLog(1, 1, deleteSql2);
|
||||||
|
String deleteSql3 = String.format("delete from group_hp_log where time < %s and time > %s", time, time - 24 * 3600);
|
||||||
|
Utility.evtdbLog(1, 1, deleteSql3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) {
|
||||||
|
|
||||||
|
JobKey jobKey = context.getJobDetail().getKey();
|
||||||
|
if(jobKey.getName().equals("clean_group_room") || jobKey.getName().equals("clean_group_room1")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
cleanGroupRoom();
|
||||||
|
logger.info("执行成功cleanGroupMemberLog");
|
||||||
|
cleanGroupMemberLog();
|
||||||
|
}
|
||||||
|
else if(jobKey.getName().equals("clean_invalid_room")|| jobKey.getName().equals("clean_invalid_room1")) {
|
||||||
|
logger.info("执行成功" + jobKey.getName());
|
||||||
|
cleanInvalidRoom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE web-app PUBLIC
|
||||||
|
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||||
|
"http://java.sun.com/dtd/web-app_2_3.dtd" >
|
||||||
|
|
||||||
|
<web-app>
|
||||||
|
<filter>
|
||||||
|
<filter-name>taurus-web</filter-name>
|
||||||
|
<filter-class>com.taurus.web.WebFilter</filter-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>main</param-name>
|
||||||
|
<param-value>com.evt.mgr.EventServer</param-value>
|
||||||
|
</init-param>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>taurus-web</filter-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
</web-app>
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>database</id>
|
||||||
|
<class>com.taurus.core.plugin.database.DataBasePlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认10个 -->
|
||||||
|
<maxPool>100</maxPool>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 配置获取连接等待超时的时间,单位是毫秒, 默认180000 -->
|
||||||
|
<maxLifetime>180000</maxLifetime>
|
||||||
|
<!--hsqldb - "select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"
|
||||||
|
Oracle - "select 1 from dual"
|
||||||
|
DB2 - "select 1 from sysibm.sysdummy1"
|
||||||
|
mysql - "select 1" -->
|
||||||
|
<validationQuery>select 1</validationQuery>
|
||||||
|
<!-- 连接超时时间,默认30000-->
|
||||||
|
<connectionTimeout>10000</connectionTimeout>
|
||||||
|
<!-- 待机超时时间,单位是毫秒, 默认60000 -->
|
||||||
|
<idleTimeout>60000</idleTimeout>
|
||||||
|
|
||||||
|
<!-- jdbc 属性 -->
|
||||||
|
<props>
|
||||||
|
<useSSL>false</useSSL>
|
||||||
|
<useUnicode>true</useUnicode>
|
||||||
|
<characterEncoding>utf-8</characterEncoding>
|
||||||
|
<!-- 服务器时区 -->
|
||||||
|
<serverTimezone>UTC</serverTimezone>
|
||||||
|
<!-- 预编译缓存 -->
|
||||||
|
<cachePrepStmts>true</cachePrepStmts>
|
||||||
|
<!-- 预编译缓存大小 -->
|
||||||
|
<prepStmtCacheSize>250</prepStmtCacheSize>
|
||||||
|
<!-- 控制长度多大的sql可以被缓存 -->
|
||||||
|
<prepStmtCacheSqlLimit>2048</prepStmtCacheSqlLimit>
|
||||||
|
</props>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<databases>
|
||||||
|
<db>
|
||||||
|
<name>db1</name>
|
||||||
|
<driverName>com.mysql.cj.jdbc.Driver</driverName>
|
||||||
|
<jdbcUrl>jdbc:mysql://8.138.220.239:8060/wb_game</jdbcUrl>
|
||||||
|
<userName>root</userName>
|
||||||
|
<password>root</password>
|
||||||
|
</db>
|
||||||
|
</databases>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>8</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>2</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="8.138.220.239" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="8.138.220.239" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db2" host="8.138.220.239" password="cssq@2020" port="6379" database="2" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="8.138.220.239" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="8.138.220.239" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="8.138.220.239" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="8.138.220.239" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="8.138.220.239" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
<info name="group1_db15" host="8.138.220.239" password="cssq@2020" port="6379" database="15" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
|
||||||
|
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
import com.taurus.web.JettyServer;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new JettyServer("src/main/webapp",8083,"/").start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.game</groupId>
|
||||||
|
<artifactId>game_common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>game_common</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!--依赖 data_cache -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.data</groupId>
|
||||||
|
<artifactId>data_cache</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-core</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--依赖 taurus-permanent -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taurus</groupId>
|
||||||
|
<artifactId>taurus-permanent</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 需要用redis时导入 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/jdom/jdom -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jdom</groupId>
|
||||||
|
<artifactId>jdom</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>game_common-${version}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- <compilerArgument>-parameters</compilerArgument> -->
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器内部事件常量表
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ActionEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备
|
||||||
|
*/
|
||||||
|
public static final String EVENT_READY = "ready";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备洗牌
|
||||||
|
*/
|
||||||
|
public static final String EVENT_READY_AND_XIPAI = "ready_and_xipai";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始游戏
|
||||||
|
*/
|
||||||
|
public static final String EVENT_START_GAME = "start_game";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出房间
|
||||||
|
*/
|
||||||
|
public static final String EVENT_EXIT_ROOM = "exit_room";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动
|
||||||
|
*/
|
||||||
|
public static final String EVENT_TIMER_AUTO = "timer_auto";
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*/
|
||||||
|
public static final String EVENT_ENTRUST = "entrust";
|
||||||
|
/**
|
||||||
|
* 离线
|
||||||
|
*/
|
||||||
|
public static final String EVENT_OFFLINE = "offline";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 洗牌
|
||||||
|
*/
|
||||||
|
public static final String EVENT_XIPAI = "xi_pai";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
public interface Constant {
|
||||||
|
/**
|
||||||
|
* 当局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_CURREN_RESULT = 1;
|
||||||
|
/**
|
||||||
|
* 满2局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_TWO_RESULT = 2;
|
||||||
|
/**
|
||||||
|
* 满3局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_THREE_RESULT = 3;
|
||||||
|
/**
|
||||||
|
* 满局大结算
|
||||||
|
*/
|
||||||
|
int ENTRUST_TOTAL_RESULT1 = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未开始
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_NOBEGIN = 0;
|
||||||
|
/**
|
||||||
|
* 游戏中
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_PLAYING = 1;
|
||||||
|
/**
|
||||||
|
* 正准备删除
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_DEL_FALG = 2;
|
||||||
|
/**
|
||||||
|
* 已删除
|
||||||
|
*/
|
||||||
|
int ROOM_STATUS_DEL = 3;
|
||||||
|
/**
|
||||||
|
* 正常大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_NORMAL = 1;
|
||||||
|
/**
|
||||||
|
* 托管当局大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_ENTRUST = 2;
|
||||||
|
/**
|
||||||
|
* 体力值不足大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_HP = 3;
|
||||||
|
/**
|
||||||
|
* 申请解散大结算
|
||||||
|
*/
|
||||||
|
int END_TYPE_DISSMISS = 4;
|
||||||
|
/**
|
||||||
|
* 体力值不足
|
||||||
|
*/
|
||||||
|
int HP_NOT_ENOUGH = -1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,357 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.data.bean.GameBean;
|
||||||
|
import com.data.bean.GroupBean;
|
||||||
|
import com.data.bean.GroupPlayBean;
|
||||||
|
import com.data.cache.GameCache;
|
||||||
|
import com.data.cache.GroupCache;
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.util.EventType;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis 事件控制器
|
||||||
|
*/
|
||||||
|
public class EventController {
|
||||||
|
private final static String GROUP_EVT_KEY = "evt_group_";
|
||||||
|
private final static String EVT_KEY = "event_";
|
||||||
|
private final static String CHACHE_KEY = "group1_db8";
|
||||||
|
|
||||||
|
private final static String EVT_TYPE = "E";
|
||||||
|
private final static String EVT_GID = "gid";
|
||||||
|
private final static String EVT_UID = "uid";
|
||||||
|
|
||||||
|
private static void sendGroupEvt(int type, int gid, ITObject data) {
|
||||||
|
int id = gid % 10;
|
||||||
|
data.putInt(EVT_GID, gid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush(GROUP_EVT_KEY + id, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendEvt(int type, int uid, ITObject data) {
|
||||||
|
int id = uid % 10;
|
||||||
|
data.putInt(EVT_UID, uid);
|
||||||
|
data.putInt(EVT_TYPE, type);
|
||||||
|
Redis.use(CHACHE_KEY).lpush(EVT_KEY + id, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册redis事件
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param type
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
public void redisEvent(int uid, int type, int num) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("N", num);
|
||||||
|
sendEvt(type, uid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圈子一局结束事件
|
||||||
|
*
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
* @param valid
|
||||||
|
*/
|
||||||
|
public void redisGroupRound(Room room, int gid, int pid, int valid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
data.putInt("valid", valid);
|
||||||
|
List<Player> list = room.scoreDesc();
|
||||||
|
Player winner = list.get(0);
|
||||||
|
for (int i = 0; i < room.getValidPlayerList().size(); i++) {
|
||||||
|
if (winner.playerid == room.getValidPlayerList().getInt(i)) {
|
||||||
|
data.putInt("win_player", winner.playerid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.putTArray("player_list", room.getValidPlayerList());
|
||||||
|
data.putInt("perfect_round", room.endType == Constant.END_TYPE_NORMAL ? 1 : 0);
|
||||||
|
int maxPlayer = room.getValidPlayer();
|
||||||
|
Global.logger.info("maxPlayer:" + maxPlayer);
|
||||||
|
Global.logger.info("valid:" + valid);
|
||||||
|
if (valid == 1 && maxPlayer > 0) {
|
||||||
|
data.putInt("valid_count", 100);
|
||||||
|
// data.putInt("valid_count", 100 / maxPlayer);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
data.putInt("valid_count", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxPlayer > 0) {
|
||||||
|
data.putInt("all_count", 100 / maxPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
GroupPlayBean gpb = GroupCache.getPlay(gid, pid);
|
||||||
|
if (gpb != null) {
|
||||||
|
int maxPlayers = gpb.maxPlayers;
|
||||||
|
ITObject configData = TObject.newFromJsonData(gpb.config);
|
||||||
|
int opt = configData.getInt("opt");
|
||||||
|
int gameId = gpb.gameId;
|
||||||
|
GameBean gb = GameCache.getGame(gameId);
|
||||||
|
if (gb != null) {
|
||||||
|
Integer pay = gb.pay.get("pay" + opt + "_" + maxPlayers);
|
||||||
|
if (pay != null && pay > 0 && maxPlayer > 0) {
|
||||||
|
data.putInt("valid_diamo", pay * 100 / maxPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendGroupEvt(EventType.REDIS_EVENT_GROUP_ROUND, gid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圈子玩家一局结束事件
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @param pid
|
||||||
|
* @param win
|
||||||
|
*/
|
||||||
|
public void redisGroupMemberRound(Player owner, int pid, boolean win, boolean hpPump, int cur_hp) {
|
||||||
|
|
||||||
|
Room room = owner.room;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
data.putInt("uid", owner.playerid);
|
||||||
|
if (owner.hp != null) {
|
||||||
|
data.putInt("score", owner.hp.total_hp);
|
||||||
|
} else {
|
||||||
|
data.putInt("score", owner.score.total_score);
|
||||||
|
}
|
||||||
|
data.putInt("time", (int) (System.currentTimeMillis() / 1000));
|
||||||
|
data.putInt("pump", owner.practicalHpPump);
|
||||||
|
data.putInt("pumpReal", owner.practicalHpPumpReal);
|
||||||
|
data.putInt("pumpBase", room.basePump);
|
||||||
|
|
||||||
|
data.putInt("xi_pai_total", owner.xi_pai_total);
|
||||||
|
data.putInt("win", win ? 1 : 0);
|
||||||
|
data.putInt("perfect_round", owner.room.endType == Constant.END_TYPE_NORMAL ? 1 : 0);
|
||||||
|
data.putInt("cur_hp", cur_hp);
|
||||||
|
data.putUtfString("room", room.roomid);
|
||||||
|
int maxPlayer = owner.room.getValidPlayer();
|
||||||
|
Global.logger.info("maxPlayer:" + maxPlayer);
|
||||||
|
Global.logger.info("hpPump:" + hpPump);
|
||||||
|
|
||||||
|
// if (hpPump && maxPlayer > 0) {
|
||||||
|
data.putInt("valid_count", 100 / maxPlayer);
|
||||||
|
// } else {
|
||||||
|
// data.putInt("valid_count", 0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
sendGroupEvt(EventType.REDIS_EVENT_GROUP_MEMBER_ROUND, owner.room.groupId, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册redis体力值事件 reward以前没有用到,现在表示抽水值只给盟主,不给合伙人参与分成
|
||||||
|
*/
|
||||||
|
public long redisFag(Player owner, int hp, boolean hpPump, boolean mengzhu_reward, int xipai_score, boolean xipai,
|
||||||
|
String desc) {
|
||||||
|
Room room = owner.room;
|
||||||
|
String gm_key = GroupMemberCache.genKey(room.groupId, owner.playerid);
|
||||||
|
Global.logger.info("playid:" + owner.playerid + "hp:" + hp + "total_hp:" + owner.hp.total_hp + "hpPump:"
|
||||||
|
+ hpPump + "mr:" + mengzhu_reward + "xp:" + xipai_score + "xipai:" + xipai + "desc:" + desc
|
||||||
|
+ "owner.practicalHpPumpReal:" + owner.practicalHpPumpReal);
|
||||||
|
long cur_hp = 0;
|
||||||
|
if (hpPump) {
|
||||||
|
String strCurHp = Redis.use("group1_db10").hget(gm_key, "hp");
|
||||||
|
if (StringUtil.isNotEmpty(strCurHp)) {
|
||||||
|
cur_hp = Long.parseLong(strCurHp);
|
||||||
|
if (cur_hp < owner.practicalHpPumpReal) {
|
||||||
|
owner.practicalHpPumpReal = (int) cur_hp;
|
||||||
|
owner.practicalHpPump = (int) cur_hp / 2;
|
||||||
|
if (owner.practicalHpPumpReal < 0) {
|
||||||
|
owner.practicalHpPumpReal = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", -owner.practicalHpPumpReal);
|
||||||
|
} else if (xipai) {
|
||||||
|
String strCurHp = Redis.use("group1_db10").hget(gm_key, "hp");
|
||||||
|
if (StringUtil.isNotEmpty(strCurHp)) {
|
||||||
|
cur_hp = Long.parseLong(strCurHp);
|
||||||
|
if (cur_hp < xipai_score) {
|
||||||
|
xipai_score = (int) cur_hp;
|
||||||
|
if (xipai_score < 0) {
|
||||||
|
xipai_score = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", -xipai_score);
|
||||||
|
} else {
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", hp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
if (cur_hp > Integer.MAX_VALUE) {
|
||||||
|
long del_value = cur_hp - (long) Integer.MAX_VALUE;
|
||||||
|
cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", -del_value);
|
||||||
|
Redis.use("group1_db10").hincrBy(gm_key, "bank_hp", del_value);
|
||||||
|
data.putInt("hp_than_max_value", (int) del_value);
|
||||||
|
}
|
||||||
|
if (owner.hp.total_hp == 0 && !xipai) {
|
||||||
|
// 如果平局则每人抽保底的一半
|
||||||
|
Redis.use("group1_db10").hincrBy(gm_key, "hp", -room.basePump);
|
||||||
|
GroupBean gb = GroupCache.getGroup(room.groupId);
|
||||||
|
// String qunzhu_key = GroupMemberCache.genKey(room.groupId, gb.owner);
|
||||||
|
// Redis.use("group1_db10").hincrBy(qunzhu_key, "hp", room.basePump);
|
||||||
|
}
|
||||||
|
Global.logger.info("hp:" + hp);
|
||||||
|
Global.logger.info("cur_hp:" + cur_hp);
|
||||||
|
Global.logger.info("owner.prs:" + owner.prs);
|
||||||
|
Global.logger.info("owner.hp.total_hp:" + owner.hp.total_hp);
|
||||||
|
|
||||||
|
data.putInt("hp", hp);
|
||||||
|
data.putInt("cur_hp", (int) cur_hp);
|
||||||
|
data.putInt("pid", room.groupPid);
|
||||||
|
data.putInt("uid", owner.playerid);
|
||||||
|
data.putInt("time", (int) (System.currentTimeMillis() / 1000));
|
||||||
|
data.putUtfString("room", room.roomid);
|
||||||
|
// 临时处理
|
||||||
|
data.putUtfString("desc", StringUtil.isNotEmpty(desc) ? desc : Global.gameName + " " + room.roomid);
|
||||||
|
data.putInt("rewardType", room.rewardType);
|
||||||
|
data.putInt("rewardValueType", room.rewardValueType);
|
||||||
|
data.putInt("xipai_rewardType", room.xipai_rewardType);
|
||||||
|
data.putInt("xipai_rewardValueType", room.xipai_rewardValueType);
|
||||||
|
|
||||||
|
if (xipai) {
|
||||||
|
data.putInt("xipai", xipai_score);
|
||||||
|
int xipai_reward_value = 0;
|
||||||
|
if (room.xipai_rewardValueType == 1) {
|
||||||
|
xipai_reward_value = xipai_score;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.putInt("max_player", room.maxPlayers);
|
||||||
|
data.putInt("xipai_reward_type", room.xipai_rewardType);
|
||||||
|
data.putInt("xipai_reward_value", xipai_reward_value);
|
||||||
|
|
||||||
|
}
|
||||||
|
int readScore = xipai ? owner.hp.total_hp - xipai_score : owner.hp.total_hp;
|
||||||
|
ITArray rewards_list = room.hpData.getTArray("rewards_list");
|
||||||
|
int UpperLimit = 0;
|
||||||
|
int UpperLimitReward = 0;
|
||||||
|
if (rewards_list.size() > 0) {
|
||||||
|
UpperLimit = rewards_list.getTObject(0).getInt("UpperLimit");
|
||||||
|
UpperLimitReward = rewards_list.getTObject(0).getInt("UpperLimitReward");
|
||||||
|
}
|
||||||
|
data.putInt("pumpReal", 0);
|
||||||
|
|
||||||
|
if (UpperLimit > readScore && mengzhu_reward && readScore > 0) {
|
||||||
|
// 如果输赢低于UpperLimit的分数则只扣除大赢家
|
||||||
|
|
||||||
|
data.putInt("pumpBase", UpperLimitReward);
|
||||||
|
data.putInt("pumpBaseWin", UpperLimitReward);
|
||||||
|
|
||||||
|
} else if (UpperLimit > readScore && mengzhu_reward && readScore == 0 && !xipai) {
|
||||||
|
// 如果平局则扣双方
|
||||||
|
data.putInt("pumpBase", room.basePump);
|
||||||
|
} else {
|
||||||
|
// 否则不扣保底分
|
||||||
|
if (hpPump) {
|
||||||
|
owner.practicalHpPumpReal = rewards_list.getTObject(0).getInt("pumpProportion");
|
||||||
|
}
|
||||||
|
data.putInt("pumpBase", 0);
|
||||||
|
data.putInt("pumpReal", owner.practicalHpPumpReal);
|
||||||
|
data.putInt("hpReal", hp);
|
||||||
|
|
||||||
|
}
|
||||||
|
Global.logger.info("mengzhu_reward:" + mengzhu_reward);
|
||||||
|
Global.logger.info("readScore:" + readScore);
|
||||||
|
|
||||||
|
Global.logger.info("room.basePump:" + data.getInt("pumpBase"));
|
||||||
|
if (hpPump || room.basePump != 0) {
|
||||||
|
data.putInt("pump", owner.practicalHpPump);
|
||||||
|
|
||||||
|
int reward_value = 0;
|
||||||
|
int max_player = room.getValidPlayer();
|
||||||
|
if (room.rewardValueType == 1) {
|
||||||
|
|
||||||
|
if (room.rewardType == 1) {
|
||||||
|
if (room.totalPump + room.basePump != 0) {
|
||||||
|
reward_value = owner.practicalHpPump
|
||||||
|
- room.basePump * owner.practicalHpPump / (room.totalPump + room.basePump);
|
||||||
|
} else {
|
||||||
|
reward_value = owner.practicalHpPump;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reward_value = room.totalPump / max_player;
|
||||||
|
if (room.basePump > 0) {
|
||||||
|
if (reward_value + (room.basePump / max_player) > owner.practicalHpPump) {
|
||||||
|
reward_value = owner.practicalHpPump - (room.basePump / max_player);
|
||||||
|
if (reward_value < 0) {
|
||||||
|
reward_value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (reward_value > owner.practicalHpPump) {
|
||||||
|
reward_value = owner.practicalHpPump;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.putInt("max_player", room.getValidPlayer());
|
||||||
|
data.putInt("reward_type", room.rewardType);
|
||||||
|
data.putInt("reward_value", reward_value);
|
||||||
|
}
|
||||||
|
if (StringUtil.isNotEmpty(owner.prs)) {
|
||||||
|
data.putUtfString("prs", owner.prs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Global.logger.info("记录:" + data);
|
||||||
|
sendGroupEvt(EventType.REDIS_EVENT_GROUP_HP, room.groupId, data);
|
||||||
|
return cur_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返还钻石
|
||||||
|
*
|
||||||
|
* @param uid
|
||||||
|
* @param pay
|
||||||
|
* @param groupId
|
||||||
|
*/
|
||||||
|
public void refundDiamo(int uid, int pay, int groupId, int pid) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("pay", -pay);
|
||||||
|
data.putInt("game", Global.gameId);
|
||||||
|
if (groupId > 0) {
|
||||||
|
data.putInt("group", groupId);
|
||||||
|
data.putInt("pid", pid);
|
||||||
|
}
|
||||||
|
sendEvt(EventType.REDIS_EVENT_BACK_PAY, uid, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大局结束事件
|
||||||
|
*
|
||||||
|
* @param gid
|
||||||
|
* @param pid
|
||||||
|
* @param valid
|
||||||
|
*/
|
||||||
|
public void redisOver(Player owner, int time, String rec_key) {
|
||||||
|
Room room = owner.room;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
if (StringUtil.isNotEmpty(rec_key)) {
|
||||||
|
data.putInt("is_rec", 1);
|
||||||
|
data.putUtfString("roomid", room.roomid);
|
||||||
|
data.putInt("gid", room.groupId);
|
||||||
|
data.putUtfString("rec_key", rec_key);
|
||||||
|
data.putInt("time", time);
|
||||||
|
} else {
|
||||||
|
data.putInt("is_rec", 0);
|
||||||
|
}
|
||||||
|
sendEvt(EventType.REDIS_EVENT_OVER, owner.playerid, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dong.teng
|
||||||
|
*/
|
||||||
|
public class GPSUtil {
|
||||||
|
// 地球半径
|
||||||
|
private static final double EARTH_RADIUS = 6378137;
|
||||||
|
|
||||||
|
private static double radian(double lngLat) {
|
||||||
|
return lngLat * Math.PI / 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据两点间经纬度坐标,计算直线距离 单位 :米
|
||||||
|
*/
|
||||||
|
public static double getDistance(String gps1, String gps2) {
|
||||||
|
double distance = 0;
|
||||||
|
if (isOpenGPS(gps1) && isOpenGPS(gps2)) {
|
||||||
|
String[] gps1Arr = gps1.split(",");
|
||||||
|
String[] gps2Arr = gps2.split(",");
|
||||||
|
Double lat1 = Double.parseDouble(gps1Arr[1]);
|
||||||
|
Double lng1 = Double.parseDouble(gps1Arr[0]);
|
||||||
|
Double lat2 = Double.parseDouble(gps2Arr[1]);
|
||||||
|
Double lng2 = Double.parseDouble(gps2Arr[0]);
|
||||||
|
double radLat1 = radian(lat1);
|
||||||
|
double radLat2 = radian(lat2);
|
||||||
|
double a = radLat1 - radLat2;
|
||||||
|
double b = radian(lng1) - radian(lng2);
|
||||||
|
distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
|
||||||
|
distance *= EARTH_RADIUS;
|
||||||
|
distance = Math.round(distance * 10000) / 10000;
|
||||||
|
}
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两位置是否过近
|
||||||
|
*
|
||||||
|
* @param gps1
|
||||||
|
* @param gps2
|
||||||
|
* @param measure
|
||||||
|
* 衡量过近米
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isDistanceNear(String gps1, String gps2, int measure) {
|
||||||
|
return getDistance(gps1, gps2) <= measure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否打开gps
|
||||||
|
*/
|
||||||
|
public static boolean isOpenGPS(String gps) {
|
||||||
|
return StringUtil.isNotEmpty(gps) && gps.contains(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//System.out.println(isDistanceNear("109.19300079346,27.710248947144", "100.23030090332,25.59494972229",50));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,667 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.data.bean.AccountBean;
|
||||||
|
import com.data.cache.AccountCache;
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.data.util.ErrorCode;
|
||||||
|
import com.game.data.JoinRoomData;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerInitState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.room.state.RoomDestoryGameState;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.routes.ActionKey;
|
||||||
|
import com.taurus.core.routes.IController;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本游戏控制器
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GameController implements IController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_INTERACTION)
|
||||||
|
public void routerChat(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_INTERACTION, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求准备
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_READY)
|
||||||
|
public void routerReady(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.stateMachine.execute(ActionEvent.EVENT_READY, gid, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求准备
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_READY_AND_XIPAI)
|
||||||
|
public void routerReadyAndXiPai(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.stateMachine.execute(ActionEvent.EVENT_READY_AND_XIPAI, gid, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求开始游戏
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_START)
|
||||||
|
public void routerStartGame(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.room.stateMachine.execute(ActionEvent.EVENT_START_GAME, gid, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActionKey(Router.GAME_XIPAI)
|
||||||
|
public void RouterXiPai(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.stateMachine.execute(ActionEvent.EVENT_XIPAI, 0, params);
|
||||||
|
owner.room.stateMachine.execute(ActionEvent.EVENT_XIPAI, 0, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_ENTRUST)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void routerEntrust(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
if (owner.room.status == Constant.ROOM_STATUS_PLAYING && owner.room.isEntrust()) {
|
||||||
|
owner.entrust = params.getBoolean("ok");
|
||||||
|
Global.gameCtr.updatePlayerEntrust(owner);
|
||||||
|
Global.logger.info(owner + " manual " + (owner.entrust ? "entrust" : "quitEntrust"));
|
||||||
|
if (owner.entrust) {
|
||||||
|
owner.setEntrustData(params);
|
||||||
|
owner.stateMachine.curState.execute(owner, ActionEvent.EVENT_ENTRUST, gid, params);
|
||||||
|
} else {
|
||||||
|
owner.exitEntrust();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求进入房间
|
||||||
|
*/
|
||||||
|
@ActionKey(value = Router.GAME_JOIN_ROOM, validate = GameInterceptor.NOT_PLAYER)
|
||||||
|
public void routerJoinRoom(Session sender, ITObject params, int gid) {
|
||||||
|
String session_id = params.getUtfString("session");
|
||||||
|
// String sessionToken = Utils.getUniqueSessionToken(sender);
|
||||||
|
String token = null;
|
||||||
|
if (StringUtil.isEmpty(session_id)) {
|
||||||
|
Global.logger.info("---------------参数session为null,参数params:{}", params);
|
||||||
|
session_id = "";
|
||||||
|
} else {
|
||||||
|
String[] sourceStrArray = session_id.split(",");
|
||||||
|
if (sourceStrArray.length == 2) {
|
||||||
|
session_id = sourceStrArray[0];
|
||||||
|
token = sourceStrArray[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.isNotEmpty(token) && StringUtil.isNotEmpty(session_id)) {
|
||||||
|
String token_session = Redis.use("group1_db0").hget(token, "user");
|
||||||
|
if (StringUtil.isEmpty(token_session)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (!token_session.equals(session_id)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.setHashId(session_id);
|
||||||
|
String pos = params.getUtfString("pos");
|
||||||
|
Global.roomMgr.joinRoom(sender, session_id, gid, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动出牌
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_AUTO_CARD)
|
||||||
|
public void routerAutoCard(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.manualAutoCard = params.getBoolean("autoCard");
|
||||||
|
|
||||||
|
if (owner.manualAutoCard) {
|
||||||
|
if (!owner.room.openEntrust) {
|
||||||
|
owner.manualAutoCard = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
owner.entrust = owner.manualAutoCard;
|
||||||
|
|
||||||
|
Global.gameCtr.updatePlayerEntrust(owner);
|
||||||
|
Global.logger.info(owner + " manualAutoCard " + (owner.entrust ? "entrust" : "quitEntrust"));
|
||||||
|
|
||||||
|
if (owner.manualAutoCard) {
|
||||||
|
owner.stateMachine.curState.execute(owner, ActionEvent.EVENT_ENTRUST, gid, params);
|
||||||
|
} else {
|
||||||
|
owner.exitEntrust();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求删除解散房间(外部)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ActionKey(value = Router.GAME_REMOVE_ROOM, validate = GameInterceptor.NOT_PLAYER)
|
||||||
|
public void routerRemoveRoom(Session sender, ITObject params, int gid) {
|
||||||
|
try {
|
||||||
|
String roomid = params.getUtfString("room");
|
||||||
|
// Global.logger.info(" ower del room : " + roomid);
|
||||||
|
// if (Global.roomMgr.removeRoom(roomid)) {
|
||||||
|
Global.logger.info(roomid + " is destroy!");
|
||||||
|
MainServer.instance.sendResponse(gid, 0, null, sender);
|
||||||
|
// } else {
|
||||||
|
// MainServer.instance.sendResponse(gid, 1, null, sender);
|
||||||
|
// }
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 1, null, sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求退出房间
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_EXIT_ROOM)
|
||||||
|
public void routerExitRoom(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.stateMachine.execute(ActionEvent.EVENT_EXIT_ROOM, gid, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求解散房间
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_ASK_DISMISS_ROOM)
|
||||||
|
public void routerAskDismiss(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.room.dismissRunable.askDismiss(owner, gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间解散投票请求
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_DISMISS_ROOM_VOTE)
|
||||||
|
public void routerDismissRoomVote(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
boolean agree = params.getBoolean("result");
|
||||||
|
owner.room.dismissRunable.responseDismiss(owner, agree);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求更新GPS位置
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_UPDATE_POS)
|
||||||
|
public void routerUpdatePos(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
owner.gps_pos = params.getUtfString("pos");
|
||||||
|
updatePlayerPos(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入座
|
||||||
|
*/
|
||||||
|
@ActionKey(Router.GAME_JOIN_SEAT)
|
||||||
|
public void routerJoinSeat(Session sender, ITObject params, int gid, Player owner) {
|
||||||
|
Global.gameCtr.joinSeat(owner, gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进入房间
|
||||||
|
*
|
||||||
|
* @param parm
|
||||||
|
* @param gid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public int joinRoom(JoinRoomData parm, int gid) {
|
||||||
|
Room owner = parm.room;
|
||||||
|
String session_key = parm.session_key;
|
||||||
|
Session sender = parm.sender;
|
||||||
|
String gps_pos = parm.gps_pos;
|
||||||
|
AccountBean acc = AccountCache.getAccount(session_key);
|
||||||
|
int playerid = acc.id;
|
||||||
|
|
||||||
|
boolean full = owner.playerMapBySeat.size() >= owner.maxPlayers;
|
||||||
|
boolean reload = owner.status == Constant.ROOM_STATUS_PLAYING;
|
||||||
|
|
||||||
|
String ip = acc.ip;
|
||||||
|
if (StringUtil.isEmpty(ip)) {
|
||||||
|
ip = sender.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = null;
|
||||||
|
boolean new_player = false;
|
||||||
|
if (owner.playerMapById.containsKey(playerid)) {
|
||||||
|
player = owner.playerMapById.get(playerid);
|
||||||
|
if (player.isReload) {
|
||||||
|
player.isReload = false;
|
||||||
|
player.stateMachine.changeState(Global.getState(PlayerInitState.class));
|
||||||
|
}
|
||||||
|
player.setSender(sender);
|
||||||
|
Global.gameCtr.playerNetState(player);
|
||||||
|
Global.gameCtr.updatePlayerPos(player);
|
||||||
|
} else {
|
||||||
|
if (full) {
|
||||||
|
sender.setHashId(null);
|
||||||
|
delRoomSeat(session_key, owner.room_key);
|
||||||
|
return ErrorCode.ROOM_CLOSE;
|
||||||
|
}
|
||||||
|
// 检测是否打开GPS 、IP检测
|
||||||
|
boolean openGps = owner.isOpenGPSCheck(), openIP = owner.isOpenIPCheck();
|
||||||
|
if (openGps || openIP) {
|
||||||
|
int errResult = 0;
|
||||||
|
if (openGps) {
|
||||||
|
Global.warn("room:{},playid:{},gps:{}", owner.room_key, playerid, gps_pos);
|
||||||
|
// 开了检测GPS 但是未获取到位置、或未打开
|
||||||
|
if (!GPSUtil.isOpenGPS(gps_pos)) {
|
||||||
|
errResult = 55;
|
||||||
|
}
|
||||||
|
// 距离过近
|
||||||
|
if (errResult == 0 && owner.checkGps(gps_pos)) {
|
||||||
|
errResult = 54;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (openIP) {
|
||||||
|
// 相同IP
|
||||||
|
|
||||||
|
if (errResult == 0 && owner.checkIp(ip)) {
|
||||||
|
errResult = 53;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errResult != 0) {
|
||||||
|
delRoomSeat(session_key, owner.room_key);
|
||||||
|
return errResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean onseat = true;
|
||||||
|
long cur_hp = 0;
|
||||||
|
if (onseat && owner.hpData != null) {
|
||||||
|
cur_hp = Util.readRedisHp(owner.groupId, playerid);
|
||||||
|
if (!checkHplimitInRoom(owner, cur_hp)) {
|
||||||
|
return ErrorCode.GROUP_LIMIT_NO_HP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player = MainServer.instance.newPlayer(playerid, owner, session_key);
|
||||||
|
if (player.room.upper_limit_hp == 0 || player.room.upper_limit_hp > cur_hp) {
|
||||||
|
player.room.upper_limit_hp = cur_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Playez firstPlayer = player.room.playerMapBySeat.get(player.seat);
|
||||||
|
// for (Map.Entry<Integer, Player> entry : player.room.playerMapBySeat.entrySet()) {
|
||||||
|
// Player other = entry.getValue();
|
||||||
|
// if (other.hp.upper_limit_hp > firstPlayer.hp.upper_limit_hp) {
|
||||||
|
// other.hp.upper_limit_hp = cur_hp;
|
||||||
|
// }else {
|
||||||
|
// player.hp.upper_limit_hp = cur_hp;
|
||||||
|
// }
|
||||||
|
// Global.logger.info(other.playerid + "当局赢分上限:" + other.hp.upper_limit_hp);
|
||||||
|
// }
|
||||||
|
|
||||||
|
player.hp.cur_hp = cur_hp;
|
||||||
|
// Global.logger.info("当局赢分上限:" + player.room.upper_limit_hp);
|
||||||
|
owner.addPlayer(player, false, onseat);
|
||||||
|
player.setSender(sender);
|
||||||
|
player.stateMachine.changeState(Global.getState(PlayerInitState.class));
|
||||||
|
new_player = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.nick = acc.nick;
|
||||||
|
player.portrait = acc.portrait;
|
||||||
|
player.sex = acc.sex;
|
||||||
|
player.ip = ip;
|
||||||
|
if (StringUtil.isNotEmpty(gps_pos))
|
||||||
|
player.gps_pos = gps_pos;
|
||||||
|
|
||||||
|
ITObject data = new TObject();
|
||||||
|
if (reload) {
|
||||||
|
data.putTObject("reloadInfo", owner.getReloadInfo(player));
|
||||||
|
}
|
||||||
|
data.putBoolean("reload", reload);
|
||||||
|
data.putInt("owner", owner.owner_id);
|
||||||
|
data.putInt("agent", owner.agent ? 1 : 0);
|
||||||
|
data.putInt("createTime", Integer.parseInt(owner.redis_room_map.get("create_time")));
|
||||||
|
data.putTObject("tableInfo", owner.getRoomInfo(player));
|
||||||
|
player.response(data, gid, 0);
|
||||||
|
|
||||||
|
if (new_player && player.seat != 0) {
|
||||||
|
owner.broadCastToClient(player.playerid, Router.GAME_EVT_PLAYER_JOIN, player.getInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reload) {
|
||||||
|
owner.join_player = player;
|
||||||
|
owner.dismissRunable.reload(player);
|
||||||
|
owner.stateMachine.curState.reload(owner);
|
||||||
|
player.stateMachine.curState.reload(player);
|
||||||
|
owner.join_player = null;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家不能进入房间,删除redis 玩家身上room、seat
|
||||||
|
*
|
||||||
|
* @param session_key
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void delRoomSeat(String session_key, String room_key) {
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
RedisLock lock = new RedisLock(session_key, jedis0);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
String cur_room = jedis0.hget(session_key, "room");
|
||||||
|
if (StringUtil.isNotEmpty(cur_room)) {
|
||||||
|
if (cur_room.equals(room_key)) {
|
||||||
|
jedis0.hdel(session_key, "room", "seat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测加人房间限制
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean checkHplimitInRoom(Room room, long cur_hp) {
|
||||||
|
if (room.hpData != null) {
|
||||||
|
int limitInRoom = room.hpData.getInt("limitInRoom");
|
||||||
|
if (cur_hp < (long) limitInRoom) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测加人房间限制
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean checkHplimitPlay(Room room, int cur_hp) {
|
||||||
|
if (room.hpData != null) {
|
||||||
|
int limitInRoom = room.hpData.getInt("limitInRoom");
|
||||||
|
if (cur_hp < limitInRoom) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 坐下
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @param gid
|
||||||
|
*/
|
||||||
|
public void joinSeat(Player owner, int gid) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天转发
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @param params
|
||||||
|
*/
|
||||||
|
public void chat(Player owner, ITObject params) {
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_INTERACTION, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管事件
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void entrust(Player owner, int time) {
|
||||||
|
ITObject broadParam = new TObject();
|
||||||
|
broadParam.putInt("aid", owner.playerid);
|
||||||
|
broadParam.putInt("time", time);
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_READY_ENTRUST, broadParam);
|
||||||
|
Global.info("{} Ready Entrust, left time:{}", owner.playerid, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消托管事件
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void cancelEntrust(Player owner) {
|
||||||
|
ITObject broadParam = new TObject();
|
||||||
|
broadParam.putInt("aid", owner.playerid);
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_CANCEL_READY_ENTRUST, broadParam);
|
||||||
|
// Global.info("{} Cancel Ready Entrust", owner.playerid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备事件
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void ready(Player owner) {
|
||||||
|
ITObject broadParam = new TObject();
|
||||||
|
broadParam.putInt("aid", owner.playerid);
|
||||||
|
long cur_hp = Util.readRedisHp(owner.room.groupId, owner.playerid);
|
||||||
|
if (cur_hp < owner.hp.cur_hp) {
|
||||||
|
Global.logger.error("cur hp:" + cur_hp + " < hp.cur_hp:" + owner.hp.cur_hp + " playerId:" + owner.playerid);
|
||||||
|
if (owner.room.round == 0 && (!checkHplimitInRoom(owner.room, cur_hp) || cur_hp == 0)) {
|
||||||
|
owner.room.saveMilitaryTotal(true);
|
||||||
|
owner.room.stateMachine.changeState(Global.getState(RoomDestoryGameState.class));
|
||||||
|
String gm_key = GroupMemberCache.genKey(owner.room.groupId, owner.playerid);
|
||||||
|
Redis.use("group1_db10").hset(gm_key, "ban", "1");
|
||||||
|
Redis.use("group1_db10").hset(gm_key, "group_ban", "1");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.hp.cur_hp = cur_hp;
|
||||||
|
|
||||||
|
boolean flag = true;
|
||||||
|
if (owner.room.maxPlayers == owner.room.playerMapById.size()) {
|
||||||
|
for (Map.Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
|
||||||
|
if (entry.getValue().playerid != owner.playerid
|
||||||
|
&& !(entry.getValue().stateMachine.curState instanceof PlayerReadyState)) {
|
||||||
|
flag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
broadParam.putInt("start", 1);
|
||||||
|
} else {
|
||||||
|
broadParam.putInt("start", 0);
|
||||||
|
}
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_READY, broadParam);
|
||||||
|
owner.stateMachine.changeState(Global.getState(PlayerReadyState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备和洗牌事件
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void readyAndXipai(Player owner) {
|
||||||
|
if (owner.xi_pai == false) {
|
||||||
|
owner.xi_pai = true;
|
||||||
|
owner.room.redisUpdateXiPaiPlayer(owner);
|
||||||
|
}
|
||||||
|
long cur_hp = Util.readRedisHp(owner.room.groupId, owner.playerid);
|
||||||
|
|
||||||
|
if (cur_hp < owner.hp.cur_hp || cur_hp == 0) {
|
||||||
|
Global.logger.error("cur hp:" + cur_hp + " < >>>>> hp.cur_hp:" + owner.hp.cur_hp + " playerId:" + owner.playerid);
|
||||||
|
if (owner.room.round == 0 && (!checkHplimitInRoom(owner.room, cur_hp) || cur_hp == 0)) {
|
||||||
|
owner.room.saveMilitaryTotal(true);
|
||||||
|
owner.room.stateMachine.changeState(Global.getState(RoomDestoryGameState.class));
|
||||||
|
String gm_key = GroupMemberCache.genKey(owner.room.groupId, owner.playerid);
|
||||||
|
Redis.use("group1_db10").hset(gm_key, "ban", "1");
|
||||||
|
Redis.use("group1_db10").hset(gm_key, "group_ban", "1");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.hp.cur_hp = cur_hp;
|
||||||
|
ITObject broadParam = new TObject();
|
||||||
|
broadParam.putInt("aid", owner.playerid);
|
||||||
|
|
||||||
|
boolean flag = true;
|
||||||
|
if (owner.room.maxPlayers == owner.room.playerMapById.size()) {
|
||||||
|
for (Map.Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
|
||||||
|
if (entry.getValue().playerid != owner.playerid
|
||||||
|
&& !(entry.getValue().stateMachine.curState instanceof PlayerReadyState)) {
|
||||||
|
flag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
broadParam.putInt("start", 1);
|
||||||
|
} else {
|
||||||
|
broadParam.putInt("start", 0);
|
||||||
|
}
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_READY_AND_XIPAI, broadParam);
|
||||||
|
owner.stateMachine.changeState(Global.getState(PlayerReadyState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解散房间通知
|
||||||
|
*
|
||||||
|
* @param askPlayer
|
||||||
|
* @param sender
|
||||||
|
* @param time
|
||||||
|
*/
|
||||||
|
public void dismissRoom(Player askPlayer, Player sender, List<Player> playerList, int time) {
|
||||||
|
ITObject parm = TObject.newInstance();
|
||||||
|
parm.putInt("req_aid", askPlayer.playerid);
|
||||||
|
parm.putInt("time", time);
|
||||||
|
ITArray list = TArray.newInstance();
|
||||||
|
parm.putTArray("list", list);
|
||||||
|
for (Player player : playerList) {
|
||||||
|
ITObject tem = TObject.newInstance();
|
||||||
|
tem.putInt("aid", player.playerid);
|
||||||
|
tem.putInt("result", player.dismissState);
|
||||||
|
list.addTObject(tem);
|
||||||
|
}
|
||||||
|
if (sender != null) {
|
||||||
|
sender.sendEvent(Router.GAME_EVT_DISMISS_ROOM, parm);
|
||||||
|
} else {
|
||||||
|
askPlayer.room.broadCastToClient(0, Router.GAME_EVT_DISMISS_ROOM, parm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 观众席
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void joinSpectator(Player owner) {
|
||||||
|
if (owner.room.exitSeat(owner)) {
|
||||||
|
if (Global.loggerDebug) {
|
||||||
|
Global.logger.info(owner + " exit seat!");
|
||||||
|
}
|
||||||
|
owner.seat = 0;
|
||||||
|
ITObject data = new TObject();
|
||||||
|
data.putInt("aid", owner.playerid);
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_JOIN_SPECTATOR, data);
|
||||||
|
owner.room.stateMachine.execute(ActionEvent.EVENT_READY, 0, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解散失败
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void dismisRoomFail(Room owner) {
|
||||||
|
owner.broadCastToClient(0, Router.GAME_EVT_DISMISS_ROOM_FAIL, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出房间
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
* @param gid
|
||||||
|
*/
|
||||||
|
public void exitRoom(Player owner, int gid, boolean kick) {
|
||||||
|
if (kick) {
|
||||||
|
owner.sendEvent(Router.GAME_EVT_KICK_PLAYER, null);
|
||||||
|
} else {
|
||||||
|
owner.response(null, gid, 0);
|
||||||
|
}
|
||||||
|
if (owner.room.status == Constant.ROOM_STATUS_NOBEGIN || owner.spectator) {
|
||||||
|
int owner_id = owner.room.owner_id;
|
||||||
|
if (!owner.room.agent && owner.playerid == owner_id) {
|
||||||
|
owner.room.stateMachine.changeState(Global.getState(RoomDestoryGameState.class));
|
||||||
|
} else {
|
||||||
|
// 在座位上
|
||||||
|
if (owner.room.playerMapBySeat.containsKey(owner.seat)) {
|
||||||
|
ITObject data = new TObject();
|
||||||
|
data.putInt("aid", owner.playerid);
|
||||||
|
owner.room.broadCastToClient(owner.playerid, Router.GAME_EVT_PLAYER_EXIT, data);
|
||||||
|
}
|
||||||
|
owner.destroy(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家网络状态通知
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void playerNetState(Player owner) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("aid", owner.playerid);
|
||||||
|
param.putInt("online", owner.isConnect ? 1 : 0);
|
||||||
|
owner.room.updatePlayerOffline(owner);
|
||||||
|
owner.room.broadCastToClient(owner.playerid, Router.GAME_EVT_PLAYER_NET_STATE, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新玩家GPS位置
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void updatePlayerPos(Player owner) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
param.putUtfString("pos", owner.gps_pos);
|
||||||
|
owner.room.broadCastToClient(owner.playerid, Router.GAME_EVT_UPDATE_POS, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新玩家托管
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void updatePlayerEntrust(Player owner) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("aid", owner.playerid);
|
||||||
|
param.putInt("type", 5);
|
||||||
|
param.putBoolean("entrust", owner.entrust);
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_UPDATE_PLAYERINFO, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.routes.Action;
|
||||||
|
import com.taurus.core.routes.IController;
|
||||||
|
import com.taurus.core.routes.Interceptor;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
public class GameInterceptor implements Interceptor{
|
||||||
|
public final static int NOT_PLAYER = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void intercept(Action action, IController controller,Object... args) throws Exception{
|
||||||
|
int validate = action.getActionKeyObj().validate();
|
||||||
|
Session sender = (Session)args[0];
|
||||||
|
TObject params = (TObject)args[1];
|
||||||
|
int gid = (int)args[2];
|
||||||
|
Method method = action.getMethod();
|
||||||
|
if((validate&NOT_PLAYER)!=0) {
|
||||||
|
method.invoke(controller,sender,params,gid);
|
||||||
|
}else {
|
||||||
|
Player player = Global.sessionMgr.getPlayer(sender);
|
||||||
|
if (player != null) {
|
||||||
|
Room room = player.room;
|
||||||
|
if (room == null)return;
|
||||||
|
if (room.isDestroy)return;
|
||||||
|
room.enqueueRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(player.isDestroy)return;
|
||||||
|
if(player.room.playerMapById.containsKey(player.playerid)) {
|
||||||
|
try {
|
||||||
|
method.invoke(controller, sender,params,gid,player);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.game.manager.RoomManager;
|
||||||
|
import com.game.manager.SessionManager;
|
||||||
|
import com.game.player.state.PlayerEndState;
|
||||||
|
import com.game.player.state.PlayerInitState;
|
||||||
|
import com.game.player.state.PlayerPauseState;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.player.state.PlayerReloadState;
|
||||||
|
import com.game.player.state.PlayerSpectatorState;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.game.room.state.RoomDestoryGameState;
|
||||||
|
import com.game.room.state.RoomEndState;
|
||||||
|
import com.game.room.state.RoomInitState;
|
||||||
|
import com.game.room.state.RoomReloadState;
|
||||||
|
import com.game.room.state.RoomStartGameState;
|
||||||
|
import com.game.room.state.RoomWaitState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
|
public class Global {
|
||||||
|
/**
|
||||||
|
* debug模式
|
||||||
|
*/
|
||||||
|
public static boolean loggerDebug = false;
|
||||||
|
// 日志
|
||||||
|
public static Logger logger;
|
||||||
|
// session管理器
|
||||||
|
public static SessionManager sessionMgr;
|
||||||
|
// 桌子管理器
|
||||||
|
public static RoomManager roomMgr;
|
||||||
|
|
||||||
|
public static GameController gameCtr;
|
||||||
|
|
||||||
|
public static EventController eventCtr;
|
||||||
|
/**
|
||||||
|
* 游戏ID
|
||||||
|
*/
|
||||||
|
public static int gameId = 1;
|
||||||
|
/**
|
||||||
|
* 游戏名字
|
||||||
|
*/
|
||||||
|
public static String gameName = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
|
||||||
|
Global.sessionMgr = new SessionManager();
|
||||||
|
Global.roomMgr = new RoomManager();
|
||||||
|
Global.eventCtr = new EventController();
|
||||||
|
|
||||||
|
registerState(RoomInitState.class, new RoomInitState());
|
||||||
|
registerState(RoomEndState.class, new RoomEndState());
|
||||||
|
registerState(RoomDestoryGameState.class, new RoomDestoryGameState());
|
||||||
|
registerState(RoomWaitState.class, new RoomWaitState());
|
||||||
|
registerState(RoomReloadState.class, new RoomReloadState());
|
||||||
|
registerState(RoomStartGameState.class, new RoomStartGameState());
|
||||||
|
|
||||||
|
registerState(PlayerInitState.class, new PlayerInitState());
|
||||||
|
registerState(PlayerPauseState.class, new PlayerPauseState());
|
||||||
|
registerState(PlayerReadyState.class, new PlayerReadyState());
|
||||||
|
registerState(PlayerReloadState.class, new PlayerReloadState());
|
||||||
|
registerState(PlayerWaitState.class, new PlayerWaitState());
|
||||||
|
registerState(PlayerSpectatorState.class, new PlayerSpectatorState());
|
||||||
|
registerState(PlayerPopupState.class, new PlayerPopupState());
|
||||||
|
registerState(PlayerEndState.class, new PlayerEndState());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Class<?>, StateBase<?>> state_map = new HashMap<>();
|
||||||
|
|
||||||
|
public static void registerState(Class<?> cls, StateBase<?> state) {
|
||||||
|
state_map.put(cls, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StateBase<?> getState(Class<?> cls) {
|
||||||
|
StateBase<?> state = state_map.get(cls);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void info(String msg, Object... params) {
|
||||||
|
if (loggerDebug) {
|
||||||
|
logger.info(Util.stringFormat(msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String msg, Object... params) {
|
||||||
|
if (loggerDebug) {
|
||||||
|
logger.warn(Util.stringFormat(msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String msg, Object... params) {
|
||||||
|
if (loggerDebug) {
|
||||||
|
logger.error(Util.stringFormat(msg, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 圈子订阅服务
|
||||||
|
*/
|
||||||
|
public class GroupPublisherService {
|
||||||
|
public static final String CHANNEL_NAME = "mgr_group";
|
||||||
|
|
||||||
|
private static final String CMD_DEL_ROOM="del_room";
|
||||||
|
private static final String CMD_UPDATE_ROOM="update_room";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除房间事件
|
||||||
|
* @param groupId
|
||||||
|
* @param roomid
|
||||||
|
*/
|
||||||
|
public static void delRoomEvt(int groupId,String roomid) {
|
||||||
|
if(groupId == 0)return;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putUtfString("roomid", roomid);
|
||||||
|
data.putUtfString("cmd", CMD_DEL_ROOM);
|
||||||
|
Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新房间事件
|
||||||
|
* @param groupId
|
||||||
|
* @param roomid
|
||||||
|
*/
|
||||||
|
public static void updateRoomEvt(int groupId,String roomid) {
|
||||||
|
if(groupId == 0)return;
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("gid", groupId);
|
||||||
|
data.putUtfString("roomid", roomid);
|
||||||
|
data.putUtfString("cmd", CMD_UPDATE_ROOM);
|
||||||
|
Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,172 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jdom.Document;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.input.SAXBuilder;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.events.Event;
|
||||||
|
import com.taurus.core.events.IEventListener;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.routes.Extension;
|
||||||
|
import com.taurus.core.routes.Routes;
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
import com.taurus.permanent.TPServer;
|
||||||
|
import com.taurus.permanent.core.TPEvents;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class MainServer extends Extension implements IEventListener{
|
||||||
|
|
||||||
|
public static MainServer instance;
|
||||||
|
|
||||||
|
private static final String GMAE_CONFIG = "config/game-config.xml";
|
||||||
|
public GameSetting gameSetting;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
Global.logger = Logger.getLogger(getClass());
|
||||||
|
try {
|
||||||
|
loadConfig();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Global.init();
|
||||||
|
|
||||||
|
TPServer.me().getEventManager().addEventListener(TPEvents.EVENT_SESSION_DISCONNECT, this);
|
||||||
|
|
||||||
|
Map<String, String> svr_info = new HashMap<>();
|
||||||
|
svr_info.put("ip", gameSetting.host);
|
||||||
|
svr_info.put("port", gameSetting.port + "");
|
||||||
|
svr_info.put("intranet", gameSetting.intranet);
|
||||||
|
svr_info.put("conns", "0");
|
||||||
|
String svr_key = "svr" +gameSetting.serverId;
|
||||||
|
Global.gameId = gameSetting.gameId;
|
||||||
|
Global.gameName = Redis.use("group1_db1").hget("game:" + Global.gameId, "name");
|
||||||
|
Global.loggerDebug = gameSetting.loggerDebug;
|
||||||
|
Redis.use().hmset(svr_key, svr_info);
|
||||||
|
Redis.use().expire(svr_key, 60);
|
||||||
|
TPServer.me().getTimerPool().scheduleAtFixedRate(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
svr_info.put("conns", Global.sessionMgr.size() + "");
|
||||||
|
Redis.use().hmset(svr_key, svr_info);
|
||||||
|
Redis.use().expire(svr_key, 60);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 30, 30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
List<Player> list = Global.sessionMgr.getPlayerList();
|
||||||
|
for (Player p : list) {
|
||||||
|
Global.sessionMgr.deleteSession(p.sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Room newRoom(String roomid, Map<String, String> redis_room_map);
|
||||||
|
|
||||||
|
public abstract Player newPlayer(int playerid, Room room, String session_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建游戏控制器
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract GameController newController();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送事件给单一客户端
|
||||||
|
* @param cmdName 事件协议号
|
||||||
|
* @param params 数据参数
|
||||||
|
* @param recipient 客户端session
|
||||||
|
*/
|
||||||
|
public void sendEvent(String cmdName, ITObject params, Session recipient) {
|
||||||
|
TPServer.me().getController().sendEvent(cmdName, params, recipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送事件给客户端
|
||||||
|
* @param cmdName 事件协议号
|
||||||
|
* @param params 数据参数
|
||||||
|
* @param recipients 客户端session列表
|
||||||
|
*/
|
||||||
|
public void sendEvent(String cmdName, ITObject params, List<Session> recipients) {
|
||||||
|
TPServer.me().getController().sendEvent(cmdName, params, recipients);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态响应客户端请示
|
||||||
|
* @param gid 响应标识ID
|
||||||
|
* @param result 响应结果 0成功
|
||||||
|
* @param params 数据参数
|
||||||
|
* @param recipient 客户端session
|
||||||
|
*/
|
||||||
|
public void sendResponse(int gid, int result, ITObject params, Session recipient) {
|
||||||
|
TPServer.me().getController().sendResponse(gid, result, params, recipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadConfig() throws Exception {
|
||||||
|
FileInputStream is = new FileInputStream(GMAE_CONFIG);
|
||||||
|
SAXBuilder builder = new SAXBuilder();
|
||||||
|
Document document = builder.build(is);
|
||||||
|
Element root = document.getRootElement();
|
||||||
|
GameSetting config = new GameSetting();
|
||||||
|
config.host = root.getChildTextTrim("host");
|
||||||
|
config.port = Integer.parseInt(root.getChildTextTrim("port"));
|
||||||
|
config.serverId = Integer.parseInt(root.getChildTextTrim("serverId"));
|
||||||
|
config.gameId = Integer.parseInt(root.getChildTextTrim("gameId"));
|
||||||
|
config.loggerDebug =Boolean.parseBoolean(root.getChildTextTrim("loggerDebug"));
|
||||||
|
config.intranet = root.getChildTextTrim("intranet");
|
||||||
|
this.gameSetting = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event event) {
|
||||||
|
if (event.getName() == TPEvents.EVENT_SESSION_DISCONNECT) {
|
||||||
|
Session session = (Session) event.getParameter(TPEvents.PARAM_SESSION);
|
||||||
|
Global.sessionMgr.disconnect(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configRoute(Routes me) {
|
||||||
|
me.setInterceptor(new GameInterceptor());
|
||||||
|
Global.gameCtr = newController();
|
||||||
|
me.add("",Global.gameCtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class GameSetting {
|
||||||
|
public String host = "127.0.0.1";
|
||||||
|
public String intranet = "127.0.0.1";
|
||||||
|
public int port = 6379;
|
||||||
|
public int serverId = 1;
|
||||||
|
public int gameId = 1;
|
||||||
|
public boolean loggerDebug = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络路由处理
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class Router {
|
||||||
|
/**
|
||||||
|
* 删除房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_REMOVE_ROOM = "1000";
|
||||||
|
/**
|
||||||
|
* 更新GPS位置
|
||||||
|
*/
|
||||||
|
public static final String GAME_UPDATE_POS = "1001";
|
||||||
|
/**
|
||||||
|
* 更新GPS位置事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_UPDATE_POS = "2000";
|
||||||
|
/**
|
||||||
|
* 进入房
|
||||||
|
*/
|
||||||
|
public static final String GAME_JOIN_ROOM = "1002";
|
||||||
|
/**
|
||||||
|
* 玩家进入房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_JOIN = "2001";
|
||||||
|
/**
|
||||||
|
* 玩家退出
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_EXIT = "2002";
|
||||||
|
/**
|
||||||
|
* 玩家网络状态
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_PLAYER_NET_STATE = "2003";
|
||||||
|
/**
|
||||||
|
* 发送聊天
|
||||||
|
*/
|
||||||
|
public static final String GAME_INTERACTION = "1006";
|
||||||
|
/**
|
||||||
|
* 聊天事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_INTERACTION = "2017";
|
||||||
|
/**
|
||||||
|
* 退出房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_EXIT_ROOM = "1005";
|
||||||
|
/**
|
||||||
|
* 房主退出房间解散
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_EXIT_ROOM_DISMISS = "2008";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送准备
|
||||||
|
*/
|
||||||
|
public static final String GAME_READY = "1003";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送准备加洗牌
|
||||||
|
*/
|
||||||
|
public static final String GAME_READY_AND_XIPAI = "201004";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备加洗牌 返回
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_READY_AND_XIPAI = "202009";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_READY = "2009";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知托管倒计时
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_READY_ENTRUST = "22010";
|
||||||
|
public static final String GAME_EVT_CANCEL_READY_ENTRUST = "22011";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String GAME_XIPAI = "20836";
|
||||||
|
|
||||||
|
public static final String GAME_EVENT_XIPAI = "20837";
|
||||||
|
|
||||||
|
public static final String GAME_EVENT_NOTIFY_XIPAI = "20838";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求开始游戏
|
||||||
|
*/
|
||||||
|
public static final String GAME_START = "1004";
|
||||||
|
/**
|
||||||
|
* 请求解散房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_ASK_DISMISS_ROOM = "1007";
|
||||||
|
/**
|
||||||
|
* 解散房间
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISMISS_ROOM = "2005";
|
||||||
|
/**
|
||||||
|
* 请求解散房间投票
|
||||||
|
*/
|
||||||
|
public static final String GAME_DISMISS_ROOM_VOTE = "1008";
|
||||||
|
/**
|
||||||
|
* 解散房间投票事件
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISMISS_ROOM_VOTE = "2006";
|
||||||
|
/**
|
||||||
|
* 解散房间失败
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_DISMISS_ROOM_FAIL= "2027";
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_SEND_REDPACKET= "3000";
|
||||||
|
/**
|
||||||
|
* 玩家被退出
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_KICK_PLAYER= "3001";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家缺体力值弹起
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_STAND_UP= "3004";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*/
|
||||||
|
public static final String GAME_ENTRUST= "1301";
|
||||||
|
/**
|
||||||
|
* 入座
|
||||||
|
*/
|
||||||
|
public static final String GAME_JOIN_SEAT= "1302";
|
||||||
|
/**
|
||||||
|
* 自动
|
||||||
|
*/
|
||||||
|
public static final String GAME_AUTO_CARD = "1303";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家进入观众席
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_JOIN_SPECTATOR= "3002";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新玩家信息
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT_UPDATE_PLAYERINFO= "3003";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端数据出错,需要重连服务器,更新关键数据
|
||||||
|
*/
|
||||||
|
public static final String GAME_EVT__UPDATE_RECONECT = "3005";
|
||||||
|
|
||||||
|
public void handel(Session sender, ITObject params, int gid){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void handelRoom(Player owner, ITObject params, int gid);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,298 @@
|
||||||
|
package com.game;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.data.cache.GroupMemberCache;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public final static Random random = new Random();
|
||||||
|
static {
|
||||||
|
random.setSeed(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list to TArray
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final ITArray toTArray(List<Integer> list) {
|
||||||
|
ITArray result = new TArray();
|
||||||
|
for (Integer card : list) {
|
||||||
|
result.addInt(card);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call checkCard
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static boolean cardInList(int eventCard, List<Integer> cardList) {
|
||||||
|
return checkCard(eventCard, cardList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static final ITArray toMPGroup(List<int[]> list) {
|
||||||
|
ITArray result = new TArray();
|
||||||
|
for (int[] card : list) {
|
||||||
|
result.addInt(card[0]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list to mod 100 list
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final List<Integer> toModList(List<Integer> list){
|
||||||
|
List<Integer> tem = new ArrayList<Integer>();
|
||||||
|
for(Integer card : list) {
|
||||||
|
tem.add(card % 100);
|
||||||
|
}
|
||||||
|
return tem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TArray to mod 100 list
|
||||||
|
* @param list
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final List<Integer> toModList(ITArray list){
|
||||||
|
List<Integer> tem = new ArrayList<>();
|
||||||
|
for(int i=0;i<list.size();++i) {
|
||||||
|
tem.add(list.getInt(i) % 100);
|
||||||
|
}
|
||||||
|
return tem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取已自己为起点的位置
|
||||||
|
* @param self_seat
|
||||||
|
* @param seat
|
||||||
|
* @param people_num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final int getPos(int self_seat, int seat, int people_num) {
|
||||||
|
int cur_seat = self_seat;
|
||||||
|
int tem = seat - (cur_seat - 1);
|
||||||
|
if (tem <= 0)
|
||||||
|
tem += people_num;
|
||||||
|
return tem - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取列表中牌数量
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final int cardNum(int eventCard, List<Integer> cardList) {
|
||||||
|
int result = 0;
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (card == eventCard) {
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌是否存在
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean checkCard(int eventCard, List<Integer> cardList) {
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (card == eventCard) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌数量
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean checkCard(int eventCard, List<Integer> cardList, int num) {
|
||||||
|
int result = 0;
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (card == eventCard) {
|
||||||
|
result++;
|
||||||
|
if (result == num)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌数量并将满足条件的删除
|
||||||
|
* @param eventCard
|
||||||
|
* @param cardList
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final boolean checkCardAndRomve(int eventCard, List<Integer> cardList, int num) {
|
||||||
|
if (checkCard(eventCard, cardList, num)) {
|
||||||
|
removeCard(cardList, eventCard, num);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取每张牌的数量MAP
|
||||||
|
* @param cardList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final Map<Integer, Integer> getCardNumMap(List<Integer> cardList) {
|
||||||
|
Map<Integer, Integer> result = new HashMap<Integer, Integer>();
|
||||||
|
for (Integer card : cardList) {
|
||||||
|
if (!result.containsKey(card)) {
|
||||||
|
result.put(card, 1);
|
||||||
|
} else {
|
||||||
|
int num = result.get(card);
|
||||||
|
result.put(card, (num + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测牌数量
|
||||||
|
* @param map
|
||||||
|
* @param card
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean cardNum(Map<Integer, Integer> map, int card, int num) {
|
||||||
|
Integer _num = map.get(card);
|
||||||
|
if (_num != null && _num >= num) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除指定数量的牌
|
||||||
|
* @param cardList
|
||||||
|
* @param card
|
||||||
|
* @param count
|
||||||
|
*/
|
||||||
|
public static final void removeCard(List<Integer> cardList, int card, int count) {
|
||||||
|
int curCount = 0;
|
||||||
|
for (int i = 0; i < cardList.size(); i++) {
|
||||||
|
if (cardList.get(i) == card) {
|
||||||
|
cardList.remove(i);
|
||||||
|
i--;
|
||||||
|
curCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == curCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final public void addCard(ITArray opcard, int card, int num) {
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
opcard.addInt(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final public void addCard(List<Integer> cardList, int card, int num) {
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
cardList.add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取今天凌晨0点时间戳
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int todayTimeSec() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
||||||
|
int timeSec = (int) (cal.getTimeInMillis() / 1000);
|
||||||
|
return timeSec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间戳获取指定当天凌晨10位时间戳
|
||||||
|
* @param timeSec
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int todayTimeSec(Long timeSec) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
// 指定日期
|
||||||
|
cal.setTime(new Date(timeSec));
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
cal.set(Calendar.MINUTE, 0);
|
||||||
|
cal.set(Calendar.SECOND, 0);
|
||||||
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
return (int) (cal.getTimeInMillis() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* msg ps : param:{},param:{}
|
||||||
|
* ==> param: abc,param:abced
|
||||||
|
* @param msg
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String stringFormat(String msg, Object... params) {
|
||||||
|
try {
|
||||||
|
if (StringUtil.isNotEmpty(msg)) {
|
||||||
|
msg = msg.replaceAll("\\{}", "\\%s");
|
||||||
|
return String.format(msg, params);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void countLog(String key,int num,Jedis jedis) {
|
||||||
|
// String day_key = key + ":d"+DateUtils.getBeginDay();
|
||||||
|
// String week_key = key + ":w"+DateUtils.getBeginWeek();
|
||||||
|
// String month_key = key + ":m"+DateUtils.getBeginMonth();
|
||||||
|
// jedis.incrBy(day_key,num);
|
||||||
|
// jedis.expire(day_key, 11*3600*24);
|
||||||
|
// jedis.incrBy(week_key,num);
|
||||||
|
// jedis.expire(week_key, 15*3600*24);
|
||||||
|
// jedis.incrBy(month_key,num);
|
||||||
|
// jedis.expire(month_key, 63*3600*24);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取玩家体力值
|
||||||
|
* @param gid
|
||||||
|
* @param uid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long readRedisHp(int gid,int uid) {
|
||||||
|
String key = GroupMemberCache.genKey(gid, uid);
|
||||||
|
String hp = Redis.use("group1_db10").hget(key, "hp");
|
||||||
|
long cur_hp = StringUtil.isNotEmpty(hp) ? Long.parseLong(hp) : 0;
|
||||||
|
return cur_hp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.util.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回放数据记录
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class BasePlayBack {
|
||||||
|
/**
|
||||||
|
* 房间信息
|
||||||
|
*/
|
||||||
|
protected ITObject info;
|
||||||
|
/**
|
||||||
|
* 指令列表
|
||||||
|
*/
|
||||||
|
protected ITArray cmdList;
|
||||||
|
|
||||||
|
protected BasePlayBack(Room room) {
|
||||||
|
info = TObject.newInstance();
|
||||||
|
cmdList = TArray.newInstance();
|
||||||
|
info.putUtfString("roomid", room.roomid);
|
||||||
|
info.putInt("round", room.round);
|
||||||
|
info.putTObject("config", room.config);
|
||||||
|
info.putInt("banker_seat", room.bankerSeat);
|
||||||
|
info.putInt("active_seat", room.activeSeat);
|
||||||
|
info.putInt("game_id", Global.gameId);
|
||||||
|
|
||||||
|
ITArray infoList = new TArray();
|
||||||
|
for (Entry<Integer, Player> entry : room.playerMapByPlaying.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
if(player.already_round==0)continue;
|
||||||
|
ITObject obj = getPlayerInfo(player);
|
||||||
|
infoList.addTObject(obj);
|
||||||
|
}
|
||||||
|
info.putTArray("playerData", infoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITObject getPlayerInfo(Player player) {
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putInt("aid", player.playerid);
|
||||||
|
obj.putUtfString("nick", player.nick);
|
||||||
|
obj.putInt("sex", player.sex);
|
||||||
|
obj.putUtfString("portrait", player.portrait);
|
||||||
|
obj.putInt("seat", player.seat);
|
||||||
|
player.hp_info(obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addCommand(String cmd, int seat, ITObject data) {
|
||||||
|
ITObject cmdObj = TObject.newInstance();
|
||||||
|
cmdObj.putUtfString("cmd", cmd);
|
||||||
|
cmdObj.putInt("seat", seat);
|
||||||
|
cmdObj.putTObject("data", data);
|
||||||
|
cmdList.addTObject(cmdObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取战绩回放数据,保存到redisd
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ITObject getData() {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putTObject("info", info);
|
||||||
|
data.putTArray("cmdList", cmdList);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 给客户端的提示按钮
|
||||||
|
* @param seat
|
||||||
|
* @param cmdData
|
||||||
|
*/
|
||||||
|
public void addTipCommand(int seat, ITObject cmdData) {
|
||||||
|
addCommand("Tip", seat, cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家操作点击的提示
|
||||||
|
* @param seat
|
||||||
|
* @param type
|
||||||
|
* @param weight
|
||||||
|
*/
|
||||||
|
public void addClickTipCommand(int seat, int type, int weight) {
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
cmdData.putInt("weight", weight);
|
||||||
|
cmdData.putInt("type", type);
|
||||||
|
addCommand("ClickTip", seat, cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小结算数据
|
||||||
|
*/
|
||||||
|
public void addResult(ITObject resultData) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
Utils.objectCopyDeep(resultData, data);
|
||||||
|
data.putInt("type", 0);
|
||||||
|
addCommand("Result", 0, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
public class Hp {
|
||||||
|
/**
|
||||||
|
* 当前体力值,每局更新,用于判断当局能输赢多少
|
||||||
|
*/
|
||||||
|
public long cur_hp = 0;
|
||||||
|
/**
|
||||||
|
* 牌局开始到结束,总输赢体力值,不包括奖励体力值。因命名之前没有奖励一说
|
||||||
|
*/
|
||||||
|
public int total_hp = 0;
|
||||||
|
/**
|
||||||
|
* 当局实际输赢体力值
|
||||||
|
*/
|
||||||
|
public int round_actual_hp = 0;
|
||||||
|
/**
|
||||||
|
* 当局本应输赢体力值
|
||||||
|
*/
|
||||||
|
public int round_answer_hp = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输赢是否已达上限
|
||||||
|
*/
|
||||||
|
public boolean upper_limit = false;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
public class JoinRoomData {
|
||||||
|
public Room room;
|
||||||
|
public String session_key;
|
||||||
|
public Session sender;
|
||||||
|
public String gps_pos;
|
||||||
|
public boolean test_user;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,606 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.MainServer;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReloadState;
|
||||||
|
import com.game.state.StateMachine;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import com.taurus.permanent.TPServer;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本玩家对象
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Player {
|
||||||
|
/**
|
||||||
|
* 所在房间对象
|
||||||
|
*/
|
||||||
|
public Room room = null;
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
public int playerid = 0;
|
||||||
|
|
||||||
|
public String ip = null;
|
||||||
|
/**
|
||||||
|
* redis session id
|
||||||
|
*/
|
||||||
|
public String session_id = StringUtil.Empty;
|
||||||
|
public String score_key = StringUtil.Empty;
|
||||||
|
public String net_key = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* 玩家状态机
|
||||||
|
*/
|
||||||
|
public StateMachine stateMachine = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mpnet session
|
||||||
|
*/
|
||||||
|
public volatile Session sender = null;
|
||||||
|
/**
|
||||||
|
* 是否正在链接
|
||||||
|
*/
|
||||||
|
public volatile boolean isConnect = false;
|
||||||
|
/**
|
||||||
|
* 是否是重连
|
||||||
|
*/
|
||||||
|
public boolean isReload = false;
|
||||||
|
/**
|
||||||
|
* 是否被摧毁
|
||||||
|
*/
|
||||||
|
public volatile boolean isDestroy = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前座位号
|
||||||
|
*/
|
||||||
|
public int seat = 0;
|
||||||
|
public int nextSeat = 0;
|
||||||
|
public int lastSeat = 0;
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
public String nick = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* 性别
|
||||||
|
*/
|
||||||
|
public int sex = 1;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
public String portrait = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* GPS位置
|
||||||
|
*/
|
||||||
|
public String gps_pos = StringUtil.Empty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0 无 1 胡 2 输
|
||||||
|
*/
|
||||||
|
public int winer = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 胡牌统计
|
||||||
|
*/
|
||||||
|
public int winCount = 0;
|
||||||
|
/**
|
||||||
|
* 准备状态
|
||||||
|
*/
|
||||||
|
public boolean ready = false;
|
||||||
|
|
||||||
|
public boolean is_white = false;
|
||||||
|
|
||||||
|
public int black_white_status = 0;
|
||||||
|
|
||||||
|
public double black_white_rate = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解散房间状态
|
||||||
|
*/
|
||||||
|
public int dismissState = 0;
|
||||||
|
/**
|
||||||
|
* 申请解散次数
|
||||||
|
*/
|
||||||
|
public int dismissCount = 0;
|
||||||
|
/**
|
||||||
|
* 计分统计
|
||||||
|
*/
|
||||||
|
public Score score;
|
||||||
|
/**
|
||||||
|
* action计时器
|
||||||
|
*/
|
||||||
|
public Timer actionTimer;
|
||||||
|
/**
|
||||||
|
* 计时器
|
||||||
|
*/
|
||||||
|
public Timer timer;
|
||||||
|
public volatile long offlineTime;
|
||||||
|
/**
|
||||||
|
* 抽水值
|
||||||
|
*/
|
||||||
|
public int practicalHpPump = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽水实际值
|
||||||
|
*/
|
||||||
|
public int practicalHpPumpReal = 0;
|
||||||
|
/**
|
||||||
|
* 奖励数据
|
||||||
|
*/
|
||||||
|
public String prs = StringUtil.Empty;
|
||||||
|
/**
|
||||||
|
* 托管
|
||||||
|
*/
|
||||||
|
public volatile boolean entrust = false;
|
||||||
|
/**
|
||||||
|
* 自动出牌
|
||||||
|
*/
|
||||||
|
public volatile boolean manualAutoCard = false;
|
||||||
|
/**
|
||||||
|
* 是否正在观看
|
||||||
|
*/
|
||||||
|
public volatile boolean spectator = false;
|
||||||
|
/**
|
||||||
|
* 已玩局数
|
||||||
|
*/
|
||||||
|
public int already_round = 0;
|
||||||
|
/**
|
||||||
|
* 体力值
|
||||||
|
*/
|
||||||
|
public Hp hp;
|
||||||
|
/**
|
||||||
|
* 托管局数
|
||||||
|
*/
|
||||||
|
public int entrust_round = 0;
|
||||||
|
/**
|
||||||
|
* 是否检测退出限制
|
||||||
|
*/
|
||||||
|
public boolean check_exit_limit = true;
|
||||||
|
|
||||||
|
public boolean xi_pai = false;
|
||||||
|
/**
|
||||||
|
* 抽水值total
|
||||||
|
*/
|
||||||
|
public int xi_pai_total = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public Player(int playerid, Room table, String session_id) {
|
||||||
|
this.room = table;
|
||||||
|
this.playerid = playerid;
|
||||||
|
this.session_id = session_id;
|
||||||
|
this.score_key = "score_" + playerid;
|
||||||
|
this.net_key = "net_" + playerid;
|
||||||
|
this.score = newScore();
|
||||||
|
this.stateMachine = new StateMachine(this);
|
||||||
|
this.isReload = false;
|
||||||
|
this.hp = new Hp();
|
||||||
|
this.xi_pai = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Score newScore() {
|
||||||
|
return new Score(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置玩家session
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
*/
|
||||||
|
public void setSender(Session sender) {
|
||||||
|
// 服务器从崩溃中重启
|
||||||
|
if (sender == null) {
|
||||||
|
this.isReload = true;
|
||||||
|
this.isConnect = false;
|
||||||
|
this.stateMachine.changeState(Global.getState(PlayerReloadState.class));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.isConnect && this.sender != null && this.sender != sender) {
|
||||||
|
Global.sessionMgr.deleteSession(this.sender);
|
||||||
|
TPServer.me().getController().disconnect(this.sender);
|
||||||
|
}
|
||||||
|
// 已经连接
|
||||||
|
this.sender = sender;
|
||||||
|
Global.sessionMgr.putPlayer(sender, this);
|
||||||
|
this.isConnect = true;
|
||||||
|
// if (this.stateMachine.curState == null || this.isReload) {
|
||||||
|
// this.stateMachine.changeState(Global.getState(PlayerInitState.class));
|
||||||
|
this.isReload = false;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计时器,Ps 到某状态自动执行某操作
|
||||||
|
*
|
||||||
|
* @param time 时间 ms
|
||||||
|
* @param cmd 计时完执行事件
|
||||||
|
* @param param 执行事件参数
|
||||||
|
*/
|
||||||
|
public void startTimer(int time, String cmd, Object param) {
|
||||||
|
stopTimer();
|
||||||
|
this.timer = new Timer(time, new Timer.ITaskHandler() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void doTask(Timer timer) {
|
||||||
|
Global.info("{} [{}] Timer Excute ActionEvent [{}] param :{}", Player.this.toString(),
|
||||||
|
stateMachine.curState.getClass().getSimpleName(), cmd,
|
||||||
|
param == null ? "null" : param.toString());
|
||||||
|
stateMachine.curState.execute(Player.this, cmd, 0, param);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
room.addTimer(this.timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定时间计时, cmd :timer_auto
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
*/
|
||||||
|
public void startTimer(int time) {
|
||||||
|
startTimer(time, ActionEvent.EVENT_TIMER_AUTO, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认配置计时器 time : 1000ms cmd : timer_auto
|
||||||
|
*/
|
||||||
|
public void startTimer() {
|
||||||
|
startTimer(room.def_actionTimer_time, ActionEvent.EVENT_TIMER_AUTO, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopTimer() {
|
||||||
|
if (this.timer != null) {
|
||||||
|
this.timer.stop();
|
||||||
|
this.timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止所有计时器,如玩家退出某状态时
|
||||||
|
*/
|
||||||
|
public void stopAllTimer() {
|
||||||
|
stopTimer();
|
||||||
|
stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管计时器
|
||||||
|
*
|
||||||
|
* @param time 单位毫秒
|
||||||
|
*/
|
||||||
|
public void startActionTimer(int time, Object param) {
|
||||||
|
stopActionTimer();
|
||||||
|
this.actionTimer = new Timer(time, new Timer.ITaskHandler() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void doTask(Timer timer) {
|
||||||
|
String type = "";
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type) && !entrust) {
|
||||||
|
entrust = true;
|
||||||
|
Global.gameCtr.updatePlayerEntrust(Player.this);
|
||||||
|
}
|
||||||
|
Global.info("{} [{}] Entrust Auto Execute ActionEvent", Player.this.toString(),
|
||||||
|
stateMachine.curState.getClass().getSimpleName());
|
||||||
|
stateMachine.curState.execute(Player.this, ActionEvent.EVENT_TIMER_AUTO, 0, param);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
String type = "";
|
||||||
|
int broad = 0;
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
if (netParam.containsKey("broad")) {
|
||||||
|
broad = netParam.getInt("broad");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type) && broad == 1) {
|
||||||
|
this.actionTimer.parameters.put("param", param);
|
||||||
|
}
|
||||||
|
room.addTimer(this.actionTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param time 单位毫秒
|
||||||
|
*/
|
||||||
|
public void startActionTimer(int time) {
|
||||||
|
startActionTimer(time, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEntrust() {
|
||||||
|
return this.room.isEntrust() && this.entrust;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 托管.
|
||||||
|
*/
|
||||||
|
public void startActionTimer() {
|
||||||
|
stopActionTimer();
|
||||||
|
int lt = getEntrustActionLeftTime();
|
||||||
|
if (room.isEntrust() && lt <= 0) {
|
||||||
|
ITObject param = TObject.newInstance();
|
||||||
|
param.putUtfString("type", ActionEvent.EVENT_ENTRUST);
|
||||||
|
|
||||||
|
if (isEntrust()) {
|
||||||
|
param.putInt("broad", 0);
|
||||||
|
startActionTimer(this.room.default_entrust_time, param);
|
||||||
|
} else {
|
||||||
|
param.putInt("broad", 1);
|
||||||
|
startActionTimer(this.room.entrustTime, param);
|
||||||
|
Global.gameCtr.entrust(Player.this, this.room.entrustTime / 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopActionTimer() {
|
||||||
|
if (this.actionTimer != null) {
|
||||||
|
if (this.actionTimer.parameters.containsKey("param")) {
|
||||||
|
ITObject param = (ITObject) this.actionTimer.parameters.get("param");
|
||||||
|
String type = "";
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type)) {
|
||||||
|
Global.gameCtr.cancelEntrust(Player.this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.actionTimer.stop();
|
||||||
|
this.actionTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActionLeftTime() {
|
||||||
|
if (this.actionTimer != null) {
|
||||||
|
return Math.abs(this.actionTimer.getCountdownTime() / 1000);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEntrustActionLeftTime() {
|
||||||
|
if (this.actionTimer != null) {
|
||||||
|
if (this.actionTimer.parameters.containsKey("param")) {
|
||||||
|
ITObject param = (ITObject) this.actionTimer.parameters.get("param");
|
||||||
|
String type = "";
|
||||||
|
if (param != null) {
|
||||||
|
ITObject netParam = (ITObject) param;
|
||||||
|
if (netParam.containsKey("type")) {
|
||||||
|
type = netParam.getUtfString("type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ActionEvent.EVENT_ENTRUST.equals(type)) {
|
||||||
|
return Math.abs(this.actionTimer.getCountdownTime() / 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回结果
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @param gid
|
||||||
|
* @param error
|
||||||
|
*/
|
||||||
|
public void response(ITObject params, int gid, int error) {
|
||||||
|
if (!this.isConnect)
|
||||||
|
return;
|
||||||
|
if (error == 0) {
|
||||||
|
MainServer.instance.sendResponse(gid, error, params, this.sender);
|
||||||
|
} else {
|
||||||
|
MainServer.instance.sendResponse(gid, error, null, this.sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送事件给客户端
|
||||||
|
*
|
||||||
|
* @param cmd
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
public void sendEvent(String cmd, ITObject param) {
|
||||||
|
if (!this.isConnect)
|
||||||
|
return;
|
||||||
|
MainServer.instance.sendEvent(cmd, param, this.sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取玩家信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ITObject getInfo() {
|
||||||
|
ITObject playerData = new TObject();
|
||||||
|
playerData.putInt("aid", this.playerid);
|
||||||
|
playerData.putUtfString("nick", this.nick);
|
||||||
|
playerData.putInt("sex", this.sex);
|
||||||
|
playerData.putUtfString("portrait", this.portrait);
|
||||||
|
if (StringUtil.isNotEmpty(gps_pos)) {
|
||||||
|
playerData.putUtfString("pos", gps_pos);
|
||||||
|
}
|
||||||
|
String ip = this.ip;
|
||||||
|
if (this.ip == null && this.sender != null) {
|
||||||
|
ip = sender.getAddress();
|
||||||
|
}
|
||||||
|
playerData.putInt("ready", this.ready ? 1 : 0);
|
||||||
|
playerData.putUtfString("ip", ip);
|
||||||
|
playerData.putInt("seat", this.seat);
|
||||||
|
playerData.putInt("online", this.isConnect ? 1 : 0);
|
||||||
|
playerData.putBoolean("spectator", spectator);
|
||||||
|
if (this.room.openEntrust) {
|
||||||
|
playerData.putBoolean("entrust", this.entrust);
|
||||||
|
playerData.putInt("entrust_time", getEntrustActionLeftTime());
|
||||||
|
}
|
||||||
|
hp_info(playerData);
|
||||||
|
// if (Redis.use().hexists(this.session_id, "offLineTime")) {
|
||||||
|
// int offLineTime = Integer.parseInt(Redis.use().hget(this.session_id,
|
||||||
|
// "offLineTime"));
|
||||||
|
// playerData.putInt("offLineTime", Utils.differSecond(offLineTime));
|
||||||
|
// }
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getReloadInfo(boolean self) {
|
||||||
|
ITObject playerData = new TObject();
|
||||||
|
playerData.putInt("playerid", playerid);
|
||||||
|
if (this.room.openEntrust && this.room.isEntrust) {
|
||||||
|
playerData.putBoolean("entrust", this.entrust);
|
||||||
|
playerData.putInt("entrust_time", getEntrustActionLeftTime());
|
||||||
|
|
||||||
|
Global.logger.info("entrust_time getEntrustActionLeftTime() : " + getEntrustActionLeftTime());
|
||||||
|
}
|
||||||
|
playerData.putBoolean("popup", this.stateMachine.curState instanceof PlayerPopupState);
|
||||||
|
hp_info(playerData);
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家销毁时调用
|
||||||
|
*
|
||||||
|
* @param sysredis
|
||||||
|
*/
|
||||||
|
public void destroy(boolean sysredis) {
|
||||||
|
if (isDestroy)
|
||||||
|
return;
|
||||||
|
isDestroy = true;
|
||||||
|
stopActionTimer();
|
||||||
|
this.room.removePlayer(this, sysredis);
|
||||||
|
if (this.sender != null) {
|
||||||
|
Global.sessionMgr.deleteSession(sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int __checkSeat(int seat, int count, boolean add) {
|
||||||
|
if (seat > this.room.maxPlayers) {
|
||||||
|
seat = 1;
|
||||||
|
} else if (seat <= 0) {
|
||||||
|
seat = this.room.maxPlayers;
|
||||||
|
}
|
||||||
|
if (count == this.room.maxPlayers)
|
||||||
|
return seat;
|
||||||
|
Player player = this.room.playerMapBySeat.get(seat);
|
||||||
|
if (player == null || player.spectator) {
|
||||||
|
if (add)
|
||||||
|
seat = seat + 1;
|
||||||
|
else
|
||||||
|
seat = seat - 1;
|
||||||
|
count++;
|
||||||
|
return __checkSeat(seat, count, add);
|
||||||
|
}
|
||||||
|
return seat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化座位信息
|
||||||
|
*/
|
||||||
|
public void initSeat() {
|
||||||
|
this.nextSeat = __checkSeat(this.seat + 1, 1, true);
|
||||||
|
this.lastSeat = __checkSeat(this.seat - 1, 1, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理玩家数据
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
this.winer = 0;
|
||||||
|
this.check_exit_limit = true;
|
||||||
|
this.is_white = false;
|
||||||
|
this.manualAutoCard = false;
|
||||||
|
|
||||||
|
stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册redis事件,总服处理
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
public void redisEvent(int type, int num) {
|
||||||
|
Global.eventCtr.redisEvent(playerid, type, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return session_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hp_info(ITObject param) {
|
||||||
|
ITObject hp_info = TObject.newInstance();
|
||||||
|
// 下局体力值
|
||||||
|
hp_info.putLong("cur_hp", hp.cur_hp);
|
||||||
|
// 本局实际输赢体力值
|
||||||
|
hp_info.putInt("round_actual_hp", hp.round_actual_hp);
|
||||||
|
// 输赢是否已达上限
|
||||||
|
hp_info.putBoolean("upper_limit", hp.upper_limit);
|
||||||
|
// 总输赢体力值
|
||||||
|
hp_info.putInt("total_hp", hp.total_hp);
|
||||||
|
param.putTObject("hp_info", hp_info);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前体力值
|
||||||
|
*/
|
||||||
|
public Long getHp() {
|
||||||
|
return this.hp.cur_hp + (long) this.hp.round_actual_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void updateHp() {
|
||||||
|
// this.hp.cur_hp = this.hp.cur_hp + this.hp.round_actual_hp;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void clearHp() {
|
||||||
|
this.hp.round_actual_hp = 0;
|
||||||
|
this.hp.round_answer_hp = 0;
|
||||||
|
this.hp.upper_limit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置托管数据
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
public void setEntrustData(ITObject data) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exitEntrust() {
|
||||||
|
if (this.room.isEntrust()) {
|
||||||
|
this.entrust_round = 0;
|
||||||
|
stopActionTimer();
|
||||||
|
this.entrust = false;
|
||||||
|
if (room.activeSeat == this.seat) {
|
||||||
|
startActionTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 牌局结束输赢总体力值,包括奖励体力值
|
||||||
|
*/
|
||||||
|
public int totalHp() {
|
||||||
|
return hp.total_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要抽水的具体体力值,不可负分 - 实际赢体力值,可负分 - 实际赢积分 换算成赢总体力值
|
||||||
|
*/
|
||||||
|
public int hpPumpValue() {
|
||||||
|
return hp.total_hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,155 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.data.util.ErrorCode;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Timer.ITaskHandler;
|
||||||
|
import com.game.room.state.RoomDestoryGameState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间解散处理
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomDismiss {
|
||||||
|
private Room owner;
|
||||||
|
public boolean start = false;
|
||||||
|
private boolean agree = true;
|
||||||
|
/**
|
||||||
|
* 最多申请次数,超过次数,该玩家不能申请解散
|
||||||
|
*/
|
||||||
|
private final int MAX_ASK_COUNT = 3;
|
||||||
|
|
||||||
|
private Timer timer;
|
||||||
|
private Player askPlayer;
|
||||||
|
public int maxTime = 90;
|
||||||
|
private List<Player> playerList;
|
||||||
|
|
||||||
|
public RoomDismiss(Room owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
playerList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void askDismiss(Player player, int gid) {
|
||||||
|
if (start) {
|
||||||
|
player.response(null, gid, 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (player.dismissCount >= MAX_ASK_COUNT) {
|
||||||
|
player.response(null, gid, ErrorCode.ROOM_DIS_UPPER_LIMIT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.room.isBanDismiss) {
|
||||||
|
player.response(null, gid, ErrorCode.ROOM_DIS_NOT_ALLOWED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
askPlayer = player;
|
||||||
|
startDismiss(player);
|
||||||
|
|
||||||
|
this.dismissCallback(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void responseDismiss(Player player, boolean agree) {
|
||||||
|
if (start == false || player.dismissState != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (agree) {
|
||||||
|
player.dismissState = 1;
|
||||||
|
} else {
|
||||||
|
player.dismissState = 2;
|
||||||
|
}
|
||||||
|
dismissCallback(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissCallback(Player player) {
|
||||||
|
int agreeCount = 0;
|
||||||
|
int notAgreeCount = 0;
|
||||||
|
for (Player p : playerList) {
|
||||||
|
if (p.dismissState == 1) {
|
||||||
|
agreeCount += 1;
|
||||||
|
} else if (p.dismissState == 2) {
|
||||||
|
notAgreeCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
agree = notAgreeCount == 0 && agreeCount == playerList.size();
|
||||||
|
|
||||||
|
if (agree) {
|
||||||
|
interruptTimer();
|
||||||
|
} else {
|
||||||
|
if (notAgreeCount > 0) {
|
||||||
|
Global.gameCtr.dismisRoomFail(owner);
|
||||||
|
interruptTimer();
|
||||||
|
} else {
|
||||||
|
Global.gameCtr.dismissRoom(askPlayer, null, playerList, getLeftTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void interruptTimer() {
|
||||||
|
if (timer != null)
|
||||||
|
timer.stop();
|
||||||
|
timer = null;
|
||||||
|
checkDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startDismiss(Player player) {
|
||||||
|
playerList.clear();
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player p = entry.getValue();
|
||||||
|
if (p.already_round > 0) {
|
||||||
|
playerList.add(p);
|
||||||
|
p.dismissState = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timer = new Timer(maxTime * 1000, new ITaskHandler() {
|
||||||
|
@Override
|
||||||
|
public void doTask(Timer timer) {
|
||||||
|
disMissTimeOutCallback();
|
||||||
|
Global.logger.error("[" + owner.room_key + "] room dismiss time out destroy!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
owner.addTimer(timer);
|
||||||
|
start = true;
|
||||||
|
player.dismissState = 1;
|
||||||
|
player.dismissCount++;
|
||||||
|
Global.logger.info("playerid :" + player.playerid + " ask dissmis room :" + player.room.roomid + ",dismissCount :" + player.dismissCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload(Player owner) {
|
||||||
|
if (start) {
|
||||||
|
if (playerList.contains(owner)) {
|
||||||
|
//jefe 重新加载不用重置数据
|
||||||
|
Global.gameCtr.dismissRoom(askPlayer, owner, playerList, getLeftTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLeftTime() {
|
||||||
|
return Math.abs(timer.getCountdownTime() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkDestroy() {
|
||||||
|
start = false;
|
||||||
|
if (agree) {
|
||||||
|
owner.saveMilitaryTotal(true);
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomDestoryGameState.class));
|
||||||
|
}
|
||||||
|
agree = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disMissTimeOutCallback() {
|
||||||
|
for (Player p : playerList) {
|
||||||
|
p.dismissState = 1;
|
||||||
|
}
|
||||||
|
agree = true;
|
||||||
|
checkDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家积分统计
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 2017年9月19日
|
||||||
|
*/
|
||||||
|
public class Score {
|
||||||
|
|
||||||
|
public Map<Integer, Integer> round_log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每局的积分统计
|
||||||
|
*/
|
||||||
|
public int round_score;
|
||||||
|
/**
|
||||||
|
* 每局的积分统计 对方积分不够的情况下, 会存在小数点问题
|
||||||
|
*/
|
||||||
|
public double d_real_score;
|
||||||
|
/**
|
||||||
|
* 总积分统计
|
||||||
|
*/
|
||||||
|
public int total_score;
|
||||||
|
|
||||||
|
public boolean negative_score;
|
||||||
|
|
||||||
|
protected Player owner;
|
||||||
|
|
||||||
|
public Score(Player owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.round_log = new HashMap<>();
|
||||||
|
this.negative_score = false;
|
||||||
|
this.d_real_score = 0;
|
||||||
|
this.initLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initLog() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetRound() {
|
||||||
|
this.round_log.clear();
|
||||||
|
this.initLog();
|
||||||
|
round_score = 0;
|
||||||
|
this.d_real_score = 0;
|
||||||
|
negative_score = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.game.data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Room timer class
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Timer {
|
||||||
|
private volatile boolean _start;
|
||||||
|
private int _time;
|
||||||
|
private long _lastTime;
|
||||||
|
private ITaskHandler _task;
|
||||||
|
public Map<Object, Object> parameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param time 单位毫秒
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
public Timer(int time, ITaskHandler task) {
|
||||||
|
_lastTime = System.currentTimeMillis();
|
||||||
|
_time = time;
|
||||||
|
_task = task;
|
||||||
|
this.parameters = new HashMap<Object, Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
if (_start)
|
||||||
|
return;
|
||||||
|
_start = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restart() {
|
||||||
|
_lastTime = System.currentTimeMillis();
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeTask() {
|
||||||
|
if (!_start)
|
||||||
|
return;
|
||||||
|
if (System.currentTimeMillis() - _lastTime >= _time) {
|
||||||
|
_start = false;
|
||||||
|
if (_task != null) {
|
||||||
|
_task.doTask(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取倒计时,单位毫秒
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getCountdownTime() {
|
||||||
|
return (int) (_time - (System.currentTimeMillis() - _lastTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (!_start)
|
||||||
|
return;
|
||||||
|
_start = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRuning() {
|
||||||
|
return _start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ITaskHandler {
|
||||||
|
|
||||||
|
public void doTask(Timer timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,144 @@
|
||||||
|
package com.game.manager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import com.data.util.ErrorCode;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.MainServer;
|
||||||
|
import com.game.data.JoinRoomData;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.room.state.RoomReloadState;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.plugin.redis.RedisLock;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间管理类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomManager {
|
||||||
|
|
||||||
|
public ConcurrentHashMap<String, Room> tableMap;
|
||||||
|
|
||||||
|
public RoomManager() {
|
||||||
|
this.tableMap = new ConcurrentHashMap<String, Room>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进入房间
|
||||||
|
* @param sender
|
||||||
|
* @param session_key
|
||||||
|
* @param gid
|
||||||
|
*/
|
||||||
|
public void joinRoom(Session sender, String session_key, int gid, String gps_pos) {
|
||||||
|
Jedis jedis = Redis.use().getJedis();
|
||||||
|
try {
|
||||||
|
if (!jedis.exists(session_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._NO_SESSION, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_key = jedis.hget(session_key, "room");
|
||||||
|
if(StringUtil.isEmpty(room_key)) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, String> room_map = null;
|
||||||
|
RedisLock lock = new RedisLock(room_key, jedis);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
room_map = jedis.hgetAll(room_key);
|
||||||
|
String status = room_map.get("status");
|
||||||
|
if(StringUtil.isEmpty(status)) {
|
||||||
|
Global.gameCtr.delRoomSeat(session_key, room_key);
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_ROOM_NUM, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (status.equals("3") || status.equals("2")) {
|
||||||
|
Global.gameCtr.delRoomSeat(session_key, room_key);
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.GROUP_ROOM_DEL, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Global.gameId != Integer.parseInt(room_map.get("game"))) {
|
||||||
|
Global.logger.error("joinRoom gameId:"+Global.gameId+" != gameId:" + Integer.parseInt(room_map.get("game")));
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode.NO_SERVICE, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String room_id = room_map.get("id");
|
||||||
|
Room room = null;
|
||||||
|
if (this.tableMap.containsKey(room_id)) {
|
||||||
|
room = this.tableMap.get(room_id);
|
||||||
|
if (room.isDestroy) {
|
||||||
|
MainServer.instance.sendResponse(gid, ErrorCode._FAILED, null, sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
room = MainServer.instance.newRoom(room_id, room_map);
|
||||||
|
room.loadRedisPlayer();
|
||||||
|
this.tableMap.put(room_id, room);
|
||||||
|
room.start();
|
||||||
|
room.stateMachine.changeState(Global.getState(RoomReloadState.class));
|
||||||
|
}
|
||||||
|
if (room.isActive() == false)
|
||||||
|
{
|
||||||
|
room.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.setHashId(session_key);
|
||||||
|
final JoinRoomData jrd = new JoinRoomData();
|
||||||
|
jrd.room = room;
|
||||||
|
jrd.session_key = session_key;
|
||||||
|
jrd.sender = sender;
|
||||||
|
jrd.gps_pos = gps_pos;
|
||||||
|
room.enqueueRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
int result = Global.gameCtr.joinRoom(jrd, gid);
|
||||||
|
if(result!=0) {
|
||||||
|
MainServer.instance.sendResponse(gid, result, null, sender);
|
||||||
|
}
|
||||||
|
Global.logger.info(session_key + " join [" + jrd.room.room_key + "]!");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}finally {
|
||||||
|
lock.unlock(false);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Global.logger.error(e);
|
||||||
|
MainServer.instance.sendResponse(gid, 500, null, sender);
|
||||||
|
} finally {
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解散房间
|
||||||
|
* @param roomid 房间ID
|
||||||
|
*/
|
||||||
|
public void dismissRoom(String roomid,boolean sendEvt) {
|
||||||
|
Room room = this.tableMap.get(roomid);
|
||||||
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
|
RedisLock lock = new RedisLock(room.room_key, jedis0);
|
||||||
|
try {
|
||||||
|
lock.lock();
|
||||||
|
room.destroy(sendEvt);
|
||||||
|
this.tableMap.remove(roomid);
|
||||||
|
}finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
package com.game.manager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前节点 玩家session管理类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SessionManager {
|
||||||
|
|
||||||
|
private ConcurrentMap<Session, Player> sessionMap = null;
|
||||||
|
|
||||||
|
public SessionManager() {
|
||||||
|
this.sessionMap = new ConcurrentHashMap<Session, Player>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过sessionid获取玩家
|
||||||
|
* @param sessionid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Player getPlayer(Session sessionid) {
|
||||||
|
return this.sessionMap.get(sessionid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加session
|
||||||
|
* @param sessionid
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public void putPlayer(Session sessionid, Player player) {
|
||||||
|
this.sessionMap.put(sessionid, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除session
|
||||||
|
* @param sessionid
|
||||||
|
*/
|
||||||
|
public Player deleteSession(Session sessionid) {
|
||||||
|
if(sessionid == null)return null;
|
||||||
|
sessionid.setHashId(null);
|
||||||
|
Player player = this.getPlayer(sessionid);
|
||||||
|
this.sessionMap.remove(sessionid);
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前服务器在线人数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return this.sessionMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getPlayerList(){
|
||||||
|
List<Player> list = new ArrayList<Player>();
|
||||||
|
list.addAll(sessionMap.values());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断线
|
||||||
|
* @param sender
|
||||||
|
*/
|
||||||
|
public synchronized void disconnect(Session sender) {
|
||||||
|
Player player = this.deleteSession(sender);
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.room.enqueueRunnable(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (player.isDestroy)return;
|
||||||
|
if (player.sender == sender) {
|
||||||
|
player.isConnect = false;
|
||||||
|
Global.gameCtr.playerNetState(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.Router;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerEndState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.clear();
|
||||||
|
owner.startActionTimer();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch(cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
case ActionEvent.EVENT_TIMER_AUTO:
|
||||||
|
case ActionEvent.EVENT_ENTRUST:
|
||||||
|
Global.gameCtr.ready(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_READY_AND_XIPAI:
|
||||||
|
Global.gameCtr.readyAndXipai(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_XIPAI:
|
||||||
|
if (owner.xi_pai == false)
|
||||||
|
{
|
||||||
|
owner.xi_pai = true;
|
||||||
|
ITObject param1 = new TObject();
|
||||||
|
param1.putInt("result", 0);
|
||||||
|
owner.sendEvent(Router.GAME_EVENT_XIPAI, param1);
|
||||||
|
|
||||||
|
owner.room.redisUpdateXiPaiPlayer(owner);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ITObject param1 = new TObject();
|
||||||
|
param1.putInt("result", 1);
|
||||||
|
owner.sendEvent(Router.GAME_EVENT_XIPAI, param1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家进房间的初始状态
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerInitState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Player owner) {
|
||||||
|
if(owner.room.round==0&&owner.room.kickTime>0) {
|
||||||
|
owner.startActionTimer(owner.room.kickTime * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.stopActionTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
Global.gameCtr.ready(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_READY_AND_XIPAI:
|
||||||
|
Global.gameCtr.readyAndXipai(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_EXIT_ROOM:
|
||||||
|
if(owner.room.round>0)return;
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,false);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_TIMER_AUTO:
|
||||||
|
if(owner.room.round>0)return;
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家暂停状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerPauseState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void toNextState(Player owner) {
|
||||||
|
owner.stateMachine.lastState.toNextState(owner);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.Router;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家缺体力值弹出状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerPopupState extends StateBase<Player>{
|
||||||
|
/**
|
||||||
|
* 进入状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.spectator = true;
|
||||||
|
ITObject msg = TObject.newInstance();
|
||||||
|
msg.putInt("seat", owner.seat);
|
||||||
|
owner.room.broadCastToClient(0, Router.GAME_EVT_STAND_UP, msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.spectator = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家准备状态
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerReadyState extends StateBase<Player> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.ready = true;
|
||||||
|
owner.room.stateMachine.execute(ActionEvent.EVENT_READY, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
if(owner.room.round>0)return;
|
||||||
|
if(cmd.equals(ActionEvent.EVENT_EXIT_ROOM)) {
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家重连状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerReloadState extends StateBase<Player> {
|
||||||
|
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
Global.gameCtr.ready(owner);
|
||||||
|
break;
|
||||||
|
case ActionEvent.EVENT_READY_AND_XIPAI:
|
||||||
|
Global.gameCtr.readyAndXipai(owner);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 观看状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerSpectatorState extends StateBase<Player> {
|
||||||
|
/**
|
||||||
|
* 进入状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void enter(Player owner) {
|
||||||
|
owner.spectator = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出状态时处理
|
||||||
|
*
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void exit(Player owner) {
|
||||||
|
owner.spectator = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_EXIT_ROOM:
|
||||||
|
Global.gameCtr.exitRoom(owner, gid,false);
|
||||||
|
break;
|
||||||
|
// case ActionEvent.EVENT_READY:
|
||||||
|
// if(owner.room.playerMapBySeat.containsKey(owner.seat)) {
|
||||||
|
// Global.gameCtr.ready(owner);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.game.player.state;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家等待状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PlayerWaitState extends StateBase<Player> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间结束状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomDestoryGameState extends StateBase<Room> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enter(Room owner) {
|
||||||
|
Global.roomMgr.dismissRoom(owner.roomid,true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerEndState;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
|
||||||
|
public class RoomEndState extends StateBase<Room>{
|
||||||
|
@Override
|
||||||
|
public void enter(Room owner) {
|
||||||
|
owner.saveSocre();
|
||||||
|
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
player.stateMachine.changeState( Global.getState(PlayerEndState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
if(player.stateMachine.curState instanceof PlayerPopupState) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(player.stateMachine.curState instanceof PlayerReadyState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间初始状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomInitState extends StateBase<Room> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
if (!(entry.getValue().stateMachine.curState instanceof PlayerReadyState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (owner.maxPlayers == owner.playerMapById.size()) {
|
||||||
|
owner.redis_room_map.put("open","0");
|
||||||
|
Redis.use().hmset(owner.room_key, owner.redis_room_map);
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerPopupState;
|
||||||
|
import com.game.player.state.PlayerReadyState;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间重连状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomReloadState extends StateBase<Room>{
|
||||||
|
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch (cmd) {
|
||||||
|
case ActionEvent.EVENT_READY:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
|
Player p = entry.getValue();
|
||||||
|
if (!(p.stateMachine.curState instanceof PlayerReadyState || p.stateMachine.curState instanceof PlayerPopupState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(owner.round == 0 &&owner.startGameNum == 0 && owner.playerMapBySeat.size()>1) {
|
||||||
|
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
|
||||||
|
|
||||||
|
}else {
|
||||||
|
int num = owner.startGameNum ==0 ? 2 :owner.startGameNum;
|
||||||
|
if(owner.playerMapBySeat.size() >= num) {
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
|
||||||
|
//owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间开始游戏
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomStartGameState extends StateBase<Room>{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.game.room.state;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.ActionEvent;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.state.StateBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 房间等待状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoomWaitState extends StateBase<Room> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
switch(cmd) {
|
||||||
|
case ActionEvent.EVENT_START_GAME:
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
Player player = entry.getValue();
|
||||||
|
player.clear();
|
||||||
|
}
|
||||||
|
owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.game.state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态基类
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public abstract class StateBase<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进入状态时处理
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void enter(T owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出状态时处理
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void exit(T owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从该状态转向下一个状态的处理
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void toNextState(T owner) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行事件处理
|
||||||
|
* @param owner
|
||||||
|
* @param cmd
|
||||||
|
* @param gid
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
public void execute(T owner, String cmd, int gid, Object param) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重连
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void reload(T owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.game.state;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态机
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public class StateMachine {
|
||||||
|
|
||||||
|
private Object owner = null;
|
||||||
|
/**
|
||||||
|
* 当前状态
|
||||||
|
*/
|
||||||
|
public StateBase curState = null;
|
||||||
|
public StateBase lastState = null;
|
||||||
|
|
||||||
|
public StateMachine(Object owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 改变状态
|
||||||
|
* @param state
|
||||||
|
*/
|
||||||
|
public void changeState(StateBase state) {
|
||||||
|
if (curState != null) {
|
||||||
|
this.curState.exit(this.owner);
|
||||||
|
}
|
||||||
|
if (this.lastState != this.curState) {
|
||||||
|
this.lastState = this.curState;
|
||||||
|
}
|
||||||
|
if (Global.loggerDebug) {
|
||||||
|
String old_log = this.curState != null ? curState.getClass().getSimpleName() : "null";
|
||||||
|
Global.logger.info(owner + " [" + old_log + "]to[" + state.getClass().getSimpleName() + "]");
|
||||||
|
}
|
||||||
|
this.curState = state;
|
||||||
|
this.curState.enter(this.owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toLastState() {
|
||||||
|
if (lastState == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.changeState(this.lastState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toNextState() {
|
||||||
|
this.curState.toNextState(this.owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行服务器内部事件
|
||||||
|
* @param cmd
|
||||||
|
* @param gid
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
public void execute(String cmd, int gid, Object param) {
|
||||||
|
this.curState.execute(this.owner, cmd, gid, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="game_mj_changsha" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<gameSetting>
|
||||||
|
<host>192.168.14.1</host>
|
||||||
|
<intranet>192.168.14.1</intranet>
|
||||||
|
<port>8842</port>
|
||||||
|
<serverId>8841</serverId>
|
||||||
|
<gameId>10</gameId>
|
||||||
|
<loggerDebug>true</loggerDebug>
|
||||||
|
</gameSetting>
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<serivce-core>
|
||||||
|
<log4jPath>log4j.properties</log4jPath>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<id>redis</id>
|
||||||
|
<class>com.taurus.core.plugin.redis.RedisPlugin</class>
|
||||||
|
|
||||||
|
<poolConfig>
|
||||||
|
<!-- 最大连接数, 默认8个 -->
|
||||||
|
<maxTotal>80</maxTotal>
|
||||||
|
<!-- 最大空闲连接数, 默认8个 -->
|
||||||
|
<maxIdle>20</maxIdle>
|
||||||
|
<!-- 最小空闲连接数, 默认0个 -->
|
||||||
|
<minIdle>5</minIdle>
|
||||||
|
<!-- 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 -->
|
||||||
|
<maxWaitMillis>-1</maxWaitMillis>
|
||||||
|
<!-- 在borrow一个jedis实例时,是否提前进行alidate操作, 默认false -->
|
||||||
|
<testOnBorrow>true</testOnBorrow>
|
||||||
|
<!-- 在return给pool时,是否提前进行validate操作, 默认false -->
|
||||||
|
<testOnReturn>true</testOnReturn>
|
||||||
|
<!-- 表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,
|
||||||
|
此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义, 默认true -->
|
||||||
|
<testWhileIdle>true</testWhileIdle>
|
||||||
|
<!-- 表示idle object evitor每次扫描的最多的对象数, 默认-1 -->
|
||||||
|
<numTestsPerEvictionRun>100</numTestsPerEvictionRun>
|
||||||
|
<!-- 表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;
|
||||||
|
这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 , 默认60000-->
|
||||||
|
<minEvictableIdleTimeMillis>60000</minEvictableIdleTimeMillis>
|
||||||
|
<!-- 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认30000 -->
|
||||||
|
<timeBetweenEvictionRunsMillis>30000</timeBetweenEvictionRunsMillis>
|
||||||
|
<!-- 在minEvictableIdleTimeMillis基础上,加入了至少minIdle个对象已经在pool里面了。
|
||||||
|
如果为-1,evicted不会根据idle time驱逐任何对象。如果minEvictableIdleTimeMillisd大于0,
|
||||||
|
则此项设置无意义,且只有在timeBetweenEvictionRunsMillis大于0时才有意义,默认1800000 -->
|
||||||
|
<softMinEvictableIdleTimeMillis>1800000</softMinEvictableIdleTimeMillis>
|
||||||
|
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true -->
|
||||||
|
<blockWhenExhausted>true</blockWhenExhausted>
|
||||||
|
</poolConfig>
|
||||||
|
|
||||||
|
<infos>
|
||||||
|
<info name="group1_db0" host="47.112.97.12" password="cssq@2020" port="6379" database="0" timeout="5000"/>
|
||||||
|
<info name="group1_db1" host="47.112.97.12" password="cssq@2020" port="6379" database="1" timeout="5000"/>
|
||||||
|
<info name="group1_db5" host="47.112.97.12" password="cssq@2020" port="6379" database="5" timeout="5000"/>
|
||||||
|
<info name="group1_db8" host="47.112.97.12" password="cssq@2020" port="6379" database="8" timeout="5000"/>
|
||||||
|
<info name="group1_db9" host="47.112.97.12" password="cssq@2020" port="6379" database="9" timeout="5000"/>
|
||||||
|
<info name="group1_db10" host="47.112.97.12" password="cssq@2020" port="6379" database="10" timeout="5000"/>
|
||||||
|
<info name="group1_db11" host="47.112.97.12" password="cssq@2020" port="6379" database="11" timeout="5000"/>
|
||||||
|
</infos>
|
||||||
|
</plugin>
|
||||||
|
</serivce-core>
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
<server>
|
||||||
|
<!-- 计时器线程池大小-->
|
||||||
|
<timerThreadPoolSize>1</timerThreadPoolSize>
|
||||||
|
<!-- 协议包压缩门槛 (单位字节),当协议包大于设定的值则会进行压缩 -->
|
||||||
|
<protocolCompression>512</protocolCompression>
|
||||||
|
<!-- 读缓冲区类型 nio Direct Buffer 或者 Heap Buffer-->
|
||||||
|
<readBufferType>Heap</readBufferType>
|
||||||
|
<!-- 写入冲区类型 nio Direct Buffer 或者 Heap Buffer-->
|
||||||
|
<writeBufferType>Heap</writeBufferType>
|
||||||
|
<!-- 最大的数据包大小 -->
|
||||||
|
<maxPacketSize>524288</maxPacketSize>
|
||||||
|
<!-- 最大读取缓存大小 -->
|
||||||
|
<maxReadBufferSize>1024</maxReadBufferSize>
|
||||||
|
<!-- 最大写入缓存大小 -->
|
||||||
|
<maxWriteBufferSize>32768</maxWriteBufferSize>
|
||||||
|
<!-- 会话队列的大小-->
|
||||||
|
<sessionPacketQueueSize>160</sessionPacketQueueSize>
|
||||||
|
|
||||||
|
<!-- Thread Pool Size of the 3 main stages of the Bitswarm Engine -->
|
||||||
|
<socketAcceptorThreadPoolSize>1</socketAcceptorThreadPoolSize>
|
||||||
|
<socketReaderThreadPoolSize>2</socketReaderThreadPoolSize>
|
||||||
|
<socketWriterThreadPoolSize>1</socketWriterThreadPoolSize>
|
||||||
|
|
||||||
|
<!-- Enable disable Nagle algorithm on sockets, true == disable -->
|
||||||
|
<tcpNoDelay>true</tcpNoDelay>
|
||||||
|
<!-- 会话超时时间(单位秒)-->
|
||||||
|
<sessionTimeout>15</sessionTimeout>
|
||||||
|
|
||||||
|
<!-- Bind socket addresses -->
|
||||||
|
<socketAddresses>
|
||||||
|
<socket address="0.0.0.0" port="8842" type="TCP" />
|
||||||
|
</socketAddresses>
|
||||||
|
|
||||||
|
<!-- Ip addresses filter-->
|
||||||
|
<ipFilter>
|
||||||
|
<addressBlackList>
|
||||||
|
<string>1.2.3.4</string>
|
||||||
|
</addressBlackList>
|
||||||
|
<addressWhiteList>
|
||||||
|
<string>127.0.0.1</string>
|
||||||
|
</addressWhiteList>
|
||||||
|
<maxConnectionsPerAddress>10000</maxConnectionsPerAddress>
|
||||||
|
</ipFilter>
|
||||||
|
|
||||||
|
<webSocket>
|
||||||
|
<isActive>false</isActive>
|
||||||
|
<address>0.0.0.0</address>
|
||||||
|
<port>80</port>
|
||||||
|
</webSocket>
|
||||||
|
|
||||||
|
<!-- Main extension class -->
|
||||||
|
<extensionConfig>
|
||||||
|
<name>extension - test</name>
|
||||||
|
<className>extend.mj.EXMainServer</className>
|
||||||
|
</extensionConfig>
|
||||||
|
|
||||||
|
<!-- The system thread pool config -->
|
||||||
|
<systemThreadPoolConfig>
|
||||||
|
<name>Sys</name>
|
||||||
|
<corePoolSize>2</corePoolSize>
|
||||||
|
<maxPoolSize>8</maxPoolSize>
|
||||||
|
<keepAliveTime>60000</keepAliveTime>
|
||||||
|
<maxQueueSize>20000</maxQueueSize>
|
||||||
|
</systemThreadPoolConfig>
|
||||||
|
|
||||||
|
<!-- The extension thread pool config -->
|
||||||
|
<extensionThreadPoolConfig>
|
||||||
|
<name>Ext</name>
|
||||||
|
<corePoolSize>2</corePoolSize>
|
||||||
|
<maxPoolSize>8</maxPoolSize>
|
||||||
|
<keepAliveTime>60000</keepAliveTime>
|
||||||
|
<maxQueueSize>20000</maxQueueSize>
|
||||||
|
</extensionThreadPoolConfig>
|
||||||
|
|
||||||
|
</server>
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.game</groupId>
|
||||||
|
<artifactId>game_mj_changsha</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>robot_mj_changsha</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!--依赖 game_common -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.game</groupId>
|
||||||
|
<artifactId>game_common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>game</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- <compilerArgument>-parameters</compilerArgument> -->
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
public class CardNiao {
|
||||||
|
public int card;
|
||||||
|
|
||||||
|
public int playerId=0;
|
||||||
|
|
||||||
|
|
||||||
|
public int score = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public ITObject toMP(){
|
||||||
|
ITObject obj = TObject.newInstance();
|
||||||
|
obj.putInt("card", card);
|
||||||
|
obj.putInt("playerId", playerId);
|
||||||
|
obj.putInt("score", score);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
public static final int FENGDING_SCORE = 28;
|
||||||
|
public static final int XIPAI_SCORE = 10;
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_ZIMO = "zimo";
|
||||||
|
public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian";
|
||||||
|
public static final String ROOM_CONFIG_NIAO = "niao";
|
||||||
|
public static final String ROOM_CONFIG_NIAO_TYPE = "niao_type";
|
||||||
|
public static final String ROOM_CONFIG_PIAO_NIAO = "piao_niao"; //0:不嫖 1:自由票 2:固定票
|
||||||
|
public static final String ROOM_CONFIG_PIAO_NIAO_AUTO = "auto_piao"; //piao fen
|
||||||
|
public static final String ROOM_CONFIG_PIAO_NIAO_OPT = "piao_niao_opt"; //piao fen
|
||||||
|
public static final String ROOM_CONFIG_ZT_LIULIUSHUN = "zhongtuliuliushun";
|
||||||
|
public static final String ROOM_CONFIG_ZT_DASIXI = "zhongtusixi";
|
||||||
|
public static final String ROOM_CONFIG_QS_JIEJIEGAO = "jiejiegao";
|
||||||
|
public static final String ROOM_CONFIG_QS_SANTONG = "santong";
|
||||||
|
public static final String ROOM_CONFIG_QS_YIZHIHUA = "yizhihua";
|
||||||
|
public static final String ROOM_CONFIG_QUEYIMEN = "queyimen";
|
||||||
|
public static final String ROOM_CONFIG_FENGDING = "fengding";
|
||||||
|
public static final String ROOM_CONFIG_FENGDING_SCORE = "fengding_score";
|
||||||
|
public static final String ROOM_CONFIG_XIPAI = "xi_pai";
|
||||||
|
public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score";
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_ANCHOU_SCORE = "an_chou_score";
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_DIFEN_SCORE = "difen_score";
|
||||||
|
public static final String ROOM_CONFIG_NIAOFEN_SCORE = "niaofen_score";
|
||||||
|
public static final String ROOM_CONFIG_NIAOFEN_OPT = "niaofen_opt"; //0中鸟加分,//1中鸟加倍
|
||||||
|
public static final String ROOM_CONFIG_KAI_GONG = "kai_gong"; //0:开杠2张,1:开杠四张
|
||||||
|
|
||||||
|
|
||||||
|
public static final int NIAO_TYPE_ADD = 0;
|
||||||
|
|
||||||
|
public static final int NIAO_TYPE_DOUBLE = 1;
|
||||||
|
|
||||||
|
public static final int NIAO_TYPE_CS2NIAO = 2;
|
||||||
|
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_QS_JTYN = "two_pair";
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_NO_JIANG = "no_jiang";
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_NATIVE_HU = "native_hu";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String ROOM_CONFIG_FOUR_WIN = "four_win";
|
||||||
|
|
||||||
|
public static final String SETTLE_XIAO_DIAN_PAO = "xiao_dian_pao";
|
||||||
|
public static final String SETTLE_XIAO_JIE_PAO = "xiao_jie_pao";
|
||||||
|
public static final String SETTLE_XIAO_ZIMO = "xiao_zimo";
|
||||||
|
public static final String SETTLE_DA_DIAN_PAO = "da_dian_pao";
|
||||||
|
public static final String SETTLE_DA_JIE_PAO = "da_jie_pao";
|
||||||
|
public static final String SETTLE_DA_ZIMO = "da_zimo";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String GAME_EVT_PLAYER_DEAL = "811";
|
||||||
|
|
||||||
|
public static final String GAME_DIS_CARD = "611";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_DISCARD = "812";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_DISCARD_TIP = "813";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_FZTIPS = "814";
|
||||||
|
|
||||||
|
public static final String GAME_ACTION = "612";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_ACTION = "815";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_HU = "816";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_RESULT1 = "817";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_RESULT2 = "818";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_DRAW = "819";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "820";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_NIAO = "821";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_QSTIP = "822";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_QSWIN = "823";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_OPENKONG = "824";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_HAIDITIP = "825";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String GAME_EVT_PIAONIAO_TIP = "833";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_PIAONIAO = "834";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_TING_TIP = "835";
|
||||||
|
|
||||||
|
public static final String GAME_EVT_TING = "836";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
public class EXActionEvent {
|
||||||
|
|
||||||
|
public static final String EVENT_ACTION = "action";
|
||||||
|
|
||||||
|
public static final String EVENT_DISCARD = "discard";
|
||||||
|
|
||||||
|
public static final String EVENT_OTHER_DISCARD = "other_discard";
|
||||||
|
|
||||||
|
public static final String EVENT_START_GAME ="start_game";
|
||||||
|
|
||||||
|
public static final String EVENT_EXIT_ROOM = "exit_room";
|
||||||
|
|
||||||
|
public static final String EVENT_KONG_WIN = "kong_win";
|
||||||
|
|
||||||
|
public static final String EVENT_OPENKONG = "other_openkong";
|
||||||
|
|
||||||
|
public static final String EVENT_PIAO_NIAO = "piao_niao";
|
||||||
|
|
||||||
|
public static final String EVENT_QSWIN = "qs_win";
|
||||||
|
public static final String EVENT_TIANTING = "tian_ting";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,490 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.GameController;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.routes.ActionKey;
|
||||||
|
import com.taurus.permanent.data.Session;
|
||||||
|
|
||||||
|
import extend.mj.tip.Tip;
|
||||||
|
import extend.mj.tip.TipManager;
|
||||||
|
import extend.mj.uitl.CardUtil;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EXGameController extends GameController {
|
||||||
|
|
||||||
|
public EXGameController() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActionKey(Config.GAME_ACTION)
|
||||||
|
public void RouterAction(Session sender,ITObject params,int gid,Player owner) {
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
int id = params.getInt("id");
|
||||||
|
if(id ==0) {
|
||||||
|
Global.logger.info(owner + " pass!");
|
||||||
|
}else {
|
||||||
|
TipManager tipMgr =((EXPlayer)owner).tipMgr;
|
||||||
|
if(tipMgr.tipMap.containsKey(id)) {
|
||||||
|
Tip tip = tipMgr.tipMap.get(id);
|
||||||
|
Global.logger.info(owner + " select_action type:"+tip.group_type+" card:"+tip.card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
owner.stateMachine.execute(EXActionEvent.EVENT_ACTION, 0, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActionKey(Config.GAME_DIS_CARD)
|
||||||
|
public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) {
|
||||||
|
owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeActiveSeat(EXRoom owner,int activeSeat) {
|
||||||
|
owner.activeSeat = activeSeat;
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", activeSeat);
|
||||||
|
owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCard(EXPlayer player,int leftCount){
|
||||||
|
ITObject otherParam = new TObject();
|
||||||
|
otherParam.putInt("card", 0);
|
||||||
|
otherParam.putInt("seat", player.room.activeSeat);
|
||||||
|
otherParam.putInt("left_count", leftCount);
|
||||||
|
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt( "card", player.drawCard );
|
||||||
|
param.putInt("seat", player.room.activeSeat);
|
||||||
|
param.putInt("left_count", leftCount);
|
||||||
|
player.sendEvent(Config.GAME_EVT_DRAW, param);
|
||||||
|
player.cardInhand.add(player.drawCard);
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " drawcard["+player.drawCard+"]");
|
||||||
|
}
|
||||||
|
player.room.broadCastToClient(player.playerid, Config.GAME_EVT_DRAW, otherParam);
|
||||||
|
|
||||||
|
((EXPlayBack)player.getRoom().playBackData).addGetCardCommand(player.room.activeSeat, player.drawCard,leftCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void outCard(EXPlayer player,int discard){
|
||||||
|
ITObject response = new TObject();
|
||||||
|
response.putInt("seat", player.seat);
|
||||||
|
response.putInt("card", discard);
|
||||||
|
player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response);
|
||||||
|
EXRoom room = player.getRoom();
|
||||||
|
((EXPlayBack)room.playBackData).addOutCardCommand(player.seat, discard);
|
||||||
|
|
||||||
|
room.activeCard = discard;
|
||||||
|
room.lastDiscardSeat = player.seat;
|
||||||
|
room.currenDiscardSeat = 0;
|
||||||
|
player.outcardList.add(discard);
|
||||||
|
Util.removeCard(player.cardInhand, discard, 1);
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " outcard["+discard+"]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray,boolean opengang){
|
||||||
|
ITObject paramBroadCast = new TObject();
|
||||||
|
paramBroadCast.putInt("playerid", player.playerid);
|
||||||
|
paramBroadCast.putInt("card", card);
|
||||||
|
paramBroadCast.putInt("type", type);
|
||||||
|
paramBroadCast.putInt("from_seat", from_seat);
|
||||||
|
if(opcardArray!=null){
|
||||||
|
paramBroadCast.putTArray("opcard", opcardArray);
|
||||||
|
}
|
||||||
|
paramBroadCast.putBoolean("opengang", opengang);
|
||||||
|
EXRoom room = player.getRoom();
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(String.format("%s from_seat:%d card:%d type:%d opengang:%b", player,from_seat,card,type,opengang));
|
||||||
|
}
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_ACTION, paramBroadCast);
|
||||||
|
((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray,opengang);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dealCard(EXRoom owner) {
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer)entry.getValue();
|
||||||
|
//player.cardInhand = owner.card.deal(player, owner.bankerSeat == player.seat?14:13);
|
||||||
|
player.cardInhand = owner.card.deal(player.seat,owner.bankerSeat == player.seat?14:13);
|
||||||
|
if(owner.bankerSeat == player.seat) {
|
||||||
|
player.drawCard = player.cardInhand.get(player.cardInhand.size()-1);
|
||||||
|
player.skipDraw = true;
|
||||||
|
}
|
||||||
|
// Collections.sort(player.cardInhand);
|
||||||
|
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " cardlist:" + player.cardInhand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer)entry.getValue();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
ITArray handCard = Util.toTArray(player.cardInhand);
|
||||||
|
param.putTArray("card_list", handCard);
|
||||||
|
param.putInt("bank_seat", player.room.bankerSeat);
|
||||||
|
param.putInt("left_count", owner.card.getCount());
|
||||||
|
param.putInt("round", owner.round);
|
||||||
|
player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param);
|
||||||
|
player.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tipEvent(EXPlayer owner) {
|
||||||
|
ITObject param = owner.tipMgr.toMP();
|
||||||
|
Global.logger.info(param.toJson());
|
||||||
|
owner.sendEvent(Config.GAME_EVT_FZTIPS, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void discardTipEvent(EXPlayer owner) {
|
||||||
|
owner.getRoom().currenDiscardSeat = owner.seat;
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putBoolean("auto",owner.autoOutCard);
|
||||||
|
owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void winEvent(EXPlayer owner,int from_seat) {
|
||||||
|
ITArray cardInHand = TArray.newInstance();
|
||||||
|
for (int card1 : owner.cardInhand) {
|
||||||
|
cardInHand.addInt(card1);
|
||||||
|
}
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putTArray("card", cardInHand);
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
param.putInt("from_seat", from_seat);
|
||||||
|
param.putInt("win_card", owner.winCard);
|
||||||
|
ITArray array = CardUtil.toMPData_WinMap(owner.winMap);
|
||||||
|
if (array != null) {
|
||||||
|
param.putTArray("win_list", array);
|
||||||
|
}
|
||||||
|
EXRoom room = owner.getRoom();
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_HU, param);
|
||||||
|
((EXPlayBack)room.playBackData).addWinCardCommand(owner.seat, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendNiaoEvt(EXPlayer owner, int seat) {
|
||||||
|
EXRoom room = owner.getRoom();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
// param.putInt("playerid", owner.playerid);
|
||||||
|
ITArray array = new TArray();
|
||||||
|
for (int index = 0; index < room.niao.size(); index++) {
|
||||||
|
array.addTObject(room.niao.get(index).toMP());
|
||||||
|
}
|
||||||
|
param.putTArray("niao", array);
|
||||||
|
param.putInt("start_seat", seat);
|
||||||
|
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_NIAO, param);
|
||||||
|
((EXPlayBack)room.playBackData).addNiaoCommand(owner.seat, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void qsTipEvent(EXPlayer owner) {
|
||||||
|
ITObject param = owner.tipMgr.toMP();
|
||||||
|
ITArray types = null;
|
||||||
|
for (Entry<Integer, Tip> entry : owner.tipMgr.tipMap.entrySet()) {
|
||||||
|
types = CardUtil.toMPData_WinMap(entry.getValue().winMap);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
param.putTArray("types", types);
|
||||||
|
owner.sendEvent(Config.GAME_EVT_QSTIP, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void piaoNiaoTipEvent(EXPlayer owner) {
|
||||||
|
owner.sendEvent(Config.GAME_EVT_PIAONIAO_TIP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void piaoNiaoEvent(EXPlayer owner) {
|
||||||
|
// if(owner.piaoNiao==0)return;
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
param.putInt("num", owner.piaoNiao);
|
||||||
|
owner.room.broadCastToClient(0, Config.GAME_EVT_PIAONIAO, param);
|
||||||
|
// owner.getRoom().playBackData.addPiaoNiaoCommand(owner.seat, owner.piaoNiao);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void tingTipEvent(EXPlayer owner) {
|
||||||
|
owner.sendEvent(Config.GAME_EVT_TING_TIP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void tingEvent(EXPlayer owner) {
|
||||||
|
if(!owner.tianting)return;
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
owner.room.broadCastToClient(0, Config.GAME_EVT_TING, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
* @param types
|
||||||
|
*/
|
||||||
|
public void qsWinEvent(EXPlayer owner,Tip tip) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
ITArray data = CardUtil.toMPData_WinMap(tip.winMap,true);
|
||||||
|
param.putTArray("data", data);
|
||||||
|
param.putInt("type", tip.group_type);
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(owner + (tip.type == RuleWeight.TYPE_QSWIN?" QS":" TZ") + "Win type " + tip.winMap);
|
||||||
|
}
|
||||||
|
EXRoom room = owner.getRoom();
|
||||||
|
int id = owner.qsList.size() + 1;
|
||||||
|
QSLog qs_log = new QSLog();
|
||||||
|
qs_log.winMap = data;
|
||||||
|
owner.qsList.add(qs_log);
|
||||||
|
for (Entry<Integer, WinCardType> entry : tip.winMap.entrySet()) {
|
||||||
|
WinCardType wct = entry.getValue();
|
||||||
|
for(int i = 0;i<wct.value; ++i) {
|
||||||
|
room.addQSScore(owner, wct.score,id,qs_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wct.type == RuleWeight.TYPE_LIULIUSHUN) {
|
||||||
|
for(int i=0;i<wct.opcard.size();++i) {
|
||||||
|
owner.llsCardRecord.add(wct.opcard.getInt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int niao_type = room.config.getInt(Config.ROOM_CONFIG_NIAO_TYPE);
|
||||||
|
if(niao_type == Config.NIAO_TYPE_CS2NIAO) {
|
||||||
|
room.niao_qsWin(owner,id,qs_log);
|
||||||
|
ITArray niao = new TArray();
|
||||||
|
for (int index = 0; index < qs_log.niaoList.size(); index++) {
|
||||||
|
niao.addTObject(qs_log.niaoList.get(index).toMP());
|
||||||
|
}
|
||||||
|
param.putTArray("niao", niao);
|
||||||
|
}
|
||||||
|
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_QSWIN, param);
|
||||||
|
((EXPlayBack)room.playBackData).addQSWinCardCommand(owner.seat,tip.group_type,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDaHu(int type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case WinCardType.QIXIAODUI:
|
||||||
|
case WinCardType.JIANGJIANGHU:
|
||||||
|
case WinCardType.QINGYISE:
|
||||||
|
case WinCardType.PENGPENGHU:
|
||||||
|
case WinCardType.GANGSHANGHUA:
|
||||||
|
case WinCardType.GANGSHANGPAO:
|
||||||
|
case WinCardType.QUANQIUREN:
|
||||||
|
case WinCardType.HAIDI:
|
||||||
|
case WinCardType.HAIDIPAO:
|
||||||
|
case WinCardType.QIANG_GANG_HU:
|
||||||
|
case WinCardType.TYPE_TIANHU:
|
||||||
|
case WinCardType.TYPE_TIANTINGHU:
|
||||||
|
case WinCardType.TYPE_MENQING:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDaHuNum(Map<Integer,WinCardType> map)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (Entry<Integer, WinCardType> entry : map.entrySet()) {
|
||||||
|
WinCardType wct = entry.getValue();
|
||||||
|
if (isDaHu(wct.type))
|
||||||
|
{
|
||||||
|
for(int i = 0;i<wct.value; ++i) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void banbanWinEvent(EXPlayer owner,Tip tip) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
ITArray data = CardUtil.toMPData_WinMap(tip.winMap,true);
|
||||||
|
param.putTArray("data", data);
|
||||||
|
param.putInt("type", tip.group_type);
|
||||||
|
param.putInt("seat", owner.seat);
|
||||||
|
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(owner + (tip.type == RuleWeight.TYPE_QSWIN?" QS":" TZ") + "Win type " + tip.winMap);
|
||||||
|
}
|
||||||
|
EXRoom room = owner.getRoom();
|
||||||
|
int id = owner.qsList.size() + 1;
|
||||||
|
QSLog qs_log = new QSLog();
|
||||||
|
qs_log.winMap = data;
|
||||||
|
owner.qsList.add(qs_log);
|
||||||
|
for (Entry<Integer, WinCardType> entry : tip.winMap.entrySet()) {
|
||||||
|
WinCardType wct = entry.getValue();
|
||||||
|
for(int i = 0;i<wct.value; ++i) {
|
||||||
|
room.addQSScore(owner, wct.score,id,qs_log);
|
||||||
|
}
|
||||||
|
if(wct.type == RuleWeight.TYPE_LIULIUSHUN) {
|
||||||
|
for(int i=0;i<wct.opcard.size();++i) {
|
||||||
|
owner.llsCardRecord.add(wct.opcard.getInt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int niao_type = room.config.getInt(Config.ROOM_CONFIG_NIAO_TYPE);
|
||||||
|
if(niao_type == Config.NIAO_TYPE_CS2NIAO) {
|
||||||
|
room.banban_qsWin(owner,id,qs_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
room.broadCastToClient(0, Config.GAME_EVT_QSWIN, param);
|
||||||
|
((EXPlayBack)room.playBackData).addQSWinCardCommand(owner.seat,tip.group_type,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player
|
||||||
|
* @param leftCount
|
||||||
|
* @param ok
|
||||||
|
*/
|
||||||
|
public void openKongEvent(EXPlayer player,int leftCount,OpenKong ok) {
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putTObject( "info", ok.getTObject());
|
||||||
|
param.putInt("seat", player.room.activeSeat);
|
||||||
|
param.putInt("left_count", leftCount);
|
||||||
|
|
||||||
|
if(Global.loggerDebug) {
|
||||||
|
Global.logger.info(player + " openkong " + ok.drawList );
|
||||||
|
}
|
||||||
|
player.room.broadCastToClient(0, Config.GAME_EVT_OPENKONG, param);
|
||||||
|
((EXPlayBack)player.getRoom().playBackData).addOpenKongCommand(player.room.activeSeat, leftCount, ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void haidiTipEvent(EXPlayer owner) {
|
||||||
|
owner.sendEvent(Config.GAME_EVT_HAIDITIP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ITObject getRoomResultData(EXRoom owner) {
|
||||||
|
ITObject mp = TObject.newInstance();
|
||||||
|
mp.putBoolean("liuju", owner.liuju);
|
||||||
|
mp.putInt("xipai_score", owner.xi_pai_score);
|
||||||
|
if(owner.liuju) {
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer p = (EXPlayer) entry.getValue();
|
||||||
|
p.win_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid);
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
long t = time / 1000;
|
||||||
|
mp.putLong("time", t);
|
||||||
|
ITArray niao = new TArray();
|
||||||
|
for (int index = 0; index < owner.niao.size(); index++) {
|
||||||
|
niao.addTObject(owner.niao.get(index).toMP());
|
||||||
|
}
|
||||||
|
mp.putTArray("niao", niao);
|
||||||
|
|
||||||
|
ITArray infoList = new TArray();
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", player.seat);
|
||||||
|
param.putInt("win_card", player.winCard);
|
||||||
|
param.putBoolean("is_win", player.winer == 1);
|
||||||
|
param.putInt("win_count", player.win_count);
|
||||||
|
param.putInt("hu_score", player.score.round_log.get(EXScore.WIN));
|
||||||
|
param.putInt("niao_score", player.score.round_log.get(EXScore.NIAO));
|
||||||
|
param.putInt("qs_score", player.score.round_log.get(EXScore.QS));
|
||||||
|
ITArray qs_info_list = TArray.newInstance();
|
||||||
|
for(QSLog log : player.qsList) {
|
||||||
|
qs_info_list.addTObject(log.toMP());
|
||||||
|
}
|
||||||
|
param.putTArray("qs_info_list", qs_info_list);
|
||||||
|
param.putInt("piao_niao_score", player.score.round_log.get(EXScore.PIAO_NIAO));
|
||||||
|
param.putBoolean("fengding", player.fengding);
|
||||||
|
param.putInt("round_score", player.score.round_score);
|
||||||
|
param.putInt("total_score", player.score.total_score);
|
||||||
|
ITArray handCard = Util.toTArray(player.cardInhand);
|
||||||
|
param.putTArray("hand_card", handCard);
|
||||||
|
ITArray array = CardUtil.toMPData_WinMap(player.winMap);
|
||||||
|
if (array != null) {
|
||||||
|
param.putTArray("win_list", array);
|
||||||
|
}
|
||||||
|
player.hp_info(param);
|
||||||
|
infoList.addTObject(param);
|
||||||
|
}
|
||||||
|
mp.putTArray("info_list", infoList);
|
||||||
|
return mp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
*/
|
||||||
|
public void roomResult(EXRoom owner) {
|
||||||
|
ITObject mp = TObject.newInstance();
|
||||||
|
mp.putInt("type", 0);
|
||||||
|
ITObject result = getRoomResultData(owner);
|
||||||
|
owner.playBackData.addResult(result);
|
||||||
|
mp.putTObject("result", result);
|
||||||
|
owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner
|
||||||
|
* @param dissmiss
|
||||||
|
*/
|
||||||
|
public void roomTotalResult(EXRoom owner,boolean dissmiss) {
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
long t = System.currentTimeMillis() / 1000;
|
||||||
|
data.putLong("time", t);
|
||||||
|
|
||||||
|
|
||||||
|
ITObject mp = TObject.newInstance();
|
||||||
|
mp.putInt("type", dissmiss?2:1);
|
||||||
|
if(!dissmiss) {
|
||||||
|
ITObject result = getRoomResultData(owner);
|
||||||
|
owner.playBackData.addResult(result);
|
||||||
|
mp.putTObject("result", result);
|
||||||
|
}
|
||||||
|
ITArray infoList = new TArray();
|
||||||
|
for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
ITObject param = new TObject();
|
||||||
|
param.putInt("seat", player.seat);
|
||||||
|
param.putTObject("settle_log", player.settleLog.toTObject());
|
||||||
|
param.putInt("total_score", player.score.total_score);
|
||||||
|
player.hp_info(param);
|
||||||
|
infoList.addTObject(param);
|
||||||
|
}
|
||||||
|
data.putTArray("info_list", infoList);
|
||||||
|
mp.putTObject("total_result", data);
|
||||||
|
|
||||||
|
owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.game.GameController;
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.MainServer;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.game.room.state.RoomStartGameState;
|
||||||
|
|
||||||
|
import extend.mj.player.rulestate.PRChowState;
|
||||||
|
import extend.mj.player.rulestate.PROtherKongState;
|
||||||
|
import extend.mj.player.rulestate.PROtherOpenKongState;
|
||||||
|
import extend.mj.player.rulestate.PROtherWinState;
|
||||||
|
import extend.mj.player.rulestate.PRPongKongState;
|
||||||
|
import extend.mj.player.rulestate.PRPongOpenKongState;
|
||||||
|
import extend.mj.player.rulestate.PRPongState;
|
||||||
|
import extend.mj.player.rulestate.PRSelfKongState;
|
||||||
|
import extend.mj.player.rulestate.PRSelfOpenKongState;
|
||||||
|
import extend.mj.player.rulestate.PRSelfWinState;
|
||||||
|
import extend.mj.player.state.EXPlayerDisCardTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerDiscardState;
|
||||||
|
import extend.mj.player.state.EXPlayerDrawState;
|
||||||
|
import extend.mj.player.state.EXPlayerDrawTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerHaidiTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerKongWinState;
|
||||||
|
import extend.mj.player.state.EXPlayerOpenKongState;
|
||||||
|
import extend.mj.player.state.EXPlayerPiaoNiaoTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerQSWinTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerTianTingTipState;
|
||||||
|
import extend.mj.player.state.EXPlayerWaitKongWinState;
|
||||||
|
import extend.mj.player.state.EXPlayerWaitState;
|
||||||
|
import extend.mj.player.state.EXPlayerZTWinTipState;
|
||||||
|
import extend.mj.room.state.EXRoomDealState;
|
||||||
|
import extend.mj.room.state.EXRoomSetpState;
|
||||||
|
import extend.mj.room.state.EXRoomStartGameState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EXMainServer extends MainServer{
|
||||||
|
|
||||||
|
|
||||||
|
public static PlayerRuleManager playerRuleMgr;
|
||||||
|
|
||||||
|
public static EXGameController gameCtr;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
gameCtr = (EXGameController)Global.gameCtr;
|
||||||
|
|
||||||
|
registerState();
|
||||||
|
|
||||||
|
playerRuleMgr = new PlayerRuleManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private final void registerState() {
|
||||||
|
Global.registerState(RoomStartGameState.class, new EXRoomStartGameState());
|
||||||
|
Global.registerState(EXRoomSetpState.class, new EXRoomSetpState());
|
||||||
|
Global.registerState(EXRoomDealState.class, new EXRoomDealState());
|
||||||
|
|
||||||
|
Global.registerState(PlayerWaitState.class, new EXPlayerWaitState());
|
||||||
|
Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState());
|
||||||
|
Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState());
|
||||||
|
Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState());
|
||||||
|
Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState());
|
||||||
|
Global.registerState(EXPlayerWaitKongWinState.class, new EXPlayerWaitKongWinState());
|
||||||
|
Global.registerState(EXPlayerKongWinState.class, new EXPlayerKongWinState());
|
||||||
|
Global.registerState(EXPlayerQSWinTipState.class, new EXPlayerQSWinTipState());
|
||||||
|
Global.registerState(EXPlayerOpenKongState.class, new EXPlayerOpenKongState());
|
||||||
|
Global.registerState(EXPlayerHaidiTipState.class, new EXPlayerHaidiTipState());
|
||||||
|
Global.registerState(EXPlayerZTWinTipState.class, new EXPlayerZTWinTipState());
|
||||||
|
Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState());
|
||||||
|
Global.registerState(EXPlayerTianTingTipState.class, new EXPlayerTianTingTipState());
|
||||||
|
|
||||||
|
Global.registerState(PRChowState.class, new PRChowState());
|
||||||
|
Global.registerState(PROtherKongState.class, new PROtherKongState());
|
||||||
|
Global.registerState(PROtherWinState.class, new PROtherWinState());
|
||||||
|
Global.registerState(PRPongKongState.class, new PRPongKongState());
|
||||||
|
Global.registerState(PRPongState.class, new PRPongState());
|
||||||
|
Global.registerState(PRSelfKongState.class, new PRSelfKongState());
|
||||||
|
Global.registerState(PRSelfWinState.class, new PRSelfWinState());
|
||||||
|
Global.registerState(PROtherOpenKongState.class, new PROtherOpenKongState());
|
||||||
|
Global.registerState(PRPongOpenKongState.class, new PRPongOpenKongState());
|
||||||
|
Global.registerState(PRSelfOpenKongState.class, new PRSelfOpenKongState());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Room newRoom(String roomid, Map<String, String> redis_room_map) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new EXRoom(roomid, redis_room_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player newPlayer(int playerid, Room room, String session_id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new EXPlayer(playerid, room, session_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GameController newController() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return new EXGameController();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.BasePlayBack;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
public class EXPlayBack extends BasePlayBack{
|
||||||
|
|
||||||
|
|
||||||
|
public EXPlayBack(EXRoom room){
|
||||||
|
super(room);
|
||||||
|
info.putInt("left_card", room.card.getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITObject getPlayerInfo(Player player) {
|
||||||
|
ITObject obj =super.getPlayerInfo(player);
|
||||||
|
EXPlayer p = (EXPlayer)player;
|
||||||
|
ITArray cardInhand = Util.toTArray(p.cardInhand);
|
||||||
|
obj.putTArray("hand_card", cardInhand);
|
||||||
|
obj.putInt("score", player.score.total_score);
|
||||||
|
obj.putInt("piao_niao", p.piaoNiao);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGetCardCommand(int seat,int card,int left_count){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("card", card);
|
||||||
|
data.putInt("left_count", left_count);
|
||||||
|
addCommand("GetCard",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addOutCardCommand(int seat,int card){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putInt("card", card);
|
||||||
|
addCommand("OutCard",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOutCardKongCommand(int seat,ITArray card){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putTArray("cardList", card);
|
||||||
|
addCommand("OutCardKong",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addActionCommand(int seat,int type,int card,int from_seat,ITArray opcardArray,boolean opengang){
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
cmdData.putInt("card", card);
|
||||||
|
cmdData.putInt("type", type);
|
||||||
|
cmdData.putInt("from_seat", from_seat);
|
||||||
|
if(opcardArray!=null)
|
||||||
|
cmdData.putTArray("opcard", opcardArray);
|
||||||
|
cmdData.putBoolean("opengang", opengang);
|
||||||
|
addCommand("Action",seat,cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void addWinCardCommand(int seat,boolean zimo){
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
addCommand("Win",seat,cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addQSWinCardCommand(int seat,int type,ITArray data){
|
||||||
|
ITObject cmdData = TObject.newInstance();
|
||||||
|
cmdData.putInt("type", type);
|
||||||
|
cmdData.putTArray("data", data);
|
||||||
|
addCommand("QSWin",seat,cmdData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void addPiaoNiaoCommand(int seat,int num){
|
||||||
|
// ITObject cmdData = TObject.newInstance();
|
||||||
|
// cmdData.putInt("num", num);
|
||||||
|
// addCommand("PiaoNiao",seat,cmdData);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void addNiaoCommand(int seat,ITObject param){
|
||||||
|
addCommand("Niao",seat,param);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOpenKongCommand(int seat,int left_count,OpenKong ok){
|
||||||
|
ITObject data = TObject.newInstance();
|
||||||
|
data.putTObject("info", ok.getTObject());
|
||||||
|
data.putInt("left_count", left_count);
|
||||||
|
addCommand("OpenKong",seat,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.data.Score;
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TArray;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
|
||||||
|
import extend.mj.tip.TipManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EXPlayer extends Player {
|
||||||
|
|
||||||
|
public List<Integer> cardInhand;
|
||||||
|
|
||||||
|
|
||||||
|
public List<Integer> outcardList;
|
||||||
|
|
||||||
|
public ITArray opCard;
|
||||||
|
|
||||||
|
public List<OpCard> opCardList;
|
||||||
|
|
||||||
|
public int drawCard = 0;
|
||||||
|
|
||||||
|
public int outCardCount = 0;
|
||||||
|
|
||||||
|
public boolean skipDraw =false;
|
||||||
|
public int winCard = 0;
|
||||||
|
|
||||||
|
public boolean tianting = false;
|
||||||
|
|
||||||
|
public TipManager tipMgr;
|
||||||
|
|
||||||
|
public SettleLog settleLog;
|
||||||
|
|
||||||
|
|
||||||
|
public boolean louhu = false;
|
||||||
|
|
||||||
|
|
||||||
|
public boolean autoOutCard = false;
|
||||||
|
|
||||||
|
public Map<Integer, WinCardType> winMap;
|
||||||
|
|
||||||
|
public OpenKong openKong;
|
||||||
|
public Set<Integer> llsCardRecord;
|
||||||
|
public int piaoNiao = 0;
|
||||||
|
|
||||||
|
public int win_count;
|
||||||
|
public boolean fengding;
|
||||||
|
public List<QSLog> qsList;
|
||||||
|
|
||||||
|
public EXPlayer(int playerid, Room table, String session_id) {
|
||||||
|
super(playerid, table, session_id);
|
||||||
|
|
||||||
|
cardInhand = new ArrayList<>();
|
||||||
|
outcardList = new ArrayList<>();
|
||||||
|
|
||||||
|
opCardList = new ArrayList<>();
|
||||||
|
opCard = new TArray();
|
||||||
|
|
||||||
|
tipMgr = new TipManager(this);
|
||||||
|
llsCardRecord = new HashSet<Integer>();
|
||||||
|
|
||||||
|
settleLog = new SettleLog();
|
||||||
|
settleLog.put(Config.SETTLE_XIAO_DIAN_PAO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_XIAO_JIE_PAO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_XIAO_ZIMO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_DA_DIAN_PAO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_DA_JIE_PAO, 0);
|
||||||
|
settleLog.put(Config.SETTLE_DA_ZIMO, 0);
|
||||||
|
|
||||||
|
qsList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Score newScore() {
|
||||||
|
return new EXScore(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initOpCard(ITArray opcard) {
|
||||||
|
this.opCard.clear();
|
||||||
|
for (int i = 0; i < opcard.size(); ++i) {
|
||||||
|
this.opCard.addInt(opcard.getInt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getReloadInfo() {
|
||||||
|
ITObject playerData = super.getReloadInfo();
|
||||||
|
ITArray disCard = Util.toTArray(this.outcardList);
|
||||||
|
playerData.putTArray("outcard_list", disCard);
|
||||||
|
playerData.putInt("card_count", cardInhand.size());
|
||||||
|
playerData.putInt("score", score.total_score);
|
||||||
|
playerData.putBoolean("auto", this.autoOutCard);
|
||||||
|
playerData.putInt("draw_card", this.drawCard);
|
||||||
|
playerData.putInt("piao_niao", this.piaoNiao);
|
||||||
|
playerData.putInt("win_count", this.win_count);
|
||||||
|
ITArray opcards = TArray.newInstance();
|
||||||
|
for (OpCard opcard : opCardList) {
|
||||||
|
ITObject opcardParam = new TObject();
|
||||||
|
opcardParam.putInt("type", opcard.type);
|
||||||
|
opcardParam.putInt("card", opcard.card);
|
||||||
|
if(opcard.opCard!=null) {
|
||||||
|
opcardParam.putTArray("opcard", opcard.opCard);
|
||||||
|
}
|
||||||
|
opcards.addTObject(opcardParam);
|
||||||
|
}
|
||||||
|
playerData.putTArray("opcard", opcards);
|
||||||
|
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
super.clear();
|
||||||
|
this.cardInhand.clear();
|
||||||
|
this.winer = 0;
|
||||||
|
this.louhu = false;
|
||||||
|
this.outcardList.clear();
|
||||||
|
this.drawCard = 0;
|
||||||
|
this.outCardCount = 0;
|
||||||
|
this.opCardList.clear();
|
||||||
|
this.score.resetRound();
|
||||||
|
this.autoOutCard = false;
|
||||||
|
this.openKong = null;
|
||||||
|
this.winMap = null;
|
||||||
|
this.skipDraw = false;
|
||||||
|
this.tianting = false;
|
||||||
|
this.piaoNiao = 0;
|
||||||
|
this.qsList.clear();
|
||||||
|
this.fengding = false;
|
||||||
|
getRoom().activeKong = null;
|
||||||
|
this.llsCardRecord.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public EXRoom getRoom() {
|
||||||
|
return (EXRoom) room;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,711 @@
|
||||||
|
package extend.mj;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.game.Global;
|
||||||
|
import com.game.Util;
|
||||||
|
import com.game.data.Player;
|
||||||
|
import com.game.data.Room;
|
||||||
|
import com.game.player.state.PlayerWaitState;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
|
||||||
|
import extend.mj.EXScore.HUScore;
|
||||||
|
import extend.mj.player.state.EXPlayerDisCardTipState;
|
||||||
|
import extend.mj.room.state.EXRoomSetpState;
|
||||||
|
import extend.mj.tip.Action;
|
||||||
|
import extend.mj.tip.TipManager;
|
||||||
|
import extend.mj.uitl.CardUtil;
|
||||||
|
|
||||||
|
public class EXRoom extends Room {
|
||||||
|
|
||||||
|
//
|
||||||
|
public Map<Integer, TipManager> tipMap;
|
||||||
|
public List<Action> actionList;
|
||||||
|
public List<Action> actionWinList;
|
||||||
|
public RoomCard card;
|
||||||
|
|
||||||
|
public int activeCard;
|
||||||
|
public int currenDiscardSeat;
|
||||||
|
public int lastDiscardSeat;
|
||||||
|
public int winCount = 0;
|
||||||
|
public boolean liuju = false;
|
||||||
|
public int tongpao = 0;
|
||||||
|
|
||||||
|
public boolean activeHaidi = false;
|
||||||
|
public int haidiCard;
|
||||||
|
|
||||||
|
|
||||||
|
public OpenKong activeKong = null;
|
||||||
|
|
||||||
|
public List<CardNiao> niao;
|
||||||
|
public int adminSeat = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public int qsWinCount = 0;
|
||||||
|
|
||||||
|
public int haidiCount = 0;
|
||||||
|
|
||||||
|
public int piaoNiaoCount = 0;
|
||||||
|
public int tianTingCount = 0;
|
||||||
|
private boolean closeWinCallBack = false;
|
||||||
|
public int fengdingScore = 0;
|
||||||
|
public int difen_score = 0;
|
||||||
|
public int niao_score = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public EXRoom(String roomid, Map<String, String> redis_room_map) {
|
||||||
|
super(roomid, redis_room_map);
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_FENGDING))
|
||||||
|
{
|
||||||
|
this.config.putBoolean(Config.ROOM_CONFIG_FENGDING, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_FENGDING_SCORE))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_FENGDING_SCORE, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int fengding_score = this.config.getInt(Config.ROOM_CONFIG_FENGDING_SCORE);
|
||||||
|
if (fengding_score == 0)
|
||||||
|
{
|
||||||
|
this.fengdingScore = 0;
|
||||||
|
}
|
||||||
|
else if (fengding_score == 1)
|
||||||
|
{
|
||||||
|
this.fengdingScore = 35;
|
||||||
|
}
|
||||||
|
else if (fengding_score == 2)
|
||||||
|
{
|
||||||
|
this.fengdingScore = 40;
|
||||||
|
}
|
||||||
|
else if (fengding_score == 3)
|
||||||
|
{
|
||||||
|
this.fengdingScore = 45;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_NIAO))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_PIAO_NIAO, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_NIAO_AUTO))
|
||||||
|
{
|
||||||
|
this.config.putBoolean(Config.ROOM_CONFIG_PIAO_NIAO_AUTO, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_NIAO_AUTO))
|
||||||
|
{
|
||||||
|
this.config.putBoolean(Config.ROOM_CONFIG_PIAO_NIAO_AUTO, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_NIAO_OPT))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_PIAO_NIAO_OPT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI_SCORE))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_XIPAI_SCORE, 0);
|
||||||
|
this.xi_pai_score = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.xi_pai_score = this.config.getInt(Config.ROOM_CONFIG_XIPAI_SCORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI))
|
||||||
|
{
|
||||||
|
this.config.putBoolean(Config.ROOM_CONFIG_XIPAI, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_DIFEN_SCORE))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_DIFEN_SCORE, 0);
|
||||||
|
this.difen_score = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.difen_score = this.config.getInt(Config.ROOM_CONFIG_DIFEN_SCORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_NIAOFEN_SCORE))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_NIAOFEN_SCORE, 0);
|
||||||
|
this.niao_score = 0;
|
||||||
|
} else {
|
||||||
|
this.niao_score = this.config.getInt(Config.ROOM_CONFIG_NIAOFEN_SCORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_NIAOFEN_OPT))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_NIAOFEN_OPT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.config.containsKey(Config.ROOM_CONFIG_KAI_GONG))
|
||||||
|
{
|
||||||
|
this.config.putInt(Config.ROOM_CONFIG_KAI_GONG, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
card = new RoomCard(this);
|
||||||
|
|
||||||
|
this.tipMap = new HashMap<Integer, TipManager>();
|
||||||
|
this.actionList = new ArrayList<Action>();
|
||||||
|
this.actionWinList = new ArrayList<Action>();
|
||||||
|
this.niao = new ArrayList<CardNiao>();
|
||||||
|
this.isEntrust=true;
|
||||||
|
this.adminSeat = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAction(Action action) {
|
||||||
|
addAction(action, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAction(Action action, boolean check) {
|
||||||
|
if (this.actionList.size() == 0) {
|
||||||
|
this.actionList.add(action);
|
||||||
|
} else if (action.tip.weight > this.actionList.get(0).tip.weight) {
|
||||||
|
this.actionList.clear();
|
||||||
|
this.actionList.add(action);
|
||||||
|
} else if (action.tip.weight == this.actionList.get(0).tip.weight) {
|
||||||
|
boolean add = true;
|
||||||
|
if (activeKong != null) {
|
||||||
|
if (action.tip.weight < RuleWeight.WIN) {
|
||||||
|
if (activeKong.tipActionSeat == -1) {
|
||||||
|
activeKong.tipActionSeat = actionList.get(0).player.seat;
|
||||||
|
}
|
||||||
|
if (activeKong.tipActionSeat != -1) {
|
||||||
|
int pos = Util.getPos(activeKong.kongSeat, action.player.seat, this.maxPlayers);
|
||||||
|
int pos1 = Util.getPos(activeKong.kongSeat, activeKong.tipActionSeat, this.maxPlayers);
|
||||||
|
if (pos < pos1) {
|
||||||
|
actionList.clear();
|
||||||
|
activeKong.tipActionSeat = action.player.seat;
|
||||||
|
} else {
|
||||||
|
add = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (add)
|
||||||
|
this.actionList.add(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (check)
|
||||||
|
checkAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkAction() {
|
||||||
|
boolean isWeightest = this.isWeightestAction();
|
||||||
|
if (!isWeightest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.isAllPass()) {
|
||||||
|
this.actionWinList.clear();
|
||||||
|
EXPlayer activePlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat);
|
||||||
|
if (activePlayer.getRoom().activeKong != null) {
|
||||||
|
activePlayer.getRoom().activeKong = null;
|
||||||
|
activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
||||||
|
stateMachine.changeState(Global.getState(EXRoomSetpState.class));
|
||||||
|
} else {
|
||||||
|
activePlayer.stateMachine.toNextState();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
for (Action action : this.actionList) {
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
this.actionList.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllPass() {
|
||||||
|
return this.actionList.size() == 0 && this.tipMap.size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWeightestAction() {
|
||||||
|
if (this.isAllPass()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (this.actionList.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Action curaction = this.actionList.get(0);
|
||||||
|
for (Entry<Integer, TipManager> entry : this.tipMap.entrySet()) {
|
||||||
|
TipManager tip = entry.getValue();
|
||||||
|
if (curaction.tip.weight <= tip.getWeightest()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) {
|
||||||
|
player.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITObject getReloadInfo(Player player) {
|
||||||
|
ITObject data = super.getReloadInfo(player);
|
||||||
|
EXPlayer p = (EXPlayer) player;
|
||||||
|
data.putTArray("hand_card", Util.toTArray(p.cardInhand));
|
||||||
|
data.putInt("left_card", card.getCount());
|
||||||
|
data.putInt("curren_outcard_seat", currenDiscardSeat);
|
||||||
|
data.putInt("last_outcard_seat", lastDiscardSeat);
|
||||||
|
if (this.activeKong != null) {
|
||||||
|
data.putTObject("okinfo", this.activeKong.getTObject());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkZhuangxian(EXPlayer destPlayer, EXPlayer fromPlayer, int type) {
|
||||||
|
boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN);
|
||||||
|
if (zhuangxian) {
|
||||||
|
if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!zhuangxian)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) {
|
||||||
|
|
||||||
|
if (type == EXScore.WIN) {
|
||||||
|
// if (checkZhuangxian(destPlayer, fromPlayer, type)) {
|
||||||
|
// score += 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
EXScore exscore = (EXScore) destPlayer.score;
|
||||||
|
HUScore hu_score = exscore.getHuScore(fromPlayer);
|
||||||
|
if (hu_score == null) {
|
||||||
|
hu_score = new HUScore();
|
||||||
|
hu_score.player = fromPlayer;
|
||||||
|
exscore.hu_score.add(hu_score);
|
||||||
|
}
|
||||||
|
|
||||||
|
hu_score.score += score;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == EXScore.WIN || type == EXScore.NIAO) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
destPlayer.score.round_log.put(type, destPlayer.score.round_log.get(type) + score);
|
||||||
|
fromPlayer.score.round_log.put(type, fromPlayer.score.round_log.get(type) - score);
|
||||||
|
|
||||||
|
destPlayer.score.round_score += score;
|
||||||
|
destPlayer.score.total_score += score;
|
||||||
|
|
||||||
|
fromPlayer.score.round_score -= score;
|
||||||
|
fromPlayer.score.total_score -= score;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addQSScore(EXPlayer destPlayer, int score, int id, QSLog qs_log) {
|
||||||
|
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
if (entry.getKey().equals(destPlayer.playerid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int tem = score;
|
||||||
|
EXPlayer fromPlayer = (EXPlayer) entry.getValue();
|
||||||
|
if (checkZhuangxian(destPlayer, fromPlayer, EXScore.QS)) {
|
||||||
|
tem += 1;
|
||||||
|
}
|
||||||
|
EXScore exscore = (EXScore) destPlayer.score;
|
||||||
|
HUScore hu_score = exscore.getHuScore(fromPlayer);
|
||||||
|
if (hu_score == null) {
|
||||||
|
hu_score = new HUScore();
|
||||||
|
hu_score.player = fromPlayer;
|
||||||
|
exscore.hu_score.add(hu_score);
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
if (hu_score.qs_score_map.containsKey(id)) {
|
||||||
|
sum = hu_score.qs_score_map.get(id);
|
||||||
|
}
|
||||||
|
sum += tem;
|
||||||
|
hu_score.qs_score_map.put(id, sum);
|
||||||
|
qs_log.score += tem;
|
||||||
|
this.addScore(destPlayer, fromPlayer, tem, EXScore.QS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAllScore(EXPlayer destPlayer, int socre, int type) {
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
if (entry.getKey().equals(destPlayer.playerid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EXPlayer fromPlayer = (EXPlayer) entry.getValue();
|
||||||
|
this.addScore(destPlayer, fromPlayer, socre, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) {
|
||||||
|
int niao_type = config.getInt(Config.ROOM_CONFIG_NIAO_TYPE);
|
||||||
|
HUScore hs = ((EXScore) destPlayer.score).getHuScore(fromPlayer);
|
||||||
|
if (niao_type == Config.NIAO_TYPE_DOUBLE) {
|
||||||
|
score = hs.score * (int) Math.round(Math.pow(2, hs.niao_double_num));
|
||||||
|
hs.niao_double_num++;
|
||||||
|
} else if (niao_type == Config.NIAO_TYPE_CS2NIAO) {
|
||||||
|
score = hs.score;
|
||||||
|
}
|
||||||
|
hs.niao_score += score;
|
||||||
|
this.addScore(destPlayer, fromPlayer, score, EXScore.NIAO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAllNiaoScore(EXPlayer destPlayer, int score) {
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
if (entry.getKey().equals(destPlayer.playerid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EXPlayer fromPlayer = (EXPlayer) entry.getValue();
|
||||||
|
addNiaoScore(destPlayer, fromPlayer, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPiaoNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer) {
|
||||||
|
int piao_niao = this.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO);
|
||||||
|
if (piao_niao == 0)
|
||||||
|
return;
|
||||||
|
this.addScore(destPlayer, fromPlayer, destPlayer.piaoNiao + fromPlayer.piaoNiao, EXScore.PIAO_NIAO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAllPiaoNiaoScore(EXPlayer destPlayer) {
|
||||||
|
int piao_niao = this.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO);
|
||||||
|
if (piao_niao == 0)
|
||||||
|
return;
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
if (entry.getKey().equals(destPlayer.playerid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EXPlayer fromPlayer = (EXPlayer) entry.getValue();
|
||||||
|
addPiaoNiaoScore(destPlayer, fromPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void niao_tongPao() {
|
||||||
|
if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat);
|
||||||
|
EXPlayer banker = (EXPlayer) this.playerMapBySeat.get(this.bankerSeat);
|
||||||
|
boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN);
|
||||||
|
__zhuaNiao_Win(zhuangxian ? banker : dianPaoPlayer);
|
||||||
|
if (niao.size() == 0)
|
||||||
|
return;
|
||||||
|
List<EXPlayer> winPlayerList = new ArrayList<EXPlayer>();
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
if (player.winer == 1) {
|
||||||
|
winPlayerList.add((EXPlayer) player);
|
||||||
|
} else {
|
||||||
|
player.win_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CardNiao cn : niao) {
|
||||||
|
boolean not_niao = true;
|
||||||
|
if (dianPaoPlayer.playerid == cn.playerId) {
|
||||||
|
for (EXPlayer winer : winPlayerList) {
|
||||||
|
this.addNiaoScore(winer, dianPaoPlayer, cn.score);
|
||||||
|
}
|
||||||
|
not_niao = false;
|
||||||
|
} else {
|
||||||
|
for (EXPlayer winer : winPlayerList) {
|
||||||
|
if (winer.playerid == cn.playerId) {
|
||||||
|
this.addNiaoScore(winer, dianPaoPlayer, cn.score);
|
||||||
|
not_niao = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (not_niao)
|
||||||
|
cn.score = 0;
|
||||||
|
}
|
||||||
|
EXMainServer.gameCtr.sendNiaoEvt(dianPaoPlayer, dianPaoPlayer.seat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void niao_dianPao(EXPlayer winer) {
|
||||||
|
if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat);
|
||||||
|
EXPlayer banker = (EXPlayer) this.playerMapBySeat.get(this.bankerSeat);
|
||||||
|
boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN);
|
||||||
|
__zhuaNiao_Win(zhuangxian ? banker : winer);
|
||||||
|
if (niao.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (CardNiao cn : niao) {
|
||||||
|
if (cn.playerId == winer.playerid || dianPaoPlayer.playerid == cn.playerId) {
|
||||||
|
this.addNiaoScore(winer, dianPaoPlayer, cn.score);
|
||||||
|
} else {
|
||||||
|
cn.score = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EXMainServer.gameCtr.sendNiaoEvt(winer, winer.seat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void niao_selfWin(EXPlayer owner) {
|
||||||
|
if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EXPlayer banker = (EXPlayer) this.playerMapBySeat.get(this.bankerSeat);
|
||||||
|
boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN);
|
||||||
|
__zhuaNiao_Win(zhuangxian ? banker : owner);
|
||||||
|
if (niao.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (CardNiao cn : niao) {
|
||||||
|
boolean not_niao = true;
|
||||||
|
if (cn.playerId == owner.playerid) {
|
||||||
|
this.addAllNiaoScore(owner, cn.score);
|
||||||
|
not_niao = false;
|
||||||
|
} else {
|
||||||
|
for (Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
if (player.playerid == cn.playerId) {
|
||||||
|
this.addNiaoScore(owner, player, cn.score);
|
||||||
|
not_niao = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (not_niao)
|
||||||
|
cn.score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXMainServer.gameCtr.sendNiaoEvt(owner, owner.seat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void niao_qsWin(EXPlayer owner, int id, QSLog qs_log) {
|
||||||
|
EXPlayer banker = (EXPlayer) this.playerMapBySeat.get(this.bankerSeat);
|
||||||
|
boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN);
|
||||||
|
qs_log.niaoList.clear();
|
||||||
|
for (int k = 0; k < 2; ++k) {
|
||||||
|
int card = CardUtil.randomDiceNum();
|
||||||
|
this.__zhuaNiao(zhuangxian ? banker : owner, qs_log.niaoList, card);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CardNiao cn : qs_log.niaoList) {
|
||||||
|
boolean not_niao = true;
|
||||||
|
if (cn.playerId == owner.playerid) {
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
if (entry.getKey().equals(owner.playerid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EXPlayer fromPlayer = (EXPlayer) entry.getValue();
|
||||||
|
__addQsWinNiao(owner, fromPlayer, id, qs_log);
|
||||||
|
}
|
||||||
|
not_niao = false;
|
||||||
|
} else {
|
||||||
|
for (Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
if (player.playerid == cn.playerId) {
|
||||||
|
__addQsWinNiao(owner, player, id, qs_log);
|
||||||
|
not_niao = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (not_niao)
|
||||||
|
cn.score = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void banban_qsWin(EXPlayer owner, int id, QSLog qs_log) {
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
if (entry.getKey().equals(owner.playerid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EXPlayer fromPlayer = (EXPlayer) entry.getValue();
|
||||||
|
__addQsWinNiao(owner, fromPlayer, id, qs_log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void __addQsWinNiao(EXPlayer destPlayer, EXPlayer fromPlayer, int id, QSLog qs_log) {
|
||||||
|
HUScore hs = ((EXScore) destPlayer.score).getHuScore(fromPlayer);
|
||||||
|
int qs_score = hs.qs_score_map.get(id);
|
||||||
|
qs_log.niao_score += qs_score;
|
||||||
|
this.addScore(destPlayer, fromPlayer, qs_score, EXScore.QS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void __zhuaNiao(EXPlayer owner, List<CardNiao> list, int card) {
|
||||||
|
CardNiao cn = new CardNiao();
|
||||||
|
cn.card = card;
|
||||||
|
list.add(cn);
|
||||||
|
int tem = card % 100;
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
int pos = Util.getPos(owner.seat, entry.getValue().seat, this.maxPlayers);
|
||||||
|
Player player = entry.getValue();
|
||||||
|
boolean result = false;
|
||||||
|
switch (pos) {
|
||||||
|
case 0:
|
||||||
|
result = tem == 1 || tem == 5 || tem == 9;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (this.maxPlayers == 2) {
|
||||||
|
result = (tem == 3 || tem == 7);
|
||||||
|
} else {
|
||||||
|
result = (tem == 2 || tem == 6);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (this.maxPlayers == 3) {
|
||||||
|
result = (tem == 4 || tem == 8);
|
||||||
|
} else {
|
||||||
|
result = (tem == 3 || tem == 7);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
result = (tem == 4 || tem == 8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result) {
|
||||||
|
cn.playerId = player.playerid;
|
||||||
|
cn.score = this.niao_score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void __zhuaNiao_Win(EXPlayer owner) {
|
||||||
|
this.niao.clear();
|
||||||
|
if (this.activeHaidi) {
|
||||||
|
card.cardList.add(this.haidiCard);
|
||||||
|
} else {
|
||||||
|
if (card.cardList.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int niao_num = config.getInt(Config.ROOM_CONFIG_NIAO);
|
||||||
|
for (int index = 0; index < niao_num; index++) {
|
||||||
|
if (card.cardList.size() == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int card = this.card.pop();
|
||||||
|
this.__zhuaNiao(owner, this.niao, card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void winAction(EXPlayer owner, boolean tongpao) {
|
||||||
|
for (Entry<Integer, Player> entry : playerMapById.entrySet()) {
|
||||||
|
EXPlayer p = (EXPlayer) entry.getValue();
|
||||||
|
if (p.winer != 1) {
|
||||||
|
p.win_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tongpao) {
|
||||||
|
niao_tongPao();
|
||||||
|
this.bankerSeat = this.activeSeat;
|
||||||
|
} else {
|
||||||
|
niao_dianPao(owner);
|
||||||
|
this.bankerSeat = owner.seat;
|
||||||
|
}
|
||||||
|
this.endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void winCallback(EXPlayer owner) {
|
||||||
|
if (closeWinCallBack)
|
||||||
|
return;
|
||||||
|
if (this.tongpao > 1) {
|
||||||
|
this.closeWinCallBack = true;
|
||||||
|
List<TipManager> tlist = new ArrayList<TipManager>(this.tipMap.values());
|
||||||
|
for (TipManager tipmgr : tlist) {
|
||||||
|
tipmgr.winAction();
|
||||||
|
}
|
||||||
|
for (Action action : this.actionWinList) {
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
this.actionWinList.clear();
|
||||||
|
// this.actionList.clear();
|
||||||
|
winAction(owner, true);
|
||||||
|
this.closeWinCallBack = false;
|
||||||
|
} else {
|
||||||
|
winAction(owner, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void roomResult() {
|
||||||
|
EXMainServer.gameCtr.roomResult(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endGame() {
|
||||||
|
boolean fengding = this.config.getBoolean(Config.ROOM_CONFIG_FENGDING);
|
||||||
|
boolean four_win = this.config.getBoolean(Config.ROOM_CONFIG_FOUR_WIN);
|
||||||
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
if (player.winer == 1) {
|
||||||
|
List<HUScore> list = ((EXScore) player.score).hu_score;
|
||||||
|
for (HUScore hu_score : list) {
|
||||||
|
int hu_num = hu_score.score;
|
||||||
|
int niao_num = hu_score.niao_score;
|
||||||
|
if (four_win && player.win_count >= 4) {
|
||||||
|
hu_num = hu_num * 2;
|
||||||
|
niao_num = niao_num * 2;
|
||||||
|
}
|
||||||
|
int sum_score = hu_num + niao_num;
|
||||||
|
EXPlayer destPlayer = player;
|
||||||
|
EXPlayer fromPlayer = hu_score.player;
|
||||||
|
|
||||||
|
destPlayer.score.round_log.put(EXScore.WIN, destPlayer.score.round_log.get(EXScore.WIN) + hu_num);
|
||||||
|
fromPlayer.score.round_log.put(EXScore.WIN, fromPlayer.score.round_log.get(EXScore.WIN) - hu_num);
|
||||||
|
destPlayer.score.round_log.put(EXScore.NIAO, destPlayer.score.round_log.get(EXScore.NIAO) + niao_num);
|
||||||
|
fromPlayer.score.round_log.put(EXScore.NIAO, fromPlayer.score.round_log.get(EXScore.NIAO) - niao_num);
|
||||||
|
//if (fengding) {
|
||||||
|
// if (sum_score > Config.FENGDING_SCORE) {
|
||||||
|
// sum_score = Config.FENGDING_SCORE;
|
||||||
|
// player.fengding = true;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
if (fengding && this.fengdingScore > 0)
|
||||||
|
{
|
||||||
|
if (sum_score > this.fengdingScore) {
|
||||||
|
sum_score = this.fengdingScore;
|
||||||
|
player.fengding = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
destPlayer.score.round_score += sum_score;
|
||||||
|
destPlayer.score.total_score += sum_score;
|
||||||
|
fromPlayer.score.round_score -= sum_score;
|
||||||
|
fromPlayer.score.total_score -= sum_score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveMilitaryTotal(boolean dissmiss) {
|
||||||
|
super.saveMilitaryTotal(dissmiss);
|
||||||
|
EXMainServer.gameCtr.roomTotalResult(this, dissmiss);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
super.clear();
|
||||||
|
this.liuju = false;
|
||||||
|
this.haidiCard = 0;
|
||||||
|
this.closeWinCallBack = false;
|
||||||
|
this.tongpao = 0;
|
||||||
|
this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0;
|
||||||
|
this.qsWinCount = this.haidiCount = this.winCount = this.piaoNiaoCount = 0;
|
||||||
|
this.activeKong = null;
|
||||||
|
this.activeHaidi = false;
|
||||||
|
this.niao.clear();
|
||||||
|
this.actionWinList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue